os/security/cryptomgmtlibs/cryptotokenfw/inc/ct/MCTToken.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/cryptotokenfw/inc/ct/MCTToken.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,246 @@
     1.4 +/*
     1.5 +* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @publishedAll
    1.25 + @released
    1.26 +*/
    1.27 +
    1.28 +#ifndef __MCTTOKEN_H__
    1.29 +#define __MCTTOKEN_H__
    1.30 +
    1.31 +#include <ct/tcttokenobjecthandle.h>
    1.32 +#include <ct/mcttokenobject.h>
    1.33 +#include <ct/tcttokenhandle.h>
    1.34 +#include <ct/mcttokentype.h>
    1.35 +
    1.36 +class MCTTokenInterface;
    1.37 +
    1.38 +
    1.39 +/** 
    1.40 + * The base class for a token.
    1.41 + * 
    1.42 + * Token types must implement this class. It is created from a MCTTokenType using 
    1.43 + * MCTTokenType::OpenToken().
    1.44 + * 
    1.45 + * A token represents one instance of a particular kind of cryptographic module; 
    1.46 + * for instance, on a device with two WIMs, each WIM is a token. The token contains 
    1.47 + * several interfaces, representing particular kinds of functions supported by 
    1.48 + * the token (e.g. certificate management, key management, etc.) 
    1.49 + * 
    1.50 + * @since v7.0 
    1.51 + */
    1.52 +class MCTToken
    1.53 +	{
    1.54 + public:
    1.55 +  //Functions for opening an interface. 
    1.56 +  //The base class implements the reference counting then calls the corresponding pure virtual Do... methods	
    1.57 +	/** 
    1.58 +	 * Gets a token interface, or NULL if it's not supported by this token.
    1.59 +	 *
    1.60 +	 * This is an asynchronous request.
    1.61 +	 *
    1.62 +	 * @param aRequiredInterface	The UID of the interface that should be returned.
    1.63 +	 * @param aReturnedInterface	On success, this will be set to a pointer to the 
    1.64 +	 * 								returned interface.
    1.65 +	 * @param aStatus				The request status object; contains the result of the 
    1.66 +	 * 								GetInterface() request when complete. Set to KErrCancel 
    1.67 +	 * 								if an outstanding request is cancelled. 
    1.68 +	 */
    1.69 +	IMPORT_C void GetInterface(TUid aRequiredInterface,
    1.70 +							  MCTTokenInterface*& aReturnedInterface, 
    1.71 +							  TRequestStatus& aStatus);
    1.72 +
    1.73 +	/** 
    1.74 +	 * Cancels an asynchronous GetInterface() operation.
    1.75 +	 *
    1.76 +	 * The operation completes with KErrCancel. 
    1.77 +	 */
    1.78 +	IMPORT_C void CancelGetInterface();
    1.79 +	
    1.80 +	/**
    1.81 +	 * Allows the client to add a reference to the token (for
    1.82 +	 * example, when a reference to a token is copied elsewhere).  
    1.83 +	 * 
    1.84 +	 * Does not need to be called if token is referenced through OpenToken().
    1.85 +	 */
    1.86 +	inline void AddRef();
    1.87 +	
    1.88 +	/** 
    1.89 +	 * Destroys the object.
    1.90 +	 *	
    1.91 +	 * The interface should be destroyed via this method as the destructor is protected.
    1.92 +	 *
    1.93 +	 * The token implements reference counting, with one count
    1.94 +	 * for itself and one for every opened interface. Once the count
    1.95 +	 * reaches 0, it releases its count with the token type.
    1.96 +	 */
    1.97 +	IMPORT_C void Release();
    1.98 +
    1.99 +	// Notification of token removal. The base class assumes the token is not removable, and so does nothing. Removable tokens must implement these functions.
   1.100 +	/** 
   1.101 +	 * Notifies the client when the token has been removed.
   1.102 +	 *	
   1.103 +	 * The base class assumes the token is not removable, and so does nothing. Removable 
   1.104 +	 * tokens must implement these functions.
   1.105 +	 *
   1.106 +	 * This is an asynchronous request.	
   1.107 +	 *
   1.108 +	 * @param aStatus	The request status object; contains the result of the 
   1.109 +	 * 					NotifyOnRemoval() request when complete. Set to KErrCancel 
   1.110 +	 * 					if an outstanding request is cancelled. 
   1.111 +	 */
   1.112 +	IMPORT_C virtual void NotifyOnRemoval(TRequestStatus& aStatus);
   1.113 +
   1.114 +	/** 
   1.115 +	 * Cancels an asynchronous NotifyOnRemoval() operation.
   1.116 +	 *
   1.117 +	 * The operation completes with KErrCancel. 
   1.118 +	 */
   1.119 +	IMPORT_C virtual void CancelNotify();
   1.120 +	
   1.121 +
   1.122 +	/** 
   1.123 +	 * Gets the associated token type.	
   1.124 +	 *
   1.125 +	 * @return	The associated token type. 
   1.126 +	 */
   1.127 +	virtual MCTTokenType& TokenType() = 0;
   1.128 +
   1.129 +	/** 
   1.130 +	 * Gets a label for the token.
   1.131 +	 *
   1.132 +	 * This should be the same as the descriptor returned by MCTTokenType::List().
   1.133 +	 *
   1.134 +	 * @return	The label to the token type. 
   1.135 +	 */
   1.136 +	virtual const TDesC& Label() = 0;
   1.137 +
   1.138 +	/** Available information strings for the token. */
   1.139 +	enum TTokenInformation
   1.140 +		{
   1.141 +		/** Version */
   1.142 +		EVersion,
   1.143 +		/** Serial number */
   1.144 +		ESerialNo,
   1.145 +		/** Manufacturer */
   1.146 +		EManufacturer
   1.147 +		};
   1.148 +	
   1.149 +	/** 
   1.150 +	 * Gets the token's handle.
   1.151 +	 *
   1.152 +	 * This can be used to identify a token to another process.
   1.153 +	 *
   1.154 +	 * See the documentation of TCTTokenHandle for an explanation of the use of token 
   1.155 +	 * handles.
   1.156 +	 *
   1.157 +	 * @return	The handle of the token. 
   1.158 +	 */
   1.159 +	virtual TCTTokenHandle Handle() = 0;
   1.160 +
   1.161 + protected:
   1.162 + 	 /** 
   1.163 + 	  * The destructor is protected so that users of the interface
   1.164 +	  * have to use the Release() function. 
   1.165 +	  */
   1.166 +	inline virtual ~MCTToken() = 0;
   1.167 +
   1.168 +	// Helper functions for the reference counting
   1.169 +	/** 
   1.170 +	 * Destroys the token object.
   1.171 +	 *
   1.172 +	 * This function is called when Release() has determined that the object is ready 
   1.173 +	 * to be destroyed.
   1.174 +	 *
   1.175 +	 * The default implementation just does a 'delete this', but classes can override 
   1.176 +	 * that if they want different behaviour.
   1.177 +	 *
   1.178 +	 * It should destroy the token; it MUST NOT release the token type, as Release() 
   1.179 +	 * will do that. 
   1.180 +	 */
   1.181 +	IMPORT_C virtual void DoRelease();
   1.182 +
   1.183 +	/** 
   1.184 +	 * Gets a reference to the variable used as a reference counter.
   1.185 +	 *
   1.186 +	 * The implementer should initialise this to 0. The value of the reference count 
   1.187 +	 * should be treated as opaque by the implementer.
   1.188 +	 *
   1.189 +	 * @return	A reference to the variable used as a reference counter. 
   1.190 +	 */
   1.191 +	virtual TInt& ReferenceCount() = 0;
   1.192 +	
   1.193 +	// Implementation of GetInterface functionality */
   1.194 +			
   1.195 +	/** 
   1.196 +	 * Implementation for getting a token interface.
   1.197 +	 *
   1.198 +	 * This is called by GetInterface().
   1.199 +	 *
   1.200 +	 * This is an asynchronous request.
   1.201 +	 *
   1.202 +	 * @see GetInterface
   1.203 +	 * @param aRequiredInterface	The UID of the interface that should be returned.
   1.204 +	 * @param aReturnedInterface	On success, this will be set to a pointer to the 
   1.205 +	 * 								returned interface.
   1.206 +	 * @param aStatus				The request status object; contains the result of 
   1.207 +	 * 								the GetInterface() request when complete. Set to 
   1.208 +	 * 								KErrCancel if an outstanding request is cancelled. 
   1.209 +	 */
   1.210 +	virtual void DoGetInterface(TUid aRequiredInterface,
   1.211 +							  MCTTokenInterface*& aReturnedInterface, 
   1.212 +							  TRequestStatus& aStatus) = 0;
   1.213 +	/** 
   1.214 +	 * Implements an asynchronous CancelGetInterface() request.
   1.215 +	 * 
   1.216 +	 * @see	CancelGetInterface
   1.217 +	 * @return	ETrue if there is an token interface running; EFalse, otherwise. 
   1.218 +	 */
   1.219 +	virtual TBool DoCancelGetInterface() = 0;
   1.220 +	
   1.221 + private:
   1.222 +	// Used by the token object to increment the reference count
   1.223 +	void ObjectCreated();
   1.224 +	// Needed to allow MCTTokenObject to increment the reference count
   1.225 +	// of the token
   1.226 +	friend class MCTTokenObject;
   1.227 + public:
   1.228 +	/**
   1.229 +	 * Gets the specified information string about the token.
   1.230 +	 * The default implementation returns an empty descriptor.
   1.231 +	 */
   1.232 +	virtual const TDesC& Information(TTokenInformation aRequiredInformation) = 0;
   1.233 +	};
   1.234 +
   1.235 +/** 
   1.236 + * Destructor.
   1.237 + *
   1.238 + * Frees all resources owned by the object, prior to its destruction. 
   1.239 + */
   1.240 +inline MCTToken::~MCTToken()
   1.241 +	{
   1.242 +	}
   1.243 +
   1.244 +inline void MCTToken::AddRef()
   1.245 +	{
   1.246 +	++ReferenceCount();
   1.247 +	}
   1.248 +
   1.249 +#endif //__MCTTOKEN_H__