williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
* This component and the accompanying materials are made available
|
williamr@2
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
williamr@2
|
6 |
* which accompanies this distribution, and is available
|
williamr@2
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Initial Contributors:
|
williamr@2
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Contributors:
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Description:
|
williamr@2
|
15 |
*
|
williamr@2
|
16 |
*/
|
williamr@2
|
17 |
|
williamr@2
|
18 |
|
williamr@2
|
19 |
|
williamr@2
|
20 |
|
williamr@2
|
21 |
/**
|
williamr@2
|
22 |
@file
|
williamr@2
|
23 |
@publishedPartner
|
williamr@2
|
24 |
@released
|
williamr@2
|
25 |
*/
|
williamr@2
|
26 |
|
williamr@2
|
27 |
#ifndef __MCTTOKEN_H__
|
williamr@2
|
28 |
#define __MCTTOKEN_H__
|
williamr@2
|
29 |
|
williamr@2
|
30 |
#include <ct/tcttokenobjecthandle.h>
|
williamr@2
|
31 |
#include <ct/mcttokenobject.h>
|
williamr@2
|
32 |
#include <ct/tcttokenhandle.h>
|
williamr@2
|
33 |
#include <ct/mcttokentype.h>
|
williamr@2
|
34 |
|
williamr@2
|
35 |
class MCTTokenInterface;
|
williamr@2
|
36 |
|
williamr@2
|
37 |
|
williamr@2
|
38 |
/**
|
williamr@2
|
39 |
* The base class for a token.
|
williamr@2
|
40 |
*
|
williamr@2
|
41 |
* Token types must implement this class. It is created from a MCTTokenType using
|
williamr@2
|
42 |
* MCTTokenType::OpenToken().
|
williamr@2
|
43 |
*
|
williamr@2
|
44 |
* A token represents one instance of a particular kind of cryptographic module;
|
williamr@2
|
45 |
* for instance, on a device with two WIMs, each WIM is a token. The token contains
|
williamr@2
|
46 |
* several interfaces, representing particular kinds of functions supported by
|
williamr@2
|
47 |
* the token (e.g. certificate management, key management, etc.)
|
williamr@2
|
48 |
*
|
williamr@2
|
49 |
* @since v7.0
|
williamr@2
|
50 |
*/
|
williamr@2
|
51 |
class MCTToken
|
williamr@2
|
52 |
{
|
williamr@2
|
53 |
public:
|
williamr@2
|
54 |
//Functions for opening an interface.
|
williamr@2
|
55 |
//The base class implements the reference counting then calls the corresponding pure virtual Do... methods
|
williamr@2
|
56 |
/**
|
williamr@2
|
57 |
* Gets a token interface, or NULL if it's not supported by this token.
|
williamr@2
|
58 |
*
|
williamr@2
|
59 |
* This is an asynchronous request.
|
williamr@2
|
60 |
*
|
williamr@2
|
61 |
* @param aRequiredInterface The UID of the interface that should be returned.
|
williamr@2
|
62 |
* @param aReturnedInterface On success, this will be set to a pointer to the
|
williamr@2
|
63 |
* returned interface.
|
williamr@2
|
64 |
* @param aStatus The request status object; contains the result of the
|
williamr@2
|
65 |
* GetInterface() request when complete. Set to KErrCancel
|
williamr@2
|
66 |
* if an outstanding request is cancelled.
|
williamr@2
|
67 |
*/
|
williamr@2
|
68 |
IMPORT_C void GetInterface(TUid aRequiredInterface,
|
williamr@2
|
69 |
MCTTokenInterface*& aReturnedInterface,
|
williamr@2
|
70 |
TRequestStatus& aStatus);
|
williamr@2
|
71 |
|
williamr@2
|
72 |
/**
|
williamr@2
|
73 |
* Cancels an asynchronous GetInterface() operation.
|
williamr@2
|
74 |
*
|
williamr@2
|
75 |
* The operation completes with KErrCancel.
|
williamr@2
|
76 |
*/
|
williamr@2
|
77 |
IMPORT_C void CancelGetInterface();
|
williamr@2
|
78 |
|
williamr@2
|
79 |
/**
|
williamr@2
|
80 |
* Allows the client to add a reference to the token (for
|
williamr@2
|
81 |
* example, when a reference to a token is copied elsewhere).
|
williamr@2
|
82 |
*
|
williamr@2
|
83 |
* Does not need to be called if token is referenced through OpenToken().
|
williamr@2
|
84 |
*/
|
williamr@2
|
85 |
inline void AddRef();
|
williamr@2
|
86 |
|
williamr@2
|
87 |
/**
|
williamr@2
|
88 |
* Destroys the object.
|
williamr@2
|
89 |
*
|
williamr@2
|
90 |
* The interface should be destroyed via this method as the destructor is protected.
|
williamr@2
|
91 |
*
|
williamr@2
|
92 |
* The token implements reference counting, with one count
|
williamr@2
|
93 |
* for itself and one for every opened interface. Once the count
|
williamr@2
|
94 |
* reaches 0, it releases its count with the token type.
|
williamr@2
|
95 |
*/
|
williamr@2
|
96 |
IMPORT_C void Release();
|
williamr@2
|
97 |
|
williamr@2
|
98 |
// Notification of token removal. The base class assumes the token is not removable, and so does nothing. Removable tokens must implement these functions.
|
williamr@2
|
99 |
/**
|
williamr@2
|
100 |
* Notifies the client when the token has been removed.
|
williamr@2
|
101 |
*
|
williamr@2
|
102 |
* The base class assumes the token is not removable, and so does nothing. Removable
|
williamr@2
|
103 |
* tokens must implement these functions.
|
williamr@2
|
104 |
*
|
williamr@2
|
105 |
* This is an asynchronous request.
|
williamr@2
|
106 |
*
|
williamr@2
|
107 |
* @param aStatus The request status object; contains the result of the
|
williamr@2
|
108 |
* NotifyOnRemoval() request when complete. Set to KErrCancel
|
williamr@2
|
109 |
* if an outstanding request is cancelled.
|
williamr@2
|
110 |
*/
|
williamr@2
|
111 |
IMPORT_C virtual void NotifyOnRemoval(TRequestStatus& aStatus);
|
williamr@2
|
112 |
|
williamr@2
|
113 |
/**
|
williamr@2
|
114 |
* Cancels an asynchronous NotifyOnRemoval() operation.
|
williamr@2
|
115 |
*
|
williamr@2
|
116 |
* The operation completes with KErrCancel.
|
williamr@2
|
117 |
*/
|
williamr@2
|
118 |
IMPORT_C virtual void CancelNotify();
|
williamr@2
|
119 |
|
williamr@2
|
120 |
|
williamr@2
|
121 |
/**
|
williamr@2
|
122 |
* Gets the associated token type.
|
williamr@2
|
123 |
*
|
williamr@2
|
124 |
* @return The associated token type.
|
williamr@2
|
125 |
*/
|
williamr@2
|
126 |
virtual MCTTokenType& TokenType() = 0;
|
williamr@2
|
127 |
|
williamr@2
|
128 |
/**
|
williamr@2
|
129 |
* Gets a label for the token.
|
williamr@2
|
130 |
*
|
williamr@2
|
131 |
* This should be the same as the descriptor returned by MCTTokenType::List().
|
williamr@2
|
132 |
*
|
williamr@2
|
133 |
* @return The label to the token type.
|
williamr@2
|
134 |
*/
|
williamr@2
|
135 |
virtual const TDesC& Label() = 0;
|
williamr@2
|
136 |
|
williamr@2
|
137 |
/** Available information strings for the token. */
|
williamr@2
|
138 |
enum TTokenInformation
|
williamr@2
|
139 |
{
|
williamr@2
|
140 |
/** Version */
|
williamr@2
|
141 |
EVersion,
|
williamr@2
|
142 |
/** Serial number */
|
williamr@2
|
143 |
ESerialNo,
|
williamr@2
|
144 |
/** Manufacturer */
|
williamr@2
|
145 |
EManufacturer
|
williamr@2
|
146 |
};
|
williamr@2
|
147 |
|
williamr@2
|
148 |
/**
|
williamr@2
|
149 |
* Gets the token's handle.
|
williamr@2
|
150 |
*
|
williamr@2
|
151 |
* This can be used to identify a token to another process.
|
williamr@2
|
152 |
*
|
williamr@2
|
153 |
* See the documentation of TCTTokenHandle for an explanation of the use of token
|
williamr@2
|
154 |
* handles.
|
williamr@2
|
155 |
*
|
williamr@2
|
156 |
* @return The handle of the token.
|
williamr@2
|
157 |
*/
|
williamr@2
|
158 |
virtual TCTTokenHandle Handle() = 0;
|
williamr@2
|
159 |
|
williamr@2
|
160 |
protected:
|
williamr@2
|
161 |
/**
|
williamr@2
|
162 |
* The destructor is protected so that users of the interface
|
williamr@2
|
163 |
* have to use the Release() function.
|
williamr@2
|
164 |
*/
|
williamr@2
|
165 |
inline virtual ~MCTToken() = 0;
|
williamr@2
|
166 |
|
williamr@2
|
167 |
// Helper functions for the reference counting
|
williamr@2
|
168 |
/**
|
williamr@2
|
169 |
* Destroys the token object.
|
williamr@2
|
170 |
*
|
williamr@2
|
171 |
* This function is called when Release() has determined that the object is ready
|
williamr@2
|
172 |
* to be destroyed.
|
williamr@2
|
173 |
*
|
williamr@2
|
174 |
* The default implementation just does a 'delete this', but classes can override
|
williamr@2
|
175 |
* that if they want different behaviour.
|
williamr@2
|
176 |
*
|
williamr@2
|
177 |
* It should destroy the token; it MUST NOT release the token type, as Release()
|
williamr@2
|
178 |
* will do that.
|
williamr@2
|
179 |
*/
|
williamr@2
|
180 |
IMPORT_C virtual void DoRelease();
|
williamr@2
|
181 |
|
williamr@2
|
182 |
/**
|
williamr@2
|
183 |
* Gets a reference to the variable used as a reference counter.
|
williamr@2
|
184 |
*
|
williamr@2
|
185 |
* The implementer should initialise this to 0. The value of the reference count
|
williamr@2
|
186 |
* should be treated as opaque by the implementer.
|
williamr@2
|
187 |
*
|
williamr@2
|
188 |
* @return A reference to the variable used as a reference counter.
|
williamr@2
|
189 |
*/
|
williamr@2
|
190 |
virtual TInt& ReferenceCount() = 0;
|
williamr@2
|
191 |
|
williamr@2
|
192 |
// Implementation of GetInterface functionality */
|
williamr@2
|
193 |
|
williamr@2
|
194 |
/**
|
williamr@2
|
195 |
* Implementation for getting a token interface.
|
williamr@2
|
196 |
*
|
williamr@2
|
197 |
* This is called by GetInterface().
|
williamr@2
|
198 |
*
|
williamr@2
|
199 |
* This is an asynchronous request.
|
williamr@2
|
200 |
*
|
williamr@2
|
201 |
* @see GetInterface
|
williamr@2
|
202 |
* @param aRequiredInterface The UID of the interface that should be returned.
|
williamr@2
|
203 |
* @param aReturnedInterface On success, this will be set to a pointer to the
|
williamr@2
|
204 |
* returned interface.
|
williamr@2
|
205 |
* @param aStatus The request status object; contains the result of
|
williamr@2
|
206 |
* the GetInterface() request when complete. Set to
|
williamr@2
|
207 |
* KErrCancel if an outstanding request is cancelled.
|
williamr@2
|
208 |
*/
|
williamr@2
|
209 |
virtual void DoGetInterface(TUid aRequiredInterface,
|
williamr@2
|
210 |
MCTTokenInterface*& aReturnedInterface,
|
williamr@2
|
211 |
TRequestStatus& aStatus) = 0;
|
williamr@2
|
212 |
/**
|
williamr@2
|
213 |
* Implements an asynchronous CancelGetInterface() request.
|
williamr@2
|
214 |
*
|
williamr@2
|
215 |
* @see CancelGetInterface
|
williamr@2
|
216 |
* @return ETrue if there is an token interface running; EFalse, otherwise.
|
williamr@2
|
217 |
*/
|
williamr@2
|
218 |
virtual TBool DoCancelGetInterface() = 0;
|
williamr@2
|
219 |
|
williamr@2
|
220 |
private:
|
williamr@2
|
221 |
// Used by the token object to increment the reference count
|
williamr@2
|
222 |
void ObjectCreated();
|
williamr@2
|
223 |
// Needed to allow MCTTokenObject to increment the reference count
|
williamr@2
|
224 |
// of the token
|
williamr@2
|
225 |
friend class MCTTokenObject;
|
williamr@2
|
226 |
public:
|
williamr@2
|
227 |
/**
|
williamr@2
|
228 |
* Gets the specified information string about the token.
|
williamr@2
|
229 |
* The default implementation returns an empty descriptor.
|
williamr@2
|
230 |
*/
|
williamr@2
|
231 |
virtual const TDesC& Information(TTokenInformation aRequiredInformation) = 0;
|
williamr@2
|
232 |
};
|
williamr@2
|
233 |
|
williamr@2
|
234 |
/**
|
williamr@2
|
235 |
* Destructor.
|
williamr@2
|
236 |
*
|
williamr@2
|
237 |
* Frees all resources owned by the object, prior to its destruction.
|
williamr@2
|
238 |
*/
|
williamr@2
|
239 |
inline MCTToken::~MCTToken()
|
williamr@2
|
240 |
{
|
williamr@2
|
241 |
}
|
williamr@2
|
242 |
|
williamr@2
|
243 |
inline void MCTToken::AddRef()
|
williamr@2
|
244 |
{
|
williamr@2
|
245 |
++ReferenceCount();
|
williamr@2
|
246 |
}
|
williamr@2
|
247 |
|
williamr@2
|
248 |
#endif //__MCTTOKEN_H__
|