|
1 /* |
|
2 * Copyright (c) 2007-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 * Example CTestStep derived implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalTechnology |
|
23 */ |
|
24 #include "keypairgeneratorpositiveobjectloadstep.h" |
|
25 |
|
26 |
|
27 #include "keypair.h" |
|
28 #include "cryptokeypairgeneratorapi.h" |
|
29 |
|
30 using namespace CryptoSpi; |
|
31 |
|
32 |
|
33 CKeyPairGeneratorPositiveObjectLoadStep::~CKeyPairGeneratorPositiveObjectLoadStep() |
|
34 { |
|
35 } |
|
36 |
|
37 CKeyPairGeneratorPositiveObjectLoadStep::CKeyPairGeneratorPositiveObjectLoadStep() |
|
38 { |
|
39 SetTestStepName(KKeyPairGeneratorPositiveObjectLoadStep); |
|
40 } |
|
41 |
|
42 TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepPreambleL() |
|
43 { |
|
44 SetTestStepResult(EPass); |
|
45 return TestStepResult(); |
|
46 } |
|
47 |
|
48 |
|
49 TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepL() |
|
50 { |
|
51 INFO_PRINTF1(_L("*** Key Pair Generator - Positive Object Load ***")); |
|
52 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
53 |
|
54 if (TestStepResult()==EPass) |
|
55 { |
|
56 //Assume faliure, unless all is successful |
|
57 SetTestStepResult(EFail); |
|
58 |
|
59 TVariantPtrC testVariant; |
|
60 TVariantPtrC keyVariant; |
|
61 |
|
62 if( !GetStringFromConfig(ConfigSection(),KConfigExchangeKey, keyVariant)) |
|
63 { |
|
64 // Leave if there's any error. |
|
65 User::Leave(KErrNotFound); |
|
66 } |
|
67 else |
|
68 { |
|
69 |
|
70 //Create an new CryptoParams object to encapsulate the key type and secret key string |
|
71 CCryptoParams* keyParams = CCryptoParams::NewL(); |
|
72 CleanupStack::PushL(keyParams); |
|
73 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid); |
|
74 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid); |
|
75 |
|
76 INFO_PRINTF1(_L("Creating Key Pair Generator...")); |
|
77 |
|
78 // create a key pair generator implementation interface |
|
79 CKeyPairGenerator* impl = NULL; |
|
80 |
|
81 TRAPD(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(impl, |
|
82 KRSAKeyPairGeneratorUid, |
|
83 keyParams)); |
|
84 |
|
85 if(impl && (err == KErrNone)) |
|
86 { |
|
87 CleanupStack::PushL(impl); |
|
88 |
|
89 INFO_PRINTF1(_L("Generating Key Pair...")); |
|
90 // Create a Key Pair with the values from the ini |
|
91 CKeyPair* keyPair = NULL; |
|
92 |
|
93 TRAP(err,impl->GenerateKeyPairL(1024, |
|
94 *keyParams, |
|
95 keyPair)); |
|
96 |
|
97 if(keyPair && (err == KErrNone)) |
|
98 { |
|
99 delete keyPair; |
|
100 INFO_PRINTF1(_L("*** PASS: Key Pair Successfully Generated ***")); |
|
101 SetTestStepResult(EPass); |
|
102 } |
|
103 else |
|
104 { |
|
105 ERR_PRINTF2(_L("*** FAIL: Key Pair Generation Failure - %d ***"), err); |
|
106 SetTestStepResult(EFail); |
|
107 } |
|
108 |
|
109 CleanupStack::PopAndDestroy(impl); |
|
110 } |
|
111 else |
|
112 { |
|
113 ERR_PRINTF2(_L("*** FAIL: Key Pair Generator Load Failure - %d ***"), err); |
|
114 SetTestStepResult(EFail); |
|
115 } |
|
116 |
|
117 CleanupStack::PopAndDestroy(keyParams); |
|
118 } |
|
119 |
|
120 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
121 |
|
122 } |
|
123 return TestStepResult(); |
|
124 } |
|
125 |
|
126 |
|
127 |
|
128 TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepPostambleL() |
|
129 { |
|
130 return TestStepResult(); |
|
131 } |