Update contrib.
     2 * Copyright (c) 2008-2010 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 "plugincharsmacstep.h"
 
    25 #include "plugincharschecker.h"
 
    27 #include <cryptospi/cryptomacapi.h>
 
    28 #include <cryptospi/keys.h>
 
    30 using namespace CryptoSpi;
 
    32 CPluginCharsMacStep::~CPluginCharsMacStep()
 
    36 CPluginCharsMacStep::CPluginCharsMacStep()
 
    38 	SetTestStepName(KPluginCharsMacStep);
 
    41 TVerdict CPluginCharsMacStep::doTestStepPreambleL()
 
    43 	SetTestStepResult(EPass);
 
    44 	return TestStepResult();
 
    47 TVerdict CPluginCharsMacStep::doTestStepL()
 
    50 	INFO_PRINTF1(_L("Plugin Characteristics - Mac Chracteristics"));
 
    51 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
 
    53 	if (TestStepResult()==EPass)
 
    55 		//Assume failure, unless all is successful
 
    56 		SetTestStepResult(EFail);
 
    58 		TVariantPtrC algorithmUid;
 
    62 		//Each of the individual parameters required to create the Mac object
 
    63 		//are read in from the specified INI configuration file	
 
    64 		if (!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
 
    65 			!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
 
    66 			!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
 
    68 			ERR_PRINTF1(_L("** .INI Error: Mac Arguments Not Located **"));
 
    69 			SetTestStepResult(EFail);
 
    75 			//Convert encryption key to an 8 Bit Descriptor
 
    76 			HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
 
    77 			TPtr8 keyStrPtr = keyStr->Des();
 
    79 			keyStrPtr.Copy(encryptKey);
 
    81 			//Create an new CryptoParams object to encapsulate the key type and secret key string
 
    82 			CCryptoParams* keyParams = CCryptoParams::NewL();
 
    83 			CleanupStack::PushL(keyParams);
 
    84 			keyParams->AddL(*keyStr,keyType);
 
    87 			TKeyProperty keyProperty;
 
    88 			CKey* key=CKey::NewL(keyProperty,*keyParams);
 
    89 			CleanupStack::PushL(key);
 
    91 			TRAPD_LOG(err,CMacFactory::CreateMacL(macImpl,
 
    99 				ERR_PRINTF2(_L("*** FAIL: Failed to Create Mac Object - %d ***"), err);
 
   103 			CleanupStack::PushL(macImpl);
 
   105 			INFO_PRINTF1(_L("** Successfully Loaded Mac Object **"));
 
   107 			//Define a pointer of type TCharacteristics in order to store the hash
 
   108 			//cryptographic object's characterisctics	
 
   109 			const TCharacteristics* chars(NULL);
 
   111 			//Retrieve the characteristics for the hash implementation object
 
   112 			TRAP_LOG(err, macImpl->GetCharacteristicsL(chars));
 
   114 			//Static cast the characteristics to type TMacCharacteristics
 
   115 			const TMacCharacteristics* macChars = static_cast<const TMacCharacteristics*>(chars);
 
   117 			//Retrieve all the Common characteristics that are required for all test cases
 
   118 			TVariantPtrC exInterfaceUid;
 
   119 			TVariantPtrC exAlgorithmUid;
 
   120 			TVariantPtrC exImplementationUid;
 
   121 			TVariantPtrC exCreatorName;
 
   122 			TBool exFIPSApproved;
 
   123 			TBool exHardwareSupported;
 
   124 			TInt exMaxConcurrencySupported;
 
   125 			TVariantPtrC exAlgorithmName;
 
   129 			//Retrieve all the Mac characteristics that are required for all test cases
 
   130 			TVariantPtrC exMacMode;
 
   132 			if (!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
 
   133 				!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
 
   134 				!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
 
   135 				!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
 
   136 				!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
 
   137 				!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
 
   138 				!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
 
   139 				!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
 
   140 				!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
 
   141 				!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
 
   142 				!GetStringFromConfig(ConfigSection(),KConfigExMacMode,exMacMode))
 
   144 				ERR_PRINTF1(_L("** .INI Error: Expected Mac/Common Characteristic Arguments Not Located **"));
 
   145 				SetTestStepResult(EFail);
 
   149 				INFO_PRINTF1(_L("** Checking Mac/Common Characteristics.... **"));
 
   151 				CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
 
   153 				//Retrieve the Common Characteristics from TMacCharacteristics 
 
   154 				const TCommonCharacteristics* macCommonChars = &macChars->iMacChar;
 
   158 				//Perform Mac/Common Characteristic Checks
 
   159 				if(pluginCheck->checkCommonCharacteristics(macCommonChars,
 
   166 											exMaxConcurrencySupported,
 
   171 					pluginCheck->checkMacCharacteristics(macChars, exMacMode, errorMessage))
 
   173 					INFO_PRINTF1(_L("Mac/Common characteristics successfully match expected values..."));
 
   174 					SetTestStepResult(EPass);
 
   178 					ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);	
 
   181 				CleanupStack::PopAndDestroy(pluginCheck);
 
   184 			CleanupStack::PopAndDestroy(macImpl);
 
   185 			CleanupStack::PopAndDestroy(key);
 
   186 			CleanupStack::PopAndDestroy(keyParams);
 
   187 			CleanupStack::PopAndDestroy(keyStr);
 
   191 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
 
   192 	return TestStepResult();
 
   195 TVerdict CPluginCharsMacStep::doTestStepPostambleL()
 
   197 	return TestStepResult();