|
1 /* |
|
2 * Copyright (c) 1998-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 * tdsasignfb.cpp |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "t_input.h" |
|
21 #include "t_output.h" |
|
22 #include <asymmetric.h> |
|
23 #include "tvectorutils.h" |
|
24 #include "trsaparams.h" |
|
25 |
|
26 _LIT8(KModStart, "<modulus>"); |
|
27 _LIT8(KModEnd, "</modulus>"); |
|
28 _LIT8(KPubExpStart, "<publicExponent>"); |
|
29 _LIT8(KPubExpEnd, "</publicExponent>"); |
|
30 _LIT8(KPrivExpStart, "<privateExponent>"); |
|
31 _LIT8(KPrivExpEnd, "</privateExponent>"); |
|
32 _LIT8(KPStart, "<P>"); |
|
33 _LIT8(KPEnd, "</P>"); |
|
34 _LIT8(KQStart, "<Q>"); |
|
35 _LIT8(KQEnd, "</Q>"); |
|
36 _LIT8(KdPStart, "<dP>"); |
|
37 _LIT8(KdPEnd, "</dP>"); |
|
38 _LIT8(KdQStart, "<dQ>"); |
|
39 _LIT8(KdQEnd, "</dQ>"); |
|
40 _LIT8(KqInvStart, "<qInv>"); |
|
41 _LIT8(KqInvEnd, "</qInv>"); |
|
42 _LIT8(KReturnCodeStart, "<return>"); |
|
43 _LIT8(KReturnCodeEnd, "</return>"); |
|
44 _LIT8(KErrArgumentString, "KErrArgument"); |
|
45 |
|
46 CTestAction* CRSATestPublicKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, |
|
47 const TTestActionSpec& aTestActionSpec) |
|
48 { |
|
49 CTestAction* self = CRSATestPublicKey::NewLC(aFs, aConsole, |
|
50 aOut, aTestActionSpec); |
|
51 CleanupStack::Pop(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 CTestAction* CRSATestPublicKey::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, |
|
56 const TTestActionSpec& aTestActionSpec) |
|
57 { |
|
58 CRSATestPublicKey* self = new(ELeave) CRSATestPublicKey(aFs, aConsole, aOut); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(aTestActionSpec); |
|
61 return self; |
|
62 } |
|
63 |
|
64 CRSATestPublicKey::~CRSATestPublicKey() |
|
65 { |
|
66 delete iBody; |
|
67 } |
|
68 |
|
69 CRSATestPublicKey::CRSATestPublicKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut) |
|
70 : CTestAction(aConsole, aOut), iFs(aFs) |
|
71 { |
|
72 } |
|
73 |
|
74 void CRSATestPublicKey::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
75 { |
|
76 CTestAction::ConstructL(aTestActionSpec); |
|
77 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length()); |
|
78 iBody->Des().Copy(aTestActionSpec.iActionBody); |
|
79 |
|
80 iExpectedReturnValue = KErrNone; |
|
81 TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd); |
|
82 if(returnValue.Compare(KErrArgumentString) == 0) |
|
83 { |
|
84 iExpectedReturnValue = KErrArgument; |
|
85 } |
|
86 |
|
87 } |
|
88 |
|
89 void CRSATestPublicKey::DoPerformPrerequisite(TRequestStatus& aStatus) |
|
90 { |
|
91 TRequestStatus* status = &aStatus; |
|
92 User::RequestComplete(status, KErrNone); |
|
93 iActionState = CTestAction::EAction; |
|
94 } |
|
95 |
|
96 void CRSATestPublicKey::DoPerformPostrequisite(TRequestStatus& aStatus) |
|
97 { |
|
98 TRequestStatus* status = &aStatus; |
|
99 |
|
100 iFinished = ETrue; |
|
101 User::RequestComplete(status, KErrNone); |
|
102 } |
|
103 |
|
104 void CRSATestPublicKey::DoReportAction(void) |
|
105 { |
|
106 } |
|
107 |
|
108 void CRSATestPublicKey::DoCheckResult(TInt) |
|
109 { |
|
110 if (iResult) |
|
111 iConsole.Printf(_L(".")); |
|
112 else |
|
113 iConsole.Printf(_L("X")); |
|
114 } |
|
115 |
|
116 void CRSATestPublicKey::PerformAction(TRequestStatus& aStatus) |
|
117 { |
|
118 __UHEAP_MARK; |
|
119 TRequestStatus* status = &aStatus; |
|
120 iResult = EFalse; |
|
121 |
|
122 TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd); |
|
123 RInteger mod = VectorUtils::ParseIntegerL(modIn); |
|
124 CleanupStack::PushL(mod); |
|
125 |
|
126 TPtrC8 expIn = Input::ParseElement(*iBody, KPubExpStart, KPubExpEnd); |
|
127 RInteger exp = VectorUtils::ParseIntegerL(expIn); |
|
128 CleanupStack::PushL(exp); |
|
129 |
|
130 |
|
131 CRSAPublicKey* key = NULL; |
|
132 TRAPD(err, key = CRSAPublicKey::NewL(mod, exp)); |
|
133 if(err == iExpectedReturnValue) |
|
134 { |
|
135 iResult=ETrue; |
|
136 } |
|
137 else |
|
138 { |
|
139 iOut.writeString(_L("CRSAPublicKey construction did not return expected result\n")); |
|
140 } |
|
141 if(err != KErrNone) |
|
142 { |
|
143 CleanupStack::PopAndDestroy(2); |
|
144 } |
|
145 else |
|
146 { |
|
147 CleanupStack::PushL(key); |
|
148 CleanupStack::PopAndDestroy(3); |
|
149 } |
|
150 |
|
151 User::RequestComplete(status, KErrNone); |
|
152 iActionState = CTestAction::EPostrequisite; |
|
153 __UHEAP_MARKEND; |
|
154 } |
|
155 |
|
156 |
|
157 CTestAction* CRSATestPrivateKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, |
|
158 const TTestActionSpec& aTestActionSpec) |
|
159 { |
|
160 CTestAction* self = CRSATestPrivateKey::NewLC(aFs, aConsole, |
|
161 aOut, aTestActionSpec); |
|
162 CleanupStack::Pop(); |
|
163 return self; |
|
164 } |
|
165 |
|
166 CTestAction* CRSATestPrivateKey::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, |
|
167 const TTestActionSpec& aTestActionSpec) |
|
168 { |
|
169 CRSATestPrivateKey* self = new(ELeave) CRSATestPrivateKey(aFs, aConsole, aOut); |
|
170 CleanupStack::PushL(self); |
|
171 self->ConstructL(aTestActionSpec); |
|
172 return self; |
|
173 } |
|
174 |
|
175 CRSATestPrivateKey::~CRSATestPrivateKey() |
|
176 { |
|
177 delete iBody; |
|
178 } |
|
179 |
|
180 CRSATestPrivateKey::CRSATestPrivateKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut) |
|
181 : CTestAction(aConsole, aOut), iFs(aFs) |
|
182 { |
|
183 } |
|
184 |
|
185 void CRSATestPrivateKey::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
186 { |
|
187 CTestAction::ConstructL(aTestActionSpec); |
|
188 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length()); |
|
189 iBody->Des().Copy(aTestActionSpec.iActionBody); |
|
190 |
|
191 iExpectedReturnValue = KErrNone; |
|
192 TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd); |
|
193 if(returnValue.Compare(KErrArgumentString) == 0) |
|
194 { |
|
195 iExpectedReturnValue = KErrArgument; |
|
196 } |
|
197 |
|
198 } |
|
199 |
|
200 void CRSATestPrivateKey::DoPerformPrerequisite(TRequestStatus& aStatus) |
|
201 { |
|
202 TRequestStatus* status = &aStatus; |
|
203 User::RequestComplete(status, KErrNone); |
|
204 iActionState = CTestAction::EAction; |
|
205 } |
|
206 |
|
207 void CRSATestPrivateKey::DoPerformPostrequisite(TRequestStatus& aStatus) |
|
208 { |
|
209 TRequestStatus* status = &aStatus; |
|
210 |
|
211 iFinished = ETrue; |
|
212 User::RequestComplete(status, KErrNone); |
|
213 } |
|
214 |
|
215 void CRSATestPrivateKey::DoReportAction(void) |
|
216 { |
|
217 } |
|
218 |
|
219 void CRSATestPrivateKey::DoCheckResult(TInt) |
|
220 { |
|
221 if (iResult) |
|
222 iConsole.Printf(_L(".")); |
|
223 else |
|
224 iConsole.Printf(_L("X")); |
|
225 } |
|
226 |
|
227 void CRSATestPrivateKey::PerformAction(TRequestStatus& aStatus) |
|
228 { |
|
229 __UHEAP_MARK; |
|
230 TRequestStatus* status = &aStatus; |
|
231 iResult = EFalse; |
|
232 |
|
233 TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd); |
|
234 RInteger mod = VectorUtils::ParseIntegerL(modIn); |
|
235 CleanupStack::PushL(mod); |
|
236 |
|
237 TPtrC8 expIn = Input::ParseElement(*iBody, KPrivExpStart, KPrivExpEnd); |
|
238 RInteger exp = VectorUtils::ParseIntegerL(expIn); |
|
239 CleanupStack::PushL(exp); |
|
240 |
|
241 |
|
242 CRSAPrivateKeyStandard* key = NULL; |
|
243 TRAPD(err, key = CRSAPrivateKeyStandard::NewL(mod, exp)); |
|
244 if(err == iExpectedReturnValue) |
|
245 { |
|
246 iResult=ETrue; |
|
247 } |
|
248 else |
|
249 { |
|
250 iOut.writeString(_L("CRSAPrivateKey construction did not return expected result\n")); |
|
251 } |
|
252 if(err != KErrNone) |
|
253 { |
|
254 CleanupStack::PopAndDestroy(2); |
|
255 } |
|
256 else |
|
257 { |
|
258 CleanupStack::PushL(key); |
|
259 CleanupStack::PopAndDestroy(3); |
|
260 } |
|
261 |
|
262 User::RequestComplete(status, KErrNone); |
|
263 iActionState = CTestAction::EPostrequisite; |
|
264 __UHEAP_MARKEND; |
|
265 } |
|
266 |
|
267 CTestAction* CRSATestPrivateKeyCRT::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, |
|
268 const TTestActionSpec& aTestActionSpec) |
|
269 { |
|
270 CTestAction* self = CRSATestPrivateKeyCRT::NewLC(aFs, aConsole, |
|
271 aOut, aTestActionSpec); |
|
272 CleanupStack::Pop(); |
|
273 return self; |
|
274 } |
|
275 |
|
276 CTestAction* CRSATestPrivateKeyCRT::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, |
|
277 const TTestActionSpec& aTestActionSpec) |
|
278 { |
|
279 CRSATestPrivateKeyCRT* self = new(ELeave) CRSATestPrivateKeyCRT(aFs, aConsole, aOut); |
|
280 CleanupStack::PushL(self); |
|
281 self->ConstructL(aTestActionSpec); |
|
282 return self; |
|
283 } |
|
284 |
|
285 CRSATestPrivateKeyCRT::~CRSATestPrivateKeyCRT() |
|
286 { |
|
287 delete iBody; |
|
288 } |
|
289 |
|
290 CRSATestPrivateKeyCRT::CRSATestPrivateKeyCRT(RFs& aFs, CConsoleBase& aConsole, Output& aOut) |
|
291 : CTestAction(aConsole, aOut), iFs(aFs) |
|
292 { |
|
293 } |
|
294 |
|
295 void CRSATestPrivateKeyCRT::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
296 { |
|
297 CTestAction::ConstructL(aTestActionSpec); |
|
298 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length()); |
|
299 iBody->Des().Copy(aTestActionSpec.iActionBody); |
|
300 |
|
301 iExpectedReturnValue = KErrNone; |
|
302 TPtrC8 returnValue = Input::ParseElement(aTestActionSpec.iActionResult, KReturnCodeStart, KReturnCodeEnd); |
|
303 if(returnValue.Compare(KErrArgumentString) == 0) |
|
304 { |
|
305 iExpectedReturnValue = KErrArgument; |
|
306 } |
|
307 |
|
308 } |
|
309 |
|
310 void CRSATestPrivateKeyCRT::DoPerformPrerequisite(TRequestStatus& aStatus) |
|
311 { |
|
312 TRequestStatus* status = &aStatus; |
|
313 User::RequestComplete(status, KErrNone); |
|
314 iActionState = CTestAction::EAction; |
|
315 } |
|
316 |
|
317 void CRSATestPrivateKeyCRT::DoPerformPostrequisite(TRequestStatus& aStatus) |
|
318 { |
|
319 TRequestStatus* status = &aStatus; |
|
320 |
|
321 iFinished = ETrue; |
|
322 User::RequestComplete(status, KErrNone); |
|
323 } |
|
324 |
|
325 void CRSATestPrivateKeyCRT::DoReportAction(void) |
|
326 { |
|
327 } |
|
328 |
|
329 void CRSATestPrivateKeyCRT::DoCheckResult(TInt) |
|
330 { |
|
331 if (iResult) |
|
332 iConsole.Printf(_L(".")); |
|
333 else |
|
334 iConsole.Printf(_L("X")); |
|
335 } |
|
336 |
|
337 void CRSATestPrivateKeyCRT::PerformAction(TRequestStatus& aStatus) |
|
338 { |
|
339 __UHEAP_MARK; |
|
340 TRequestStatus* status = &aStatus; |
|
341 iResult = EFalse; |
|
342 |
|
343 TPtrC8 modIn = Input::ParseElement(*iBody, KModStart, KModEnd); |
|
344 RInteger mod = VectorUtils::ParseIntegerL(modIn); |
|
345 CleanupStack::PushL(mod); |
|
346 |
|
347 TPtrC8 PIn = Input::ParseElement(*iBody, KPStart, KPEnd); |
|
348 RInteger P = VectorUtils::ParseIntegerL(PIn); |
|
349 CleanupStack::PushL(P); |
|
350 |
|
351 TPtrC8 QIn = Input::ParseElement(*iBody, KQStart, KQEnd); |
|
352 RInteger Q = VectorUtils::ParseIntegerL(QIn); |
|
353 CleanupStack::PushL(Q); |
|
354 |
|
355 TPtrC8 dPIn = Input::ParseElement(*iBody, KdPStart, KdPEnd); |
|
356 RInteger dP = VectorUtils::ParseIntegerL(dPIn); |
|
357 CleanupStack::PushL(dP); |
|
358 |
|
359 TPtrC8 dQIn = Input::ParseElement(*iBody, KdQStart, KdQEnd); |
|
360 RInteger dQ = VectorUtils::ParseIntegerL(dQIn); |
|
361 CleanupStack::PushL(dQ); |
|
362 |
|
363 TPtrC8 QInvIn = Input::ParseElement(*iBody, KqInvStart, KqInvEnd); |
|
364 RInteger QInv = VectorUtils::ParseIntegerL(QInvIn); |
|
365 CleanupStack::PushL(QInv); |
|
366 |
|
367 |
|
368 CRSAPrivateKeyCRT* key = NULL; |
|
369 TRAPD(err, key = CRSAPrivateKeyCRT::NewL(mod, P, Q, dP, dQ, QInv)); |
|
370 if(err == iExpectedReturnValue) |
|
371 { |
|
372 iResult=ETrue; |
|
373 } |
|
374 else |
|
375 { |
|
376 iOut.writeString(_L("CRSAPrivateKeyCRT construction did not return expected result\n")); |
|
377 } |
|
378 if(err != KErrNone) |
|
379 { |
|
380 CleanupStack::PopAndDestroy(6); |
|
381 } |
|
382 else |
|
383 { |
|
384 CleanupStack::PushL(key); |
|
385 CleanupStack::PopAndDestroy(7); |
|
386 } |
|
387 |
|
388 User::RequestComplete(status, KErrNone); |
|
389 iActionState = CTestAction::EPostrequisite; |
|
390 __UHEAP_MARKEND; |
|
391 } |