os/security/crypto/weakcryptospi/test/tcryptospi/src/hmacpositiveobjectloadstep.cpp
Update contrib.
2 * Copyright (c) 2007-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.
15 * Example CTestStep derived implementation
24 #include "hmacpositiveobjectloadstep.h"
26 #include <cryptospi/cryptohashapi.h>
27 #include <cryptospi/keys.h>
29 using namespace CryptoSpi;
31 CHmacPositiveObjectLoadStep::~CHmacPositiveObjectLoadStep()
36 CHmacPositiveObjectLoadStep::CHmacPositiveObjectLoadStep()
38 SetTestStepName(KHmacPositiveObjectLoadStep);
42 TVerdict CHmacPositiveObjectLoadStep::doTestStepPreambleL()
44 SetTestStepResult(EPass);
45 return TestStepResult();
49 TVerdict CHmacPositiveObjectLoadStep::doTestStepL()
51 if (TestStepResult()==EPass)
54 //Assume faliure, unless all is successful
55 SetTestStepResult(EFail);
57 INFO_PRINTF1(_L("*** Hmac - Positive Object Load ***"));
58 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
60 TVariantPtrC algorithmUid;
61 TVariantPtrC operationModeUid;
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))
71 ERR_PRINTF1(_L("** Error: Failed to Load Configuration Parameters **"));
72 SetTestStepResult(EFail);
76 //Create and initialise a pointer for the Hash + Key (Hmac) Implementation Object
77 CHash* hmacImpl = NULL;
79 ///Convert encryption key to an 8 Bit Descriptor
80 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
81 TPtr8 keyStrPtr = keyStr->Des();
83 keyStrPtr.Copy(encryptKey);
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);
90 //Create the Key Object
91 TKeyProperty keyProperty;
92 CKey* key=CKey::NewL(keyProperty,*keyParams);
93 CleanupStack::PushL(key);
95 //Retrieve a Hmac Factory Object
96 TRAPD(err,CHashFactory::CreateHashL(hmacImpl,
102 //If there are no errors (KErrNone) creating the Hmac factory object, Pass the Test
103 if(hmacImpl && (err == KErrNone))
105 INFO_PRINTF1(_L("*** Hmac - Positive Object Load : PASS ***"));
107 SetTestStepResult(EPass);
111 ERR_PRINTF2(_L("*** FAIL: Failed to Create Hmac Object - %d ***"), err);
112 SetTestStepResult(EFail);
115 CleanupStack::PopAndDestroy(key);
116 CleanupStack::PopAndDestroy(keyParams);
117 CleanupStack::PopAndDestroy(keyStr);
120 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
123 return TestStepResult();
127 TVerdict CHmacPositiveObjectLoadStep::doTestStepPostambleL()
129 return TestStepResult();