os/security/crypto/weakcryptospi/test/tcryptospi/src/symmetriccipherprocessbeforeivsetstep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/symmetriccipherprocessbeforeivsetstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,146 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalTechnology
1.25 +*/
1.26 +
1.27 +#include "symmetriccipherprocessbeforeivsetstep.h"
1.28 +
1.29 +using namespace CryptoSpi;
1.30 +
1.31 +CSymmetricCipherProcessBeforeIvSetStep::CSymmetricCipherProcessBeforeIvSetStep()
1.32 + {
1.33 + SetTestStepName(KSymmetricCipherProcessBeforeIvSetStep);
1.34 + }
1.35 +
1.36 +
1.37 +TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPreambleL()
1.38 + {
1.39 + SetTestStepResult(EPass);
1.40 + return TestStepResult();
1.41 + }
1.42 +
1.43 +
1.44 +TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepL()
1.45 + {
1.46 + INFO_PRINTF1(_L("*** Symmetric Cipher - Calling the Process methods without first setting the IV ***"));
1.47 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.48 +
1.49 + if (TestStepResult()!=EPass)
1.50 + {
1.51 + return TestStepResult();
1.52 + }
1.53 +
1.54 + //Assume failure, unless all is successful
1.55 + SetTestStepResult(EFail);
1.56 +
1.57 + TVariantPtrC operationMode;
1.58 +
1.59 + CSymmetricCipher* impl = NULL;
1.60 + CKey* key = NULL;
1.61 + SetupCipherL(EFalse, EFalse, operationMode, impl, key);
1.62 +
1.63 + INFO_PRINTF1(_L("Plugin loaded."));
1.64 +
1.65 + CleanupStack::PushL(key);
1.66 + CleanupStack::PushL(impl);
1.67 +
1.68 + HBufC8* plaintext = ReadInPlaintextL();
1.69 + CleanupStack::PushL(plaintext);
1.70 +
1.71 + //Create buffer for encrypted data
1.72 + TInt maxOutputLength = impl->MaxFinalOutputLength(plaintext->Length());
1.73 + HBufC8* encrypted = HBufC8::NewLC(maxOutputLength);
1.74 + TPtr8 encryptedPtr = encrypted->Des();
1.75 +
1.76 + INFO_PRINTF1(_L("Calling ProcessL()..."));
1.77 +
1.78 + //Perform the encryption operation
1.79 + TRAPD(err, impl->ProcessL((*plaintext), encryptedPtr));
1.80 +
1.81 + if (err == KErrNotSupported)
1.82 + {
1.83 + INFO_PRINTF1(_L("ProcessL() errored with KErrNotSupported as expected"));
1.84 + SetTestStepResult(EPass);
1.85 + }
1.86 + else if (err == KErrNone)
1.87 + {
1.88 + ERR_PRINTF1(_L("*** FAIL: ProcessL() did not error ***"));
1.89 + SetTestStepResult(EFail);
1.90 + }
1.91 + else
1.92 + {
1.93 + ERR_PRINTF2(_L("*** FAIL: ProcessL() errored with unexpected error code - %d ***"), err);
1.94 + SetTestStepResult(EFail);
1.95 + }
1.96 +
1.97 + if (encryptedPtr.Length() != 0)
1.98 + {
1.99 + ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessL() ***"));
1.100 + SetTestStepResult(EFail);
1.101 + }
1.102 +
1.103 + if (TestStepResult() == EFail)
1.104 + {
1.105 + CleanupStack::PopAndDestroy(4, key);
1.106 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.107 + return TestStepResult();
1.108 + }
1.109 +
1.110 + INFO_PRINTF1(_L("Calling ProcessFinalL()..."));
1.111 +
1.112 + //Perform the encryption operation
1.113 + TRAP(err, impl->ProcessFinalL((*plaintext), encryptedPtr));
1.114 +
1.115 + if (err == KErrNotSupported)
1.116 + {
1.117 + INFO_PRINTF1(_L("ProcessFinalL() errored with KErrNotSupported as expected"));
1.118 + }
1.119 + else if (err == KErrNone)
1.120 + {
1.121 + ERR_PRINTF1(_L("*** FAIL: ProcessFinalL() did not error ***"));
1.122 + SetTestStepResult(EFail);
1.123 + }
1.124 + else
1.125 + {
1.126 + ERR_PRINTF2(_L("*** FAIL: ProcessFinalL() errored with unexpected error code - %d ***"), err);
1.127 + SetTestStepResult(EFail);
1.128 + }
1.129 +
1.130 + if (encryptedPtr.Length() != 0)
1.131 + {
1.132 + ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessFinalL() ***"));
1.133 + SetTestStepResult(EFail);
1.134 + }
1.135 +
1.136 + CleanupStack::PopAndDestroy(encrypted);
1.137 + CleanupStack::PopAndDestroy(plaintext);
1.138 + CleanupStack::PopAndDestroy(impl);
1.139 + CleanupStack::PopAndDestroy(key);
1.140 +
1.141 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.142 + return TestStepResult();
1.143 + }
1.144 +
1.145 +
1.146 +TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPostambleL()
1.147 + {
1.148 + return TestStepResult();
1.149 + }