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 <e32base.h>
|
sl@0
|
20 |
#include "t_keystore_actions.h"
|
sl@0
|
21 |
#include "t_keystore_defs.h"
|
sl@0
|
22 |
#include "t_input.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
/*static*/ CTestAction* CDeleteKeys::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
25 |
{
|
sl@0
|
26 |
CTestAction* self = CDeleteKeys::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
27 |
CleanupStack::Pop(self);
|
sl@0
|
28 |
return self;
|
sl@0
|
29 |
}
|
sl@0
|
30 |
|
sl@0
|
31 |
/*static*/ CTestAction* CDeleteKeys::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
CDeleteKeys* self = new (ELeave) CDeleteKeys(aFs, aConsole, aOut);
|
sl@0
|
34 |
CleanupStack::PushL(self);
|
sl@0
|
35 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
36 |
return self;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
CDeleteKeys::~CDeleteKeys()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
iKeys.Close();
|
sl@0
|
42 |
}
|
sl@0
|
43 |
|
sl@0
|
44 |
void CDeleteKeys::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
if (aStatus != KErrNone)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
iState = EFinished;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
52 |
ASSERT(keyStore);
|
sl@0
|
53 |
|
sl@0
|
54 |
switch (iState)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
case EListKeys:
|
sl@0
|
57 |
keyStore->List(iKeys, iFilter, aStatus);
|
sl@0
|
58 |
|
sl@0
|
59 |
if (*iLabel != KNullDesC)
|
sl@0
|
60 |
iState = EDeleteKeyByLabel;
|
sl@0
|
61 |
else if (iNonExistentKey)
|
sl@0
|
62 |
iState = EDeleteNonExistentKey;
|
sl@0
|
63 |
else
|
sl@0
|
64 |
iState = EDeleteAllKeys;
|
sl@0
|
65 |
|
sl@0
|
66 |
break;
|
sl@0
|
67 |
|
sl@0
|
68 |
case EDeleteKeyByLabel:
|
sl@0
|
69 |
for ( ; iDeleteIndex < iKeys.Count() ; ++iDeleteIndex)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
CCTKeyInfo* key = iKeys[iDeleteIndex];
|
sl@0
|
72 |
if (key->Label() == *iLabel)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
keyStore->DeleteKey(*key, aStatus);
|
sl@0
|
75 |
++iDeletedCount;
|
sl@0
|
76 |
break;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
if (iDeleteIndex == iKeys.Count())
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TRequestStatus* status = &aStatus;
|
sl@0
|
83 |
User::RequestComplete(status, KErrNotFound);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
iState = EFinished;
|
sl@0
|
87 |
break;
|
sl@0
|
88 |
|
sl@0
|
89 |
case EDeleteNonExistentKey:
|
sl@0
|
90 |
{
|
sl@0
|
91 |
// Skip test if we want to delete a non-existant key, but there are
|
sl@0
|
92 |
// no keys present to get token handle from - this happens if
|
sl@0
|
93 |
// previous tests fail
|
sl@0
|
94 |
if (iKeys.Count() == 0)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
_LIT(KSkippingTest, "!!!No keys present, skipping delete non-existant key test!!!\n");
|
sl@0
|
97 |
iConsole.Write(KSkippingTest);
|
sl@0
|
98 |
iOut.writeString(KSkippingTest);
|
sl@0
|
99 |
iActionState = EPostrequisite;
|
sl@0
|
100 |
TRequestStatus* status = &aStatus;
|
sl@0
|
101 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
102 |
break;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
CCTKeyInfo* keyInfo = iKeys[0];
|
sl@0
|
106 |
iDeleteHandle = keyInfo->Handle();
|
sl@0
|
107 |
if (iNonExistentKey > 0)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
// Modify the handle to a key that will not exist
|
sl@0
|
110 |
iDeleteHandle.iObjectId = 0xfbadcafe;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
iState = EFinished;
|
sl@0
|
114 |
keyStore->DeleteKey(iDeleteHandle, aStatus);
|
sl@0
|
115 |
}
|
sl@0
|
116 |
break;
|
sl@0
|
117 |
|
sl@0
|
118 |
case EDeleteAllKeys:
|
sl@0
|
119 |
if (iDeleteIndex < iKeys.Count())
|
sl@0
|
120 |
{
|
sl@0
|
121 |
iState = EDeleteAllKeys;
|
sl@0
|
122 |
keyStore->DeleteKey(*iKeys[iDeleteIndex], aStatus);
|
sl@0
|
123 |
++iDeleteIndex;
|
sl@0
|
124 |
++iDeletedCount;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
else
|
sl@0
|
127 |
{
|
sl@0
|
128 |
iState = EFinished;
|
sl@0
|
129 |
TRequestStatus* status = &aStatus;
|
sl@0
|
130 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
break;
|
sl@0
|
133 |
|
sl@0
|
134 |
case EFinished:
|
sl@0
|
135 |
{
|
sl@0
|
136 |
iOut.writeString(_L("Delete: initial key count == "));
|
sl@0
|
137 |
iOut.writeNum(iKeys.Count());
|
sl@0
|
138 |
iOut.writeNewLine();
|
sl@0
|
139 |
iOut.writeString(_L("Delete: delete count == "));
|
sl@0
|
140 |
iOut.writeNum(iDeletedCount);
|
sl@0
|
141 |
iOut.writeNewLine();
|
sl@0
|
142 |
iOut.writeString(_L("Delete: status == "));
|
sl@0
|
143 |
iOut.writeNum(aStatus.Int());
|
sl@0
|
144 |
iOut.writeNewLine();
|
sl@0
|
145 |
|
sl@0
|
146 |
if (aStatus != KErrNone && iDeletedCount > 0)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
// Attempt to delete key failed, adjust count
|
sl@0
|
149 |
--iDeletedCount;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
iResult = (aStatus == iExpectedResult) &&
|
sl@0
|
153 |
(iExpectedDeleteCount == iDeletedCount || iExpectedDeleteCount == -1);
|
sl@0
|
154 |
|
sl@0
|
155 |
iActionState = EPostrequisite;
|
sl@0
|
156 |
|
sl@0
|
157 |
TRequestStatus* status = &aStatus;
|
sl@0
|
158 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
159 |
}
|
sl@0
|
160 |
break;
|
sl@0
|
161 |
|
sl@0
|
162 |
default:
|
sl@0
|
163 |
User::Invariant();
|
sl@0
|
164 |
}
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
void CDeleteKeys::PerformCancel()
|
sl@0
|
168 |
{
|
sl@0
|
169 |
CUnifiedKeyStore* keystore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
170 |
ASSERT(keystore);
|
sl@0
|
171 |
keystore->Cancel();
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
void CDeleteKeys::Reset()
|
sl@0
|
175 |
{
|
sl@0
|
176 |
iState = EListKeys;
|
sl@0
|
177 |
iDeleteIndex = 0;
|
sl@0
|
178 |
iDeletedCount = 0;
|
sl@0
|
179 |
iKeys.Close();
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
void CDeleteKeys::DoReportAction()
|
sl@0
|
183 |
{
|
sl@0
|
184 |
_LIT(KDeleting, "Deleting...");
|
sl@0
|
185 |
iOut.writeString(KDeleting);
|
sl@0
|
186 |
iOut.writeNewLine();
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
void CDeleteKeys::DoCheckResult(TInt aError)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
if (iFinished)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
TBuf<256> buf;
|
sl@0
|
194 |
if (aError == KErrNone)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
if (iExpectedDeleteCount!=-1)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
_LIT(KSuccessful, "%d Key(s) deleted successfully (expected to delete %d)\n");
|
sl@0
|
199 |
buf.Format(KSuccessful, iDeletedCount, iExpectedDeleteCount);
|
sl@0
|
200 |
iConsole.Write(buf);
|
sl@0
|
201 |
iOut.writeString(buf);
|
sl@0
|
202 |
iOut.writeNewLine();
|
sl@0
|
203 |
}
|
sl@0
|
204 |
}
|
sl@0
|
205 |
else
|
sl@0
|
206 |
{
|
sl@0
|
207 |
if (aError!=iExpectedResult)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
if (iExpectedDeleteCount!=-1)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
_LIT(KFailed, "!!!Key delete failure %d!!!\n");
|
sl@0
|
212 |
buf.Format(KFailed, aError);
|
sl@0
|
213 |
iConsole.Write(buf);
|
sl@0
|
214 |
iOut.writeString(buf);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
}
|
sl@0
|
217 |
else
|
sl@0
|
218 |
{
|
sl@0
|
219 |
_LIT(KFailed, "Key delete failed, but expected\n");
|
sl@0
|
220 |
iConsole.Write(KFailed);
|
sl@0
|
221 |
iOut.writeString(KFailed);
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
iOut.writeNewLine();
|
sl@0
|
225 |
}
|
sl@0
|
226 |
}
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
CDeleteKeys::CDeleteKeys(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
|
sl@0
|
230 |
: CKeyStoreTestAction(aFs, aConsole, aOut),
|
sl@0
|
231 |
iInitialKeyCount(-1),
|
sl@0
|
232 |
iFinalKeyCount(0),
|
sl@0
|
233 |
iDeletedCount(0),
|
sl@0
|
234 |
iDeleteIndex(0),
|
sl@0
|
235 |
iNonExistentKey(0),
|
sl@0
|
236 |
iExpectedDeleteCount(-1)
|
sl@0
|
237 |
{}
|
sl@0
|
238 |
|
sl@0
|
239 |
void CDeleteKeys::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
240 |
{
|
sl@0
|
241 |
CKeyStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
242 |
iFilter.iKeyAlgorithm = iAlgorithm;
|
sl@0
|
243 |
|
sl@0
|
244 |
TPtrC8 buf(0,0);
|
sl@0
|
245 |
buf.Set(Input::ParseElement(aTestActionSpec.iActionBody, KNonExistentKeyStart));
|
sl@0
|
246 |
if (buf.Length() != 0)
|
sl@0
|
247 |
SetNonExistent(buf);
|
sl@0
|
248 |
|
sl@0
|
249 |
buf.Set(Input::ParseElement(aTestActionSpec.iActionBody, KDeleteCountStart));
|
sl@0
|
250 |
if (buf.Length() != 0)
|
sl@0
|
251 |
SetDeleteCount(buf);
|
sl@0
|
252 |
|
sl@0
|
253 |
buf.Set(Input::ParseElement(aTestActionSpec.iActionBody, KOwnerStart));
|
sl@0
|
254 |
if (buf.Length() != 0)
|
sl@0
|
255 |
{
|
sl@0
|
256 |
User::Leave(KErrNotSupported);
|
sl@0
|
257 |
}
|
sl@0
|
258 |
|
sl@0
|
259 |
if (*iLabel != KNullDesC || iNonExistentKey)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
iFilter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
|
sl@0
|
262 |
}
|
sl@0
|
263 |
else
|
sl@0
|
264 |
{
|
sl@0
|
265 |
iFilter.iPolicyFilter = TCTKeyAttributeFilter::EManageableKeys;
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
iState = EListKeys;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
|
sl@0
|
272 |
void CDeleteKeys::SetNonExistent(const TDesC8& aNonExistent)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
TLex8 lexer(aNonExistent);
|
sl@0
|
275 |
lexer.Val(iNonExistentKey);
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
void CDeleteKeys::SetDeleteCount(const TDesC8& aDeleteCount)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
TLex8 lexer(aDeleteCount);
|
sl@0
|
281 |
lexer.Val(iExpectedDeleteCount);
|
sl@0
|
282 |
}
|