crypto/weakcryptospi/test/tcryptospi/src/hmacpositiveobjectloadstep.cpp
changeset 8 35751d3474b7
child 49 2f10d260163b
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 * Example CTestStep derived implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalTechnology
       
    23 */
       
    24 #include "hmacpositiveobjectloadstep.h"
       
    25 
       
    26 #include <cryptospi/cryptohashapi.h>
       
    27 #include "keys.h"
       
    28 
       
    29 using namespace CryptoSpi;
       
    30 
       
    31 CHmacPositiveObjectLoadStep::~CHmacPositiveObjectLoadStep()
       
    32 	{
       
    33 	}
       
    34 
       
    35 
       
    36 CHmacPositiveObjectLoadStep::CHmacPositiveObjectLoadStep()
       
    37 	{
       
    38 	SetTestStepName(KHmacPositiveObjectLoadStep);
       
    39 	}
       
    40 
       
    41 
       
    42 TVerdict CHmacPositiveObjectLoadStep::doTestStepPreambleL()
       
    43 	{
       
    44 	SetTestStepResult(EPass);
       
    45 	return TestStepResult();
       
    46 	}
       
    47 
       
    48 
       
    49 TVerdict CHmacPositiveObjectLoadStep::doTestStepL()
       
    50 	{
       
    51 	if (TestStepResult()==EPass)
       
    52 		{
       
    53 		
       
    54 		//Assume faliure, unless all is successful
       
    55 		SetTestStepResult(EFail);
       
    56 		
       
    57 		INFO_PRINTF1(_L("*** Hmac - Positive Object Load ***"));
       
    58 		INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
    59 		
       
    60 		TVariantPtrC algorithmUid;
       
    61 		TVariantPtrC operationModeUid;
       
    62 		TPtrC encryptKey;
       
    63 		TVariantPtrC keyType;
       
    64 		
       
    65 		//Extract the Test Case ID parameter from the specified INI file
       
    66 		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
    67 			!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationModeUid) ||
       
    68 			!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
       
    69 			!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
       
    70 			{
       
    71 			ERR_PRINTF1(_L("** Error: Failed to Load Configuration Parameters **"));
       
    72 			SetTestStepResult(EFail);
       
    73 			}
       
    74 		else
       
    75 			{
       
    76 			//Create and initialise a pointer for the Hash + Key (Hmac) Implementation Object
       
    77 			CHash* hmacImpl = NULL;
       
    78 
       
    79 			///Convert encryption key to an 8 Bit Descriptor
       
    80 			HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
       
    81 			TPtr8 keyStrPtr = keyStr->Des();
       
    82 			
       
    83 			keyStrPtr.Copy(encryptKey);
       
    84 									
       
    85 			//Create an new CryptoParams object to encapsulate the key type and secret key string
       
    86 			CCryptoParams* keyParams = CCryptoParams::NewL();
       
    87 			CleanupStack::PushL(keyParams);
       
    88 			keyParams->AddL(*keyStr,keyType);
       
    89 			
       
    90 			//Create the Key Object
       
    91 			TKeyProperty keyProperty;			
       
    92 			CKey* key=CKey::NewL(keyProperty,*keyParams);
       
    93 			CleanupStack::PushL(key);
       
    94 			
       
    95 			//Retrieve a Hmac Factory Object			
       
    96 			TRAPD(err,CHashFactory::CreateHashL(hmacImpl,
       
    97 												algorithmUid,
       
    98 												operationModeUid,
       
    99 												key,
       
   100 												NULL));						
       
   101 			
       
   102 			//If there are no errors (KErrNone) creating the Hmac factory object, Pass the Test	
       
   103 			if(hmacImpl && (err == KErrNone))
       
   104 				{
       
   105 				INFO_PRINTF1(_L("*** Hmac - Positive Object Load : PASS ***"));
       
   106 				delete hmacImpl;
       
   107 				SetTestStepResult(EPass);	
       
   108 				}
       
   109 			else
       
   110 				{
       
   111 				ERR_PRINTF2(_L("*** FAIL: Failed to Create Hmac Object - %d ***"), err);
       
   112 				SetTestStepResult(EFail);	
       
   113 				}
       
   114 			
       
   115 			CleanupStack::PopAndDestroy(key);
       
   116 			CleanupStack::PopAndDestroy(keyParams);	
       
   117 			CleanupStack::PopAndDestroy(keyStr);
       
   118 			}
       
   119 		
       
   120 		INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
   121 		
       
   122 		}
       
   123 	return TestStepResult();
       
   124 	}
       
   125 
       
   126 
       
   127 TVerdict CHmacPositiveObjectLoadStep::doTestStepPostambleL()
       
   128 	{
       
   129 	return TestStepResult();
       
   130 	}