crypto/weakcryptospi/test/tcryptospi/src/symmetriccipherbadivlengthstep.cpp
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     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 "symmetriccipherbadivlengthstep.h"
       
    25 
       
    26 using namespace CryptoSpi;
       
    27 
       
    28 CSymmetricCipherBadIvLengthStep::CSymmetricCipherBadIvLengthStep()
       
    29 	{
       
    30 	SetTestStepName(KSymmetricCipherBadIvLengthStep);
       
    31 	}
       
    32 
       
    33 
       
    34 TVerdict CSymmetricCipherBadIvLengthStep::doTestStepPreambleL()
       
    35 	{
       
    36 	SetTestStepResult(EPass);
       
    37 	return TestStepResult();
       
    38 	}
       
    39 
       
    40 
       
    41 TVerdict CSymmetricCipherBadIvLengthStep::doTestStepL()
       
    42 	{
       
    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());
       
    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 	CSymmetricCipher* impl = NULL;
       
    56 	CKey* key = NULL;
       
    57 	SetupCipherL(EFalse, EFalse, operationMode, impl, key);
       
    58 	
       
    59 	INFO_PRINTF1(_L("Plugin loaded."));
       
    60 	
       
    61 	CleanupStack::PushL(key);
       
    62 	CleanupStack::PushL(impl);
       
    63 			
       
    64 	if((TUid(operationMode) == KOperationModeCBCUid) || (TUid(operationMode) == KOperationModeCTRUid))
       
    65 		{
       
    66 		TInt blockSize(0);
       
    67 				
       
    68 		if (TUid(operationMode) == KOperationModeCTRUid)
       
    69 			{
       
    70 			blockSize = CtrModeCalcBlockSizeL(*impl) * 2;
       
    71 			}
       
    72 		else
       
    73 			{
       
    74 			blockSize = impl->BlockSize() * 2;
       
    75 			}
       
    76 		
       
    77 		// blocksize is in bits so to allocate the correct number of bytes devide by 8
       
    78 		HBufC8* iv = HBufC8::NewLC(blockSize/8);
       
    79 		
       
    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++)
       
    82 			{
       
    83 			iv->Des().Append(_L8("12345678"));
       
    84 			}
       
    85 									
       
    86 		TRAPD(err,impl->SetIvL(iv->Des()));
       
    87 				
       
    88 		if(err == KErrArgument)
       
    89 			{
       
    90 			INFO_PRINTF1(_L("PASS : SetIvL() errored with KErrArgument as expected"));
       
    91 			SetTestStepResult(EPass);
       
    92 			}
       
    93 		else if (err == KErrNone)
       
    94 			{
       
    95 			ERR_PRINTF1(_L("*** FAIL: SetIvL() did not error ***"));
       
    96 			SetTestStepResult(EFail);						
       
    97 			}
       
    98 		else
       
    99 			{
       
   100 			ERR_PRINTF2(_L("*** FAIL: SetIvL() errored with unexpected error code - %d ***"), err);
       
   101 			SetTestStepResult(EFail);				
       
   102 			}
       
   103 		CleanupStack::PopAndDestroy(iv);					
       
   104 		}
       
   105 	else
       
   106 		{
       
   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);					
       
   109 		}
       
   110 
       
   111 	CleanupStack::PopAndDestroy(impl);
       
   112 	CleanupStack::PopAndDestroy(key);
       
   113 			
       
   114 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
   115 
       
   116 	return TestStepResult();
       
   117 	}
       
   118 
       
   119 
       
   120 TVerdict CSymmetricCipherBadIvLengthStep::doTestStepPostambleL()
       
   121 	{
       
   122 	return TestStepResult();
       
   123 	}