os/security/crypto/weakcryptospi/test/tcryptospi/src/hmacpositiveobjectloadstep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/hmacpositiveobjectloadstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,130 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Example CTestStep derived implementation
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalTechnology
1.26 +*/
1.27 +#include "hmacpositiveobjectloadstep.h"
1.28 +
1.29 +#include <cryptospi/cryptohashapi.h>
1.30 +#include <cryptospi/keys.h>
1.31 +
1.32 +using namespace CryptoSpi;
1.33 +
1.34 +CHmacPositiveObjectLoadStep::~CHmacPositiveObjectLoadStep()
1.35 + {
1.36 + }
1.37 +
1.38 +
1.39 +CHmacPositiveObjectLoadStep::CHmacPositiveObjectLoadStep()
1.40 + {
1.41 + SetTestStepName(KHmacPositiveObjectLoadStep);
1.42 + }
1.43 +
1.44 +
1.45 +TVerdict CHmacPositiveObjectLoadStep::doTestStepPreambleL()
1.46 + {
1.47 + SetTestStepResult(EPass);
1.48 + return TestStepResult();
1.49 + }
1.50 +
1.51 +
1.52 +TVerdict CHmacPositiveObjectLoadStep::doTestStepL()
1.53 + {
1.54 + if (TestStepResult()==EPass)
1.55 + {
1.56 +
1.57 + //Assume faliure, unless all is successful
1.58 + SetTestStepResult(EFail);
1.59 +
1.60 + INFO_PRINTF1(_L("*** Hmac - Positive Object Load ***"));
1.61 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.62 +
1.63 + TVariantPtrC algorithmUid;
1.64 + TVariantPtrC operationModeUid;
1.65 + TPtrC encryptKey;
1.66 + TVariantPtrC keyType;
1.67 +
1.68 + //Extract the Test Case ID parameter from the specified INI file
1.69 + if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
1.70 + !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationModeUid) ||
1.71 + !GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
1.72 + !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
1.73 + {
1.74 + ERR_PRINTF1(_L("** Error: Failed to Load Configuration Parameters **"));
1.75 + SetTestStepResult(EFail);
1.76 + }
1.77 + else
1.78 + {
1.79 + //Create and initialise a pointer for the Hash + Key (Hmac) Implementation Object
1.80 + CHash* hmacImpl = NULL;
1.81 +
1.82 + ///Convert encryption key to an 8 Bit Descriptor
1.83 + HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
1.84 + TPtr8 keyStrPtr = keyStr->Des();
1.85 +
1.86 + keyStrPtr.Copy(encryptKey);
1.87 +
1.88 + //Create an new CryptoParams object to encapsulate the key type and secret key string
1.89 + CCryptoParams* keyParams = CCryptoParams::NewL();
1.90 + CleanupStack::PushL(keyParams);
1.91 + keyParams->AddL(*keyStr,keyType);
1.92 +
1.93 + //Create the Key Object
1.94 + TKeyProperty keyProperty;
1.95 + CKey* key=CKey::NewL(keyProperty,*keyParams);
1.96 + CleanupStack::PushL(key);
1.97 +
1.98 + //Retrieve a Hmac Factory Object
1.99 + TRAPD(err,CHashFactory::CreateHashL(hmacImpl,
1.100 + algorithmUid,
1.101 + operationModeUid,
1.102 + key,
1.103 + NULL));
1.104 +
1.105 + //If there are no errors (KErrNone) creating the Hmac factory object, Pass the Test
1.106 + if(hmacImpl && (err == KErrNone))
1.107 + {
1.108 + INFO_PRINTF1(_L("*** Hmac - Positive Object Load : PASS ***"));
1.109 + delete hmacImpl;
1.110 + SetTestStepResult(EPass);
1.111 + }
1.112 + else
1.113 + {
1.114 + ERR_PRINTF2(_L("*** FAIL: Failed to Create Hmac Object - %d ***"), err);
1.115 + SetTestStepResult(EFail);
1.116 + }
1.117 +
1.118 + CleanupStack::PopAndDestroy(key);
1.119 + CleanupStack::PopAndDestroy(keyParams);
1.120 + CleanupStack::PopAndDestroy(keyStr);
1.121 + }
1.122 +
1.123 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.124 +
1.125 + }
1.126 + return TestStepResult();
1.127 + }
1.128 +
1.129 +
1.130 +TVerdict CHmacPositiveObjectLoadStep::doTestStepPostambleL()
1.131 + {
1.132 + return TestStepResult();
1.133 + }