sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-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 |
#include <unifiedkeystore.h>
|
sl@0
|
20 |
#include <e32base.h>
|
sl@0
|
21 |
#include "t_keystore_actions.h"
|
sl@0
|
22 |
#include "t_keystore_defs.h"
|
sl@0
|
23 |
#include "t_input.h"
|
sl@0
|
24 |
#include "t_output.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
_LIT(KEllipsis, "...");
|
sl@0
|
27 |
|
sl@0
|
28 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
29 |
// CAddKey
|
sl@0
|
30 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
31 |
|
sl@0
|
32 |
CTestAction* CAddKey::NewL(RFs& aFs,
|
sl@0
|
33 |
CConsoleBase& aConsole,
|
sl@0
|
34 |
Output& aOut,
|
sl@0
|
35 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
CTestAction* self = CAddKey::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
38 |
CleanupStack::Pop(self);
|
sl@0
|
39 |
return self;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
CTestAction* CAddKey::NewLC(RFs& aFs,
|
sl@0
|
43 |
CConsoleBase& aConsole,
|
sl@0
|
44 |
Output& aOut,
|
sl@0
|
45 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
CAddKey* self = new (ELeave) CAddKey(aFs, aConsole, aOut);
|
sl@0
|
48 |
CleanupStack::PushL(self);
|
sl@0
|
49 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
50 |
return self;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
CAddKey::~CAddKey()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
if (iKeyInfo != NULL)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
iKeyInfo->Release();
|
sl@0
|
58 |
}
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
CAddKey::CAddKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
|
sl@0
|
62 |
CKeyStoreTestAction(aFs, aConsole, aOut), iState(EAddKey)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
void CAddKey::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
CKeyStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
69 |
|
sl@0
|
70 |
SetKeySize(Input::ParseElement(aTestActionSpec.iActionBody, KKeySizeStart));
|
sl@0
|
71 |
SetStartDateL(Input::ParseElement(aTestActionSpec.iActionBody, KKeyStartDateStart));
|
sl@0
|
72 |
SetEndDateL(Input::ParseElement(aTestActionSpec.iActionBody, KKeyEndDateStart));
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
void CAddKey::SetKeySize(const TDesC8& aKeySize)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
TLex8 lex(aKeySize);
|
sl@0
|
78 |
lex.Val(iSize);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
void CAddKey::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
switch (iState)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
case EAddKey:
|
sl@0
|
86 |
{
|
sl@0
|
87 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
88 |
if(iKeyStoreImplLabel.Length() != 0)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
SetKeyStoreIndex(keyStore);
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
#ifdef SYMBIAN_AUTH_SERVER
|
sl@0
|
94 |
if(iUseNewApi)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
keyStore->CreateKey(iKeyStoreImplIndex, iUsage, iSize, *iLabel, iAlgorithm,
|
sl@0
|
97 |
iAccessType, iStartDate, iEndDate, *iAuthExpression, iFreshness, iKeyInfo, aStatus);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
else
|
sl@0
|
100 |
#endif // SYMBIAN_AUTH_SERVER
|
sl@0
|
101 |
{
|
sl@0
|
102 |
keyStore->CreateKey(iKeyStoreImplIndex, iUsage, iSize, *iLabel, iAlgorithm,
|
sl@0
|
103 |
iAccessType, iStartDate, iEndDate, iKeyInfo, aStatus);
|
sl@0
|
104 |
|
sl@0
|
105 |
}
|
sl@0
|
106 |
iState = EFinished;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
break;
|
sl@0
|
109 |
|
sl@0
|
110 |
case EFinished:
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TRequestStatus* status = &aStatus;
|
sl@0
|
113 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
114 |
if (aStatus == iExpectedResult)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
iResult = ETrue;
|
sl@0
|
117 |
}
|
sl@0
|
118 |
else
|
sl@0
|
119 |
{
|
sl@0
|
120 |
iResult = EFalse;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
iActionState = EPostrequisite;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
break;
|
sl@0
|
126 |
|
sl@0
|
127 |
default:
|
sl@0
|
128 |
break; // Nothing to do, for the compiler
|
sl@0
|
129 |
}
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
void CAddKey::PerformCancel()
|
sl@0
|
133 |
{
|
sl@0
|
134 |
if (iState == EFinished)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
137 |
keyStore->CancelCreateKey();
|
sl@0
|
138 |
}
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
void CAddKey::Reset()
|
sl@0
|
142 |
{
|
sl@0
|
143 |
iState = EAddKey;
|
sl@0
|
144 |
if (iKeyInfo != NULL)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
iKeyInfo->Release();
|
sl@0
|
147 |
iKeyInfo = NULL;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
void CAddKey::DoReportAction()
|
sl@0
|
152 |
{
|
sl@0
|
153 |
_LIT(KAdding, "Adding key...");
|
sl@0
|
154 |
iOut.writeString(KAdding);
|
sl@0
|
155 |
|
sl@0
|
156 |
iOut.writeString(iLabel->Left(32));
|
sl@0
|
157 |
if (iLabel->Length() > 32)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
iOut.writeString(KEllipsis);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
iOut.writeNewLine();
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
|
sl@0
|
166 |
void CAddKey::DoCheckResult(TInt aError)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
if (iFinished)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
if (aError == KErrNone)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
_LIT(KSuccessful, "Key added successfully\n");
|
sl@0
|
173 |
iConsole.Write(KSuccessful);
|
sl@0
|
174 |
iOut.writeString(KSuccessful);
|
sl@0
|
175 |
iOut.writeNewLine();
|
sl@0
|
176 |
iOut.writeNewLine();
|
sl@0
|
177 |
}
|
sl@0
|
178 |
else
|
sl@0
|
179 |
{
|
sl@0
|
180 |
if (aError!=iExpectedResult)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
_LIT(KFailed, "!!!Key adding failure!!!\n");
|
sl@0
|
183 |
iConsole.Write(KFailed);
|
sl@0
|
184 |
iOut.writeString(KFailed);
|
sl@0
|
185 |
}
|
sl@0
|
186 |
else
|
sl@0
|
187 |
{
|
sl@0
|
188 |
_LIT(KFailed, "Key adding failed, but expected\n");
|
sl@0
|
189 |
iConsole.Write(KFailed);
|
sl@0
|
190 |
iOut.writeString(KFailed);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
iOut.writeNewLine();
|
sl@0
|
194 |
iOut.writeNewLine();
|
sl@0
|
195 |
}
|
sl@0
|
196 |
}
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
|
sl@0
|
200 |
void CAddKey::SetStartDateL(const TDesC8& aData)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
if (aData.Length() == 0)
|
sl@0
|
203 |
return;
|
sl@0
|
204 |
|
sl@0
|
205 |
HBufC* buf = HBufC::NewLC(aData.Length());
|
sl@0
|
206 |
TPtr ptr = buf->Des();
|
sl@0
|
207 |
ptr.Copy(aData);
|
sl@0
|
208 |
User::LeaveIfError(iStartDate.Parse(*buf));
|
sl@0
|
209 |
CleanupStack::PopAndDestroy(buf);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
void CAddKey::SetEndDateL(const TDesC8& aData)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
if (aData.Length() == 0)
|
sl@0
|
215 |
return;
|
sl@0
|
216 |
|
sl@0
|
217 |
HBufC* buf = HBufC::NewLC(aData.Length());
|
sl@0
|
218 |
TPtr ptr = buf->Des();
|
sl@0
|
219 |
ptr.Copy(aData);
|
sl@0
|
220 |
User::LeaveIfError(iEndDate.Parse(*buf));
|
sl@0
|
221 |
CleanupStack::PopAndDestroy(buf);
|
sl@0
|
222 |
}
|