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.
24 #include "plugincharscommonstep.h"
25 #include "plugincharschecker.h"
27 #include <cryptospi/cryptosymmetriccipherapi.h>
28 #include <cryptospi/keys.h>
30 using namespace CryptoSpi;
32 CPluginCharsCommonStep::~CPluginCharsCommonStep()
36 CPluginCharsCommonStep::CPluginCharsCommonStep()
38 SetTestStepName(KPluginCharsCommonStep);
41 TVerdict CPluginCharsCommonStep::doTestStepPreambleL()
43 SetTestStepResult(EPass);
44 return TestStepResult();
47 TVerdict CPluginCharsCommonStep::doTestStepL()
50 INFO_PRINTF1(_L("Plugin Characteristics - Common Chracteristics"));
51 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
53 if (TestStepResult()==EPass)
56 //Assume faliure, unless all is successful
57 SetTestStepResult(EFail);
61 TVariantPtrC algorithmUid;
62 TVariantPtrC cryptoMode;
63 TVariantPtrC operationMode;
64 TVariantPtrC paddingMode;
66 //Each of the individual parameters required to create the Symmetric Cipher object
67 //are read in from the specified INI configuration file
68 if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
69 !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
70 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
71 !GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
72 !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
73 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode))
75 ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
76 SetTestStepResult(EFail);
80 //Convert encryption key to an 8 Bit Descriptor
81 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
82 TPtr8 keyStrPtr = keyStr->Des();
84 keyStrPtr.Copy(encryptKey);
86 //Create an new CryptoParams object to encapsulate the key type and secret key string
87 CCryptoParams* keyParams = CCryptoParams::NewL();
88 CleanupStack::PushL(keyParams);
89 keyParams->AddL(*keyStr,keyType);
92 TKeyProperty keyProperty;
93 CKey* key=CKey::NewL(keyProperty,*keyParams);
94 CleanupStack::PushL(key);
96 CSymmetricCipher* symmetricCipherImpl = NULL;
98 TRAPD_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
108 if(symmetricCipherImpl && (err == KErrNone))
111 CleanupStack::PushL(symmetricCipherImpl);
113 INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
115 //Define a pointer of type TCharacteristics in order to store the symmetric cipher
116 //encryption object's characterisctics
117 const TCharacteristics* chars(NULL);
119 //Retrieve the characteristics for the symmetric cipher implementation object
120 TRAP_LOG(err, symmetricCipherImpl->GetCharacteristicsL(chars));
122 //Static cast the characteristics to type TCommonCharacteristics
123 const TCommonCharacteristics* commonChars = static_cast<const TCommonCharacteristics*>(chars);
125 //Retrieve all the Common characteristics that are required for all test cases
126 TVariantPtrC exInterfaceUid;
127 TVariantPtrC exAlgorithmUid;
128 TVariantPtrC exImplementationUid;
129 TVariantPtrC exCreatorName;
130 TBool exFIPSApproved;
131 TBool exHardwareSupported;
132 TInt exMaxConcurrencySupported;
133 TVariantPtrC exAlgorithmName;
137 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
138 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
139 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
140 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
141 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
142 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
143 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
144 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
145 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
146 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput))
148 ERR_PRINTF1(_L("** .INI Error: Expected Common Characteristic Arguments Not Located **"));
149 SetTestStepResult(EFail);
154 INFO_PRINTF1(_L("** Checking common Characteristics.... **"));
156 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
160 //******************************************************************
161 //Perform Characteristic Checks
162 //******************************************************************
163 if(pluginCheck->checkCommonCharacteristics(commonChars,
170 exMaxConcurrencySupported,
176 INFO_PRINTF1(_L("** PASS : Common characteristics successfully match expected values **"));
177 SetTestStepResult(EPass);
181 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
184 CleanupStack::PopAndDestroy(pluginCheck);
187 CleanupStack::PopAndDestroy(symmetricCipherImpl);
191 ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Cipher Object - %d ***"), err);
194 CleanupStack::PopAndDestroy(3,keyStr);
199 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
200 return TestStepResult();
203 TVerdict CPluginCharsCommonStep::doTestStepPostambleL()
205 return TestStepResult();