os/security/crypto/weakcryptospi/test/tcryptospi/src/symmetriccipherbadivlengthstep.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 "symmetriccipherbadivlengthstep.h"
26 using namespace CryptoSpi;
28 CSymmetricCipherBadIvLengthStep::CSymmetricCipherBadIvLengthStep()
30 SetTestStepName(KSymmetricCipherBadIvLengthStep);
34 TVerdict CSymmetricCipherBadIvLengthStep::doTestStepPreambleL()
36 SetTestStepResult(EPass);
37 return TestStepResult();
41 TVerdict CSymmetricCipherBadIvLengthStep::doTestStepL()
43 INFO_PRINTF1(_L("*** Symmetric Cipher - Trying to set the IV to a descriptor of the wrong length ***"));
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;
55 CSymmetricCipher* impl = NULL;
57 SetupCipherL(EFalse, EFalse, operationMode, impl, key);
59 INFO_PRINTF1(_L("Plugin loaded."));
61 CleanupStack::PushL(key);
62 CleanupStack::PushL(impl);
64 if((TUid(operationMode) == KOperationModeCBCUid) || (TUid(operationMode) == KOperationModeCTRUid))
68 if (TUid(operationMode) == KOperationModeCTRUid)
70 blockSize = CtrModeCalcBlockSizeL(*impl) * 2;
74 blockSize = impl->BlockSize() * 2;
77 // blocksize is in bits so to allocate the correct number of bytes devide by 8
78 HBufC8* iv = HBufC8::NewLC(blockSize/8);
80 // blocksize is in bits so to allocate the correct number of 8 byte chunks divide by 64
81 for(TInt i = 0 ; i <blockSize/64 ; i++)
83 iv->Des().Append(_L8("12345678"));
86 TRAPD(err,impl->SetIvL(iv->Des()));
88 if(err == KErrArgument)
90 INFO_PRINTF1(_L("PASS : SetIvL() errored with KErrArgument as expected"));
91 SetTestStepResult(EPass);
93 else if (err == KErrNone)
95 ERR_PRINTF1(_L("*** FAIL: SetIvL() did not error ***"));
96 SetTestStepResult(EFail);
100 ERR_PRINTF2(_L("*** FAIL: SetIvL() errored with unexpected error code - %d ***"), err);
101 SetTestStepResult(EFail);
103 CleanupStack::PopAndDestroy(iv);
107 ERR_PRINTF2(_L("*** FAIL: This test requires an operation mode that supports an initialisation vector and does not support operation id: %d ***"), (TUid(operationMode)).iUid);
108 SetTestStepResult(EFail);
111 CleanupStack::PopAndDestroy(impl);
112 CleanupStack::PopAndDestroy(key);
114 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
116 return TestStepResult();
120 TVerdict CSymmetricCipherBadIvLengthStep::doTestStepPostambleL()
122 return TestStepResult();