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 "pluginloadstep.h"
25 #include "plugincharschecker.h"
27 #include <cryptospi/cryptosymmetriccipherapi.h>
28 #include <cryptospi/keys.h>
30 #include <cryptospi/cryptospistateapi.h>
31 #include <cryptospi/cryptohashapi.h>
32 #include <cryptospi/cryptorandomapi.h>
33 #include <cryptospi/cryptosymmetriccipherapi.h>
34 #include <cryptospi/cryptoasymmetriccipherapi.h>
35 #include <cryptospi/cryptosignatureapi.h>
36 #include <cryptospi/cryptokeypairgeneratorapi.h>
37 #include <cryptospi/cryptokeyagreementapi.h>
38 #include <cryptospi/ruleselector.h>
40 using namespace CryptoSpi;
43 CPluginLoadStep::~CPluginLoadStep()
48 CPluginLoadStep::CPluginLoadStep()
50 SetTestStepName(KPluginLoadStep);
54 TVerdict CPluginLoadStep::doTestStepPreambleL()
56 SetTestStepResult(EPass);
57 return TestStepResult();
61 TVerdict CPluginLoadStep::doTestStepL()
64 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
66 if (TestStepResult()==EPass)
68 //Assume faliure, unless all is successful
69 SetTestStepResult(EFail);
73 TVariantPtrC algorithm;
74 TVariantPtrC operationMode;
75 TVariantPtrC paddingMode;
76 TBool ruleSelectorToggle = EFalse;
79 if( !GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
80 !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
81 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid, algorithm) ||
82 !GetStringFromConfig(ConfigSection(),KConfigOperationMode, operationMode) ||
83 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode, paddingMode ) ||
84 !GetBoolFromConfig(ConfigSection(),KConfigRuleSelectorToggle, ruleSelectorToggle ))
86 ERR_PRINTF1(_L("** Error: Failed to Load DoStep() Configuration Parameters **"));
87 User::Leave(KErrNotFound);
91 //Convert encryption key to an 8 Bit Descriptor
92 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
93 TPtr8 keyStrPtr = keyStr->Des();
95 keyStrPtr.Copy(encryptKey);
97 //Create an new CryptoParams object to encapsulate the key type and secret key string
98 CCryptoParams* keyParams = CCryptoParams::NewL();
99 CleanupStack::PushL(keyParams);
100 keyParams->AddL(*keyStr,keyType);
103 TKeyProperty keyProperty;
104 CKey* key=CKey::NewL(keyProperty,*keyParams);
105 CleanupStack::PushL(key);
107 //***** Determine whether to set the Rule Selector *****
109 CRuleSelector* ruleSelector = NULL;
111 if(ruleSelectorToggle)
113 //Create Rule Selection Rules Object
114 CSelectionRules* rules = CSelectionRules::NewL();
115 CleanupStack::PushL(rules);
117 //Create Rule Selector Object
118 ruleSelector = CRuleSelector::NewL(rules);
119 CleanupStack::Pop(rules);
120 CleanupStack::PushL(ruleSelector);
122 //Set the Selector Passing in a pointer to the Default Selector and SPI State
123 CCryptoSpiStateApi::SetSelector(ruleSelector);
126 //******************************************************
128 // Create a Symmetric Cipher with the values from the ini file
129 CryptoSpi::CSymmetricCipher * impl = NULL;
131 TRAPD(err,CSymmetricCipherFactory::CreateSymmetricCipherL(impl,
134 KCryptoModeEncryptUid,
139 if(impl && (err==KErrNone))
141 INFO_PRINTF1(_L("Successful Implementation Object Load..."));
143 CleanupStack::PushL(impl);
145 //Define a pointer of type TCharacteristics in order to store the appropriate
146 //encryption object's characterisctics
147 const TCharacteristics* characteristics(NULL);
149 //Retrieve the characteristics for the symmetric cipher implementation object
150 TRAP_LOG(err, impl->GetCharacteristicsL(characteristics));
152 TVariantPtrC exAlgorithmUid;
153 TVariantPtrC exImplementationUid;
155 if(!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
156 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid))
158 ERR_PRINTF1(_L("** .INI Error: Expected Algorithm Arguments Not Located **"));
159 SetTestStepResult(EFail);
163 INFO_PRINTF1(_L("Checking Plug-in Selection..."));
165 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
169 //Perform plug-in Check
170 if(pluginCheck->checkSelectedPlugin(characteristics,
175 INFO_PRINTF1(_L("** PASS: Expected Plugin Loaded Successfully **"));
176 SetTestStepResult(EPass);
180 ERR_PRINTF2(_L("** FAIL: Unexpected Plugin Implementation Loaded - %S **"),&errorMessage);
183 CleanupStack::PopAndDestroy(pluginCheck);
187 CleanupStack::PopAndDestroy(impl);
193 ERR_PRINTF2(_L("*** FAIL: Implementation Object Load Failure ***"), err);
194 SetTestStepResult(EFail);
197 if(ruleSelectorToggle)
199 //Set the Selector Passing in a pointer to the Default Selector and SPI State
200 CCryptoSpiStateApi::UnsetSelector();
202 CleanupStack::PopAndDestroy();
205 CleanupStack::PopAndDestroy(3,keyStr);
211 ERR_PRINTF1(_L("*** FAIL: Test Case Initialistion Failure ***"));
214 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
216 return TestStepResult();
220 TVerdict CPluginLoadStep::doTestStepPostambleL()
222 return TestStepResult();