os/security/crypto/weakcryptospi/test/tcryptospi/src/symmetriccipherprocessbeforeivsetstep.cpp
Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #include "symmetriccipherprocessbeforeivsetstep.h"
26 using namespace CryptoSpi;
28 CSymmetricCipherProcessBeforeIvSetStep::CSymmetricCipherProcessBeforeIvSetStep()
30 SetTestStepName(KSymmetricCipherProcessBeforeIvSetStep);
34 TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPreambleL()
36 SetTestStepResult(EPass);
37 return TestStepResult();
41 TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepL()
43 INFO_PRINTF1(_L("*** Symmetric Cipher - Calling the Process methods without first setting the IV ***"));
44 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
46 if (TestStepResult()!=EPass)
48 return TestStepResult();
51 //Assume failure, unless all is successful
52 SetTestStepResult(EFail);
54 TVariantPtrC operationMode;
56 CSymmetricCipher* impl = NULL;
58 SetupCipherL(EFalse, EFalse, operationMode, impl, key);
60 INFO_PRINTF1(_L("Plugin loaded."));
62 CleanupStack::PushL(key);
63 CleanupStack::PushL(impl);
65 HBufC8* plaintext = ReadInPlaintextL();
66 CleanupStack::PushL(plaintext);
68 //Create buffer for encrypted data
69 TInt maxOutputLength = impl->MaxFinalOutputLength(plaintext->Length());
70 HBufC8* encrypted = HBufC8::NewLC(maxOutputLength);
71 TPtr8 encryptedPtr = encrypted->Des();
73 INFO_PRINTF1(_L("Calling ProcessL()..."));
75 //Perform the encryption operation
76 TRAPD(err, impl->ProcessL((*plaintext), encryptedPtr));
78 if (err == KErrNotSupported)
80 INFO_PRINTF1(_L("ProcessL() errored with KErrNotSupported as expected"));
81 SetTestStepResult(EPass);
83 else if (err == KErrNone)
85 ERR_PRINTF1(_L("*** FAIL: ProcessL() did not error ***"));
86 SetTestStepResult(EFail);
90 ERR_PRINTF2(_L("*** FAIL: ProcessL() errored with unexpected error code - %d ***"), err);
91 SetTestStepResult(EFail);
94 if (encryptedPtr.Length() != 0)
96 ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessL() ***"));
97 SetTestStepResult(EFail);
100 if (TestStepResult() == EFail)
102 CleanupStack::PopAndDestroy(4, key);
103 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
104 return TestStepResult();
107 INFO_PRINTF1(_L("Calling ProcessFinalL()..."));
109 //Perform the encryption operation
110 TRAP(err, impl->ProcessFinalL((*plaintext), encryptedPtr));
112 if (err == KErrNotSupported)
114 INFO_PRINTF1(_L("ProcessFinalL() errored with KErrNotSupported as expected"));
116 else if (err == KErrNone)
118 ERR_PRINTF1(_L("*** FAIL: ProcessFinalL() did not error ***"));
119 SetTestStepResult(EFail);
123 ERR_PRINTF2(_L("*** FAIL: ProcessFinalL() errored with unexpected error code - %d ***"), err);
124 SetTestStepResult(EFail);
127 if (encryptedPtr.Length() != 0)
129 ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessFinalL() ***"));
130 SetTestStepResult(EFail);
133 CleanupStack::PopAndDestroy(encrypted);
134 CleanupStack::PopAndDestroy(plaintext);
135 CleanupStack::PopAndDestroy(impl);
136 CleanupStack::PopAndDestroy(key);
138 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
139 return TestStepResult();
143 TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPostambleL()
145 return TestStepResult();