|
1 /* |
|
2 * Copyright (c) 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tasymmetricmisc.h" |
|
20 #include "t_input.h" |
|
21 #include <asymmetric.h> |
|
22 #include <random.h> |
|
23 #include <padding.h> |
|
24 #include <bigint.h> |
|
25 #include "tbrokenrandom.h" |
|
26 |
|
27 enum TActionMode {EDHKeyPair = 1, EDHPrivateKey =2, EDHPublicKey =3}; |
|
28 |
|
29 CTestAction* CAsymmetricMiscellaneous::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, |
|
30 const TTestActionSpec& aTestActionSpec) |
|
31 { |
|
32 CTestAction* self = CAsymmetricMiscellaneous::NewLC(aFs, aConsole, |
|
33 aOut, aTestActionSpec); |
|
34 CleanupStack::Pop(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 CTestAction* CAsymmetricMiscellaneous::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, |
|
39 const TTestActionSpec& aTestActionSpec) |
|
40 { |
|
41 CAsymmetricMiscellaneous* self = new(ELeave) CAsymmetricMiscellaneous(aFs, aConsole, aOut); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(aTestActionSpec); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CAsymmetricMiscellaneous::~CAsymmetricMiscellaneous() |
|
48 { |
|
49 delete iBody; |
|
50 } |
|
51 |
|
52 CAsymmetricMiscellaneous::CAsymmetricMiscellaneous(RFs& aFs, CConsoleBase& aConsole, Output& aOut) |
|
53 : CTestAction(aConsole, aOut), iFs(aFs) |
|
54 { |
|
55 } |
|
56 |
|
57 void CAsymmetricMiscellaneous::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
58 { |
|
59 CTestAction::ConstructL(aTestActionSpec); |
|
60 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length()); |
|
61 iBody->Des().Copy(aTestActionSpec.iActionBody); |
|
62 |
|
63 iActionMode = Input::ParseIntElement(*iBody, _L8("<actionmode>"), _L8("</actionmode>")); |
|
64 |
|
65 HBufC8* g = Input::ParseElementHexL(*iBody, _L8("<g>")); |
|
66 CleanupStack::PushL(g); |
|
67 iG = RInteger::NewL(*g); |
|
68 CleanupStack::PopAndDestroy(g); |
|
69 |
|
70 HBufC8* n = Input::ParseElementHexL(*iBody, _L8("<n>")); |
|
71 CleanupStack::PushL(n); |
|
72 iN = RInteger::NewL(*n); |
|
73 CleanupStack::PopAndDestroy(n); |
|
74 |
|
75 HBufC8* x = Input::ParseElementHexL(*iBody, _L8("<x>")); |
|
76 CleanupStack::PushL(x); |
|
77 iX = RInteger::NewL(*x); |
|
78 CleanupStack::PopAndDestroy(x); |
|
79 } |
|
80 |
|
81 void CAsymmetricMiscellaneous::DoPerformPrerequisite(TRequestStatus& aStatus) |
|
82 { |
|
83 TRequestStatus* status = &aStatus; |
|
84 User::RequestComplete(status, KErrNone); |
|
85 iActionState = CTestAction::EAction; |
|
86 } |
|
87 |
|
88 void CAsymmetricMiscellaneous::DoPerformPostrequisite(TRequestStatus& aStatus) |
|
89 { |
|
90 TRequestStatus* status = &aStatus; |
|
91 |
|
92 iFinished = ETrue; |
|
93 User::RequestComplete(status, KErrNone); |
|
94 } |
|
95 |
|
96 void CAsymmetricMiscellaneous::DoReportAction(void) |
|
97 { |
|
98 } |
|
99 |
|
100 void CAsymmetricMiscellaneous::DoCheckResult(TInt) |
|
101 { |
|
102 if (iResult) |
|
103 iConsole.Printf(_L(".")); |
|
104 else |
|
105 iConsole.Printf(_L("X")); |
|
106 } |
|
107 |
|
108 void CAsymmetricMiscellaneous::PerformAction(TRequestStatus& aStatus) |
|
109 { |
|
110 __UHEAP_MARK; |
|
111 TRequestStatus* status = &aStatus; |
|
112 iResult = ETrue; |
|
113 |
|
114 // Construction of dummy objects just to cover the left over methods. |
|
115 switch (iActionMode) |
|
116 { |
|
117 case EDHKeyPair: |
|
118 { |
|
119 CDHKeyPair* dhKeyPair = CDHKeyPair::NewLC(iN, iG, iX); |
|
120 if (dhKeyPair == NULL) |
|
121 { |
|
122 iResult = EFalse; |
|
123 } |
|
124 CleanupStack::PopAndDestroy(dhKeyPair); |
|
125 } |
|
126 break; |
|
127 |
|
128 case EDHPrivateKey: |
|
129 { |
|
130 CDHPrivateKey* dhPrivateKey = CDHPrivateKey::NewLC(iN, iG, iX); |
|
131 if (dhPrivateKey == NULL) |
|
132 { |
|
133 iResult = EFalse; |
|
134 } |
|
135 CleanupStack::PopAndDestroy(dhPrivateKey); |
|
136 } |
|
137 break; |
|
138 |
|
139 case EDHPublicKey: |
|
140 { |
|
141 CDHPublicKey* dhPublicKeyPtr = CDHPublicKey::NewLC(iN, iG, iX); |
|
142 if (dhPublicKeyPtr == NULL) |
|
143 { |
|
144 iResult = EFalse; |
|
145 } |
|
146 CleanupStack::PopAndDestroy(dhPublicKeyPtr); |
|
147 } |
|
148 break; |
|
149 |
|
150 default: |
|
151 break; |
|
152 } |
|
153 User::RequestComplete(status, KErrNone); |
|
154 iActionState = CTestAction::EPostrequisite; |
|
155 __UHEAP_MARKEND; |
|
156 } |