cryptoservices/certificateandkeymgmt/tadditionalstores/Test1certstoretoken.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "test1certstoretoken.h"
       
    20 #include "test1certstore.h"
       
    21 
       
    22 _LIT(KName1, "Test store 1");
       
    23 _LIT(KName2, "Test store 2");
       
    24 #ifdef CERTSTORE_HARDWARE_SIM
       
    25 	_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1simcertstore.dat");
       
    26 	_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2simcertstore.dat");
       
    27 #else
       
    28 	#ifdef CERTSTORE_HARDWARE_WIM
       
    29 		_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1wimcertstore.dat");
       
    30 		_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2wimcertstore.dat");
       
    31 	#else
       
    32 		#ifdef CERTSTORE_HARDWARE_UICC
       
    33 			_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1uicccertstore.dat");
       
    34 			_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2uicccertstore.dat");
       
    35  		#else
       
    36 			#ifdef CERTSTORE_DEVICE_IMMUTABLE
       
    37 				_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1deviceimmutablecertstore.dat");
       
    38 				_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2deviceimmutablecertstore.dat");
       
    39 			#else
       
    40 				_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1certstore.dat");
       
    41 				_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2certstore.dat");
       
    42 			#endif
       
    43  		#endif
       
    44 	#endif
       
    45 #endif
       
    46 
       
    47 
       
    48 CTest1CertStoreToken* CTest1CertStoreToken::New(CTest1CertStoreTokenType::TTokenId aTokenId,
       
    49 												CTest1CertStoreTokenType& aFileCertStoreTokenType)
       
    50 	{
       
    51 	return new CTest1CertStoreToken(aTokenId, aFileCertStoreTokenType);
       
    52 	}
       
    53 
       
    54 CTest1CertStoreToken::~CTest1CertStoreToken()
       
    55 	{
       
    56 	}
       
    57 
       
    58 MCTTokenType& CTest1CertStoreToken::TokenType()
       
    59 	{
       
    60 	return iTokenType;
       
    61 	}
       
    62 
       
    63 const TDesC& CTest1CertStoreToken::Label()
       
    64 	{
       
    65 	switch (iTokenId)
       
    66 		{
       
    67 	case CTest1CertStoreTokenType::ETest1CertStore:
       
    68 		return KName1;
       
    69 
       
    70 	case CTest1CertStoreTokenType::ETest2CertStore:
       
    71 		return KName2;
       
    72 
       
    73 	default:
       
    74 		return KNullDesC;
       
    75 		}
       
    76 	}
       
    77 
       
    78 const TDesC& CTest1CertStoreToken::Information(TTokenInformation)
       
    79 	{
       
    80 	_LIT(KAnswer, "I Know Nothing");
       
    81 	return KAnswer;
       
    82 	}
       
    83 
       
    84 TCTTokenHandle CTest1CertStoreToken::Handle()
       
    85 	{
       
    86 	return TCTTokenHandle(iTokenType.Type(), iTokenId);
       
    87 	}
       
    88 
       
    89 void CTest1CertStoreToken::DoRelease()
       
    90 	{
       
    91 	delete this;
       
    92 	}
       
    93 
       
    94 TInt& CTest1CertStoreToken::ReferenceCount()
       
    95 	{
       
    96 	return iRefCount;
       
    97 	}
       
    98 
       
    99 void CTest1CertStoreToken::DoGetInterface(TUid aRequiredInterface,
       
   100 										  MCTTokenInterface*& aReturnedInterface,
       
   101 										  TRequestStatus& aStatus)
       
   102 	{
       
   103 	RFs& fs = static_cast<CCTTokenType&>(TokenType()).Fs();
       
   104 	MCTTokenInterface* result = 0;
       
   105 	TInt error = KErrNone;
       
   106 
       
   107 	//gets the system drive
       
   108 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   109 	TDriveName driveName(sysDrive.Name());	
       
   110 	TBuf<128> fullPath (driveName);
       
   111 	TInt* refCountInterface = &iRefCountInterface;
       
   112 	
       
   113 	if (iTokenId == CTest1CertStoreTokenType::ETest1CertStore)
       
   114 		{
       
   115 		fullPath.Append(KTest1CertStoreFullPath);
       
   116 		refCountInterface = &iRefCountInterface;
       
   117 		}
       
   118 		
       
   119 	// This is mainly used for testing and also as an example on how to manage
       
   120 	// multiple tokens within one TokenType.
       
   121 	else if (iTokenId == CTest1CertStoreTokenType::ETest2CertStore)
       
   122 		{
       
   123 		fullPath.Append(KTest2CertStoreFullPath);
       
   124 		refCountInterface = &iRefCountInterface2;
       
   125 		}
       
   126 	else
       
   127 		{
       
   128 		// If not certstore 1 or 2, then we complete with bad name.
       
   129 		TRequestStatus* r = &aStatus;
       
   130 		User::RequestComplete(r, KErrBadName);
       
   131 		return;
       
   132 		}
       
   133 
       
   134 	switch (aRequiredInterface.iUid)
       
   135 		{
       
   136 	case KInterfaceCertStore:
       
   137 		{
       
   138 		if (!iFileCertStore)
       
   139 			{
       
   140 			TRAP(error, iFileCertStore = CTest1CertStore::NewL(fs, *this, fullPath, 
       
   141 				EFileShareReadersOnly));
       
   142 			iFileMode = EFileRead;
       
   143 			}
       
   144 		MCTCertStore* temp = iFileCertStore;
       
   145 		result = temp;
       
   146 		}
       
   147 		break;
       
   148 
       
   149 	case KInterfaceWritableCertStore:
       
   150 		{
       
   151 		if (!iFileCertStore)
       
   152 			{
       
   153 			TRAP(error, iFileCertStore = CTest1CertStore::NewL(fs, *this, fullPath, EFileWrite));
       
   154 			iFileMode = EFileWrite;
       
   155 			}
       
   156 		if (iFileMode == EFileRead)
       
   157 			{
       
   158 			error = KErrInUse;
       
   159 			}
       
   160 		else
       
   161 			{
       
   162 			MCTWritableCertStore* temp = iFileCertStore;
       
   163 			result = temp;
       
   164 			}
       
   165 		}
       
   166 		break;
       
   167 
       
   168 	default:
       
   169 		error = KErrNotSupported;
       
   170 		break;
       
   171 		}
       
   172 
       
   173 	if (error == KErrNotSupported)
       
   174 		{
       
   175 		Release();
       
   176 		}
       
   177 	else if ((error != KErrNone) || !result)
       
   178 		{
       
   179 		Release();
       
   180 		}
       
   181 	else
       
   182 		{
       
   183 		(*refCountInterface)++;
       
   184 		aReturnedInterface = result;
       
   185 		}
       
   186 
       
   187 	TRequestStatus* r = &aStatus;
       
   188 	User::RequestComplete(r, error);
       
   189 	}
       
   190 
       
   191 TBool CTest1CertStoreToken::DoCancelGetInterface()
       
   192 	{
       
   193 	return EFalse;
       
   194 	}
       
   195 
       
   196 CTest1CertStoreToken::CTest1CertStoreToken(CTest1CertStoreTokenType::TTokenId aTokenId,
       
   197 										   CTest1CertStoreTokenType& aFileCertStoreTokenType)
       
   198 	:  iTokenType(aFileCertStoreTokenType), iTokenId(aTokenId)
       
   199 	{
       
   200 	}