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