sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #include "symmetriccipherprocessbeforeivsetstep.h" sl@0: sl@0: using namespace CryptoSpi; sl@0: sl@0: CSymmetricCipherProcessBeforeIvSetStep::CSymmetricCipherProcessBeforeIvSetStep() sl@0: { sl@0: SetTestStepName(KSymmetricCipherProcessBeforeIvSetStep); sl@0: } sl@0: sl@0: sl@0: TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPreambleL() sl@0: { sl@0: SetTestStepResult(EPass); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("*** Symmetric Cipher - Calling the Process methods without first setting the IV ***")); sl@0: INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); sl@0: sl@0: if (TestStepResult()!=EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: //Assume failure, unless all is successful sl@0: SetTestStepResult(EFail); sl@0: sl@0: TVariantPtrC operationMode; sl@0: sl@0: CSymmetricCipher* impl = NULL; sl@0: CKey* key = NULL; sl@0: SetupCipherL(EFalse, EFalse, operationMode, impl, key); sl@0: sl@0: INFO_PRINTF1(_L("Plugin loaded.")); sl@0: sl@0: CleanupStack::PushL(key); sl@0: CleanupStack::PushL(impl); sl@0: sl@0: HBufC8* plaintext = ReadInPlaintextL(); sl@0: CleanupStack::PushL(plaintext); sl@0: sl@0: //Create buffer for encrypted data sl@0: TInt maxOutputLength = impl->MaxFinalOutputLength(plaintext->Length()); sl@0: HBufC8* encrypted = HBufC8::NewLC(maxOutputLength); sl@0: TPtr8 encryptedPtr = encrypted->Des(); sl@0: sl@0: INFO_PRINTF1(_L("Calling ProcessL()...")); sl@0: sl@0: //Perform the encryption operation sl@0: TRAPD(err, impl->ProcessL((*plaintext), encryptedPtr)); sl@0: sl@0: if (err == KErrNotSupported) sl@0: { sl@0: INFO_PRINTF1(_L("ProcessL() errored with KErrNotSupported as expected")); sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else if (err == KErrNone) sl@0: { sl@0: ERR_PRINTF1(_L("*** FAIL: ProcessL() did not error ***")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("*** FAIL: ProcessL() errored with unexpected error code - %d ***"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (encryptedPtr.Length() != 0) sl@0: { sl@0: ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessL() ***")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (TestStepResult() == EFail) sl@0: { sl@0: CleanupStack::PopAndDestroy(4, key); sl@0: INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Calling ProcessFinalL()...")); sl@0: sl@0: //Perform the encryption operation sl@0: TRAP(err, impl->ProcessFinalL((*plaintext), encryptedPtr)); sl@0: sl@0: if (err == KErrNotSupported) sl@0: { sl@0: INFO_PRINTF1(_L("ProcessFinalL() errored with KErrNotSupported as expected")); sl@0: } sl@0: else if (err == KErrNone) sl@0: { sl@0: ERR_PRINTF1(_L("*** FAIL: ProcessFinalL() did not error ***")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("*** FAIL: ProcessFinalL() errored with unexpected error code - %d ***"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if (encryptedPtr.Length() != 0) sl@0: { sl@0: ERR_PRINTF1(_L("*** FAIL: encryptedPtr had been modified by ProcessFinalL() ***")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(encrypted); sl@0: CleanupStack::PopAndDestroy(plaintext); sl@0: CleanupStack::PopAndDestroy(impl); sl@0: CleanupStack::PopAndDestroy(key); sl@0: sl@0: INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CSymmetricCipherProcessBeforeIvSetStep::doTestStepPostambleL() sl@0: { sl@0: return TestStepResult(); sl@0: }