|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalTechnology |
|
22 */ |
|
23 |
|
24 #include "symmetriccipherprocessbeforeivsetstep.h" |
|
25 |
|
26 using namespace CryptoSpi; |
|
27 |
|
28 CSymmetricCipherProcessBeforeIvSetStep::CSymmetricCipherProcessBeforeIvSetStep() |
|
29 { |
|
30 SetTestStepName(KSymmetricCipherProcessBeforeIvSetStep); |
|
31 } |
|
32 |
|
33 |
|
34 TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPreambleL() |
|
35 { |
|
36 SetTestStepResult(EPass); |
|
37 return TestStepResult(); |
|
38 } |
|
39 |
|
40 |
|
41 TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepL() |
|
42 { |
|
43 INFO_PRINTF1(_L("*** Symmetric Cipher - Calling the Process methods without first setting the IV ***")); |
|
44 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
45 |
|
46 if (TestStepResult()!=EPass) |
|
47 { |
|
48 return TestStepResult(); |
|
49 } |
|
50 |
|
51 //Assume failure, unless all is successful |
|
52 SetTestStepResult(EFail); |
|
53 |
|
54 TVariantPtrC operationMode; |
|
55 |
|
56 CSymmetricCipher* impl = NULL; |
|
57 CKey* key = NULL; |
|
58 SetupCipherL(EFalse, EFalse, operationMode, impl, key); |
|
59 |
|
60 INFO_PRINTF1(_L("Plugin loaded.")); |
|
61 |
|
62 CleanupStack::PushL(key); |
|
63 CleanupStack::PushL(impl); |
|
64 |
|
65 HBufC8* plaintext = ReadInPlaintextL(); |
|
66 CleanupStack::PushL(plaintext); |
|
67 |
|
68 //Create buffer for encrypted data |
|
69 TInt maxOutputLength = impl->MaxFinalOutputLength(plaintext->Length()); |
|
70 HBufC8* encrypted = HBufC8::NewLC(maxOutputLength); |
|
71 TPtr8 encryptedPtr = encrypted->Des(); |
|
72 |
|
73 INFO_PRINTF1(_L("Calling ProcessL()...")); |
|
74 |
|
75 //Perform the encryption operation |
|
76 TRAPD(err, impl->ProcessL((*plaintext), encryptedPtr)); |
|
77 |
|
78 if (err == KErrNotSupported) |
|
79 { |
|
80 INFO_PRINTF1(_L("ProcessL() errored with KErrNotSupported as expected")); |
|
81 SetTestStepResult(EPass); |
|
82 } |
|
83 else if (err == KErrNone) |
|
84 { |
|
85 ERR_PRINTF1(_L("*** FAIL: ProcessL() did not error ***")); |
|
86 SetTestStepResult(EFail); |
|
87 } |
|
88 else |
|
89 { |
|
90 ERR_PRINTF2(_L("*** FAIL: ProcessL() errored with unexpected error code - %d ***"), err); |
|
91 SetTestStepResult(EFail); |
|
92 } |
|
93 |
|
94 if (encryptedPtr.Length() != 0) |
|
95 { |
|
96 ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessL() ***")); |
|
97 SetTestStepResult(EFail); |
|
98 } |
|
99 |
|
100 if (TestStepResult() == EFail) |
|
101 { |
|
102 CleanupStack::PopAndDestroy(4, key); |
|
103 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
104 return TestStepResult(); |
|
105 } |
|
106 |
|
107 INFO_PRINTF1(_L("Calling ProcessFinalL()...")); |
|
108 |
|
109 //Perform the encryption operation |
|
110 TRAP(err, impl->ProcessFinalL((*plaintext), encryptedPtr)); |
|
111 |
|
112 if (err == KErrNotSupported) |
|
113 { |
|
114 INFO_PRINTF1(_L("ProcessFinalL() errored with KErrNotSupported as expected")); |
|
115 } |
|
116 else if (err == KErrNone) |
|
117 { |
|
118 ERR_PRINTF1(_L("*** FAIL: ProcessFinalL() did not error ***")); |
|
119 SetTestStepResult(EFail); |
|
120 } |
|
121 else |
|
122 { |
|
123 ERR_PRINTF2(_L("*** FAIL: ProcessFinalL() errored with unexpected error code - %d ***"), err); |
|
124 SetTestStepResult(EFail); |
|
125 } |
|
126 |
|
127 if (encryptedPtr.Length() != 0) |
|
128 { |
|
129 ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessFinalL() ***")); |
|
130 SetTestStepResult(EFail); |
|
131 } |
|
132 |
|
133 CleanupStack::PopAndDestroy(encrypted); |
|
134 CleanupStack::PopAndDestroy(plaintext); |
|
135 CleanupStack::PopAndDestroy(impl); |
|
136 CleanupStack::PopAndDestroy(key); |
|
137 |
|
138 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
139 return TestStepResult(); |
|
140 } |
|
141 |
|
142 |
|
143 TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPostambleL() |
|
144 { |
|
145 return TestStepResult(); |
|
146 } |