os/security/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_addkey.cpp
First public contribution.
2 * Copyright (c) 2003-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 <unifiedkeystore.h>
21 #include "t_keystore_actions.h"
22 #include "t_keystore_defs.h"
26 _LIT(KEllipsis, "...");
28 /////////////////////////////////////////////////////////////////////////////////
30 /////////////////////////////////////////////////////////////////////////////////
32 CTestAction* CAddKey::NewL(RFs& aFs,
33 CConsoleBase& aConsole,
35 const TTestActionSpec& aTestActionSpec)
37 CTestAction* self = CAddKey::NewLC(aFs, aConsole, aOut, aTestActionSpec);
38 CleanupStack::Pop(self);
42 CTestAction* CAddKey::NewLC(RFs& aFs,
43 CConsoleBase& aConsole,
45 const TTestActionSpec& aTestActionSpec)
47 CAddKey* self = new (ELeave) CAddKey(aFs, aConsole, aOut);
48 CleanupStack::PushL(self);
49 self->ConstructL(aTestActionSpec);
61 CAddKey::CAddKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
62 CKeyStoreTestAction(aFs, aConsole, aOut), iState(EAddKey)
66 void CAddKey::ConstructL(const TTestActionSpec& aTestActionSpec)
68 CKeyStoreTestAction::ConstructL(aTestActionSpec);
70 SetKeySize(Input::ParseElement(aTestActionSpec.iActionBody, KKeySizeStart));
71 SetStartDateL(Input::ParseElement(aTestActionSpec.iActionBody, KKeyStartDateStart));
72 SetEndDateL(Input::ParseElement(aTestActionSpec.iActionBody, KKeyEndDateStart));
75 void CAddKey::SetKeySize(const TDesC8& aKeySize)
81 void CAddKey::PerformAction(TRequestStatus& aStatus)
87 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
88 if(iKeyStoreImplLabel.Length() != 0)
90 SetKeyStoreIndex(keyStore);
93 #ifdef SYMBIAN_AUTH_SERVER
96 keyStore->CreateKey(iKeyStoreImplIndex, iUsage, iSize, *iLabel, iAlgorithm,
97 iAccessType, iStartDate, iEndDate, *iAuthExpression, iFreshness, iKeyInfo, aStatus);
100 #endif // SYMBIAN_AUTH_SERVER
102 keyStore->CreateKey(iKeyStoreImplIndex, iUsage, iSize, *iLabel, iAlgorithm,
103 iAccessType, iStartDate, iEndDate, iKeyInfo, aStatus);
112 TRequestStatus* status = &aStatus;
113 User::RequestComplete(status, aStatus.Int());
114 if (aStatus == iExpectedResult)
123 iActionState = EPostrequisite;
128 break; // Nothing to do, for the compiler
132 void CAddKey::PerformCancel()
134 if (iState == EFinished)
136 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
137 keyStore->CancelCreateKey();
141 void CAddKey::Reset()
144 if (iKeyInfo != NULL)
151 void CAddKey::DoReportAction()
153 _LIT(KAdding, "Adding key...");
154 iOut.writeString(KAdding);
156 iOut.writeString(iLabel->Left(32));
157 if (iLabel->Length() > 32)
159 iOut.writeString(KEllipsis);
166 void CAddKey::DoCheckResult(TInt aError)
170 if (aError == KErrNone)
172 _LIT(KSuccessful, "Key added successfully\n");
173 iConsole.Write(KSuccessful);
174 iOut.writeString(KSuccessful);
180 if (aError!=iExpectedResult)
182 _LIT(KFailed, "!!!Key adding failure!!!\n");
183 iConsole.Write(KFailed);
184 iOut.writeString(KFailed);
188 _LIT(KFailed, "Key adding failed, but expected\n");
189 iConsole.Write(KFailed);
190 iOut.writeString(KFailed);
200 void CAddKey::SetStartDateL(const TDesC8& aData)
202 if (aData.Length() == 0)
205 HBufC* buf = HBufC::NewLC(aData.Length());
206 TPtr ptr = buf->Des();
208 User::LeaveIfError(iStartDate.Parse(*buf));
209 CleanupStack::PopAndDestroy(buf);
212 void CAddKey::SetEndDateL(const TDesC8& aData)
214 if (aData.Length() == 0)
217 HBufC* buf = HBufC::NewLC(aData.Length());
218 TPtr ptr = buf->Des();
220 User::LeaveIfError(iEndDate.Parse(*buf));
221 CleanupStack::PopAndDestroy(buf);