diff -r 675a964f4eb5 -r 35751d3474b7 crypto/weakcryptospi/test/tcryptospi/src/hmacpositiveobjectloadstep.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/test/tcryptospi/src/hmacpositiveobjectloadstep.cpp Thu Sep 10 14:01:51 2009 +0300 @@ -0,0 +1,130 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Example CTestStep derived implementation +* +*/ + + +/** + @file + @internalTechnology +*/ +#include "hmacpositiveobjectloadstep.h" + +#include +#include "keys.h" + +using namespace CryptoSpi; + +CHmacPositiveObjectLoadStep::~CHmacPositiveObjectLoadStep() + { + } + + +CHmacPositiveObjectLoadStep::CHmacPositiveObjectLoadStep() + { + SetTestStepName(KHmacPositiveObjectLoadStep); + } + + +TVerdict CHmacPositiveObjectLoadStep::doTestStepPreambleL() + { + SetTestStepResult(EPass); + return TestStepResult(); + } + + +TVerdict CHmacPositiveObjectLoadStep::doTestStepL() + { + if (TestStepResult()==EPass) + { + + //Assume faliure, unless all is successful + SetTestStepResult(EFail); + + INFO_PRINTF1(_L("*** Hmac - Positive Object Load ***")); + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); + + TVariantPtrC algorithmUid; + TVariantPtrC operationModeUid; + TPtrC encryptKey; + TVariantPtrC keyType; + + //Extract the Test Case ID parameter from the specified INI file + if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) || + !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationModeUid) || + !GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) || + !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType)) + { + ERR_PRINTF1(_L("** Error: Failed to Load Configuration Parameters **")); + SetTestStepResult(EFail); + } + else + { + //Create and initialise a pointer for the Hash + Key (Hmac) Implementation Object + CHash* hmacImpl = NULL; + + ///Convert encryption key to an 8 Bit Descriptor + HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length()); + TPtr8 keyStrPtr = keyStr->Des(); + + keyStrPtr.Copy(encryptKey); + + //Create an new CryptoParams object to encapsulate the key type and secret key string + CCryptoParams* keyParams = CCryptoParams::NewL(); + CleanupStack::PushL(keyParams); + keyParams->AddL(*keyStr,keyType); + + //Create the Key Object + TKeyProperty keyProperty; + CKey* key=CKey::NewL(keyProperty,*keyParams); + CleanupStack::PushL(key); + + //Retrieve a Hmac Factory Object + TRAPD(err,CHashFactory::CreateHashL(hmacImpl, + algorithmUid, + operationModeUid, + key, + NULL)); + + //If there are no errors (KErrNone) creating the Hmac factory object, Pass the Test + if(hmacImpl && (err == KErrNone)) + { + INFO_PRINTF1(_L("*** Hmac - Positive Object Load : PASS ***")); + delete hmacImpl; + SetTestStepResult(EPass); + } + else + { + ERR_PRINTF2(_L("*** FAIL: Failed to Create Hmac Object - %d ***"), err); + SetTestStepResult(EFail); + } + + CleanupStack::PopAndDestroy(key); + CleanupStack::PopAndDestroy(keyParams); + CleanupStack::PopAndDestroy(keyStr); + } + + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); + + } + return TestStepResult(); + } + + +TVerdict CHmacPositiveObjectLoadStep::doTestStepPostambleL() + { + return TestStepResult(); + }