os/security/cryptoservices/certificateandkeymgmt/tadditionalstores/Test1certstoretoken.cpp
First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "test1certstoretoken.h"
20 #include "test1certstore.h"
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");
28 #ifdef CERTSTORE_HARDWARE_WIM
29 _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1wimcertstore.dat");
30 _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2wimcertstore.dat");
32 #ifdef CERTSTORE_HARDWARE_UICC
33 _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1uicccertstore.dat");
34 _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2uicccertstore.dat");
36 #ifdef CERTSTORE_DEVICE_IMMUTABLE
37 _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1deviceimmutablecertstore.dat");
38 _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2deviceimmutablecertstore.dat");
40 _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1certstore.dat");
41 _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2certstore.dat");
48 CTest1CertStoreToken* CTest1CertStoreToken::New(CTest1CertStoreTokenType::TTokenId aTokenId,
49 CTest1CertStoreTokenType& aFileCertStoreTokenType)
51 return new CTest1CertStoreToken(aTokenId, aFileCertStoreTokenType);
54 CTest1CertStoreToken::~CTest1CertStoreToken()
58 MCTTokenType& CTest1CertStoreToken::TokenType()
63 const TDesC& CTest1CertStoreToken::Label()
67 case CTest1CertStoreTokenType::ETest1CertStore:
70 case CTest1CertStoreTokenType::ETest2CertStore:
78 const TDesC& CTest1CertStoreToken::Information(TTokenInformation)
80 _LIT(KAnswer, "I Know Nothing");
84 TCTTokenHandle CTest1CertStoreToken::Handle()
86 return TCTTokenHandle(iTokenType.Type(), iTokenId);
89 void CTest1CertStoreToken::DoRelease()
94 TInt& CTest1CertStoreToken::ReferenceCount()
99 void CTest1CertStoreToken::DoGetInterface(TUid aRequiredInterface,
100 MCTTokenInterface*& aReturnedInterface,
101 TRequestStatus& aStatus)
103 RFs& fs = static_cast<CCTTokenType&>(TokenType()).Fs();
104 MCTTokenInterface* result = 0;
105 TInt error = KErrNone;
107 //gets the system drive
108 TDriveUnit sysDrive (RFs::GetSystemDrive());
109 TDriveName driveName(sysDrive.Name());
110 TBuf<128> fullPath (driveName);
111 TInt* refCountInterface = &iRefCountInterface;
113 if (iTokenId == CTest1CertStoreTokenType::ETest1CertStore)
115 fullPath.Append(KTest1CertStoreFullPath);
116 refCountInterface = &iRefCountInterface;
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)
123 fullPath.Append(KTest2CertStoreFullPath);
124 refCountInterface = &iRefCountInterface2;
128 // If not certstore 1 or 2, then we complete with bad name.
129 TRequestStatus* r = &aStatus;
130 User::RequestComplete(r, KErrBadName);
134 switch (aRequiredInterface.iUid)
136 case KInterfaceCertStore:
140 TRAP(error, iFileCertStore = CTest1CertStore::NewL(fs, *this, fullPath,
141 EFileShareReadersOnly));
142 iFileMode = EFileRead;
144 MCTCertStore* temp = iFileCertStore;
149 case KInterfaceWritableCertStore:
153 TRAP(error, iFileCertStore = CTest1CertStore::NewL(fs, *this, fullPath, EFileWrite));
154 iFileMode = EFileWrite;
156 if (iFileMode == EFileRead)
162 MCTWritableCertStore* temp = iFileCertStore;
169 error = KErrNotSupported;
173 if (error == KErrNotSupported)
177 else if ((error != KErrNone) || !result)
183 (*refCountInterface)++;
184 aReturnedInterface = result;
187 TRequestStatus* r = &aStatus;
188 User::RequestComplete(r, error);
191 TBool CTest1CertStoreToken::DoCancelGetInterface()
196 CTest1CertStoreToken::CTest1CertStoreToken(CTest1CertStoreTokenType::TTokenId aTokenId,
197 CTest1CertStoreTokenType& aFileCertStoreTokenType)
198 : iTokenType(aFileCertStoreTokenType), iTokenId(aTokenId)