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 "plugincharsextendedstep.h"
25 #include "plugincharschecker.h"
27 #include <cryptospi/cryptosymmetriccipherapi.h>
28 #include <cryptospi/keys.h>
29 #include <cryptospi/plugincharacteristics.h>
31 using namespace CryptoSpi;
33 CPluginCharsExtendedStep::~CPluginCharsExtendedStep()
37 CPluginCharsExtendedStep::CPluginCharsExtendedStep()
39 SetTestStepName(KPluginCharsExtendedStep);
42 TVerdict CPluginCharsExtendedStep::doTestStepPreambleL()
44 SetTestStepResult(EPass);
45 return TestStepResult();
48 TVerdict CPluginCharsExtendedStep::doTestStepL()
51 INFO_PRINTF1(_L("Plugin Characteristics - Extended Chracteristics"));
52 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
54 if (TestStepResult()==EPass)
57 //Assume faliure, unless all is successful
58 SetTestStepResult(EFail);
62 TVariantPtrC algorithmUid;
63 TVariantPtrC cryptoMode;
64 TVariantPtrC operationMode;
65 TVariantPtrC paddingMode;
67 //Each of the individual parameters required to create the Symmetric Cipher object
68 //are read in from the specified INI configuration file
69 if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
70 !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
71 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
72 !GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
73 !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
74 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode))
76 ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
77 SetTestStepResult(EFail);
81 //Convert encryption key to an 8 Bit Descriptor
82 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
83 TPtr8 keyStrPtr = keyStr->Des();
85 keyStrPtr.Copy(encryptKey);
87 //Create an new CryptoParams object to encapsulate the key type and secret key string
88 CCryptoParams* keyParams = CCryptoParams::NewL();
89 CleanupStack::PushL(keyParams);
90 keyParams->AddL(*keyStr,keyType);
93 TKeyProperty keyProperty;
94 CKey* key=CKey::NewL(keyProperty,*keyParams);
95 CleanupStack::PushL(key);
97 CSymmetricCipher* symmetricCipherImpl = NULL;
99 TRAPD_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
109 if(symmetricCipherImpl && (err == KErrNone))
111 CleanupStack::PushL(symmetricCipherImpl);
113 INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
115 //Retrieve all the Symmetric Cipher characteristics that are required for all test cases
116 TInt exExtendedTestChar1;
117 TInt exExtendedTestChar2;
118 TPtrC exExtendedTestChar3;
119 TVariantPtrC exExtendedConcurrency;
120 TBool exExtendedExclusiveUse;
122 if(!GetIntFromConfig(ConfigSection(),KConfigExExtendTestChar1,exExtendedTestChar1) ||
123 !GetIntFromConfig(ConfigSection(),KConfigExExtendTestChar2,exExtendedTestChar2) ||
124 !GetStringFromConfig(ConfigSection(),KConfigExExtendTestChar3,exExtendedTestChar3) ||
125 !GetStringFromConfig(ConfigSection(),KConfigExExtendConcurrency,exExtendedConcurrency) ||
126 !GetBoolFromConfig(ConfigSection(),KConfigExExtendExclusiveUse,exExtendedExclusiveUse))
128 ERR_PRINTF1(_L("** .INI Error: Expected Symmetric Cipher Extended Characteristics Not Located **"));
129 SetTestStepResult(EFail);
133 INFO_PRINTF1(_L("** Checking Symmetric Cipher Extended Characteristics.... **"));
135 //******************EXTENDED CHARACTERISITICS****************************
137 //Retrieve Characteristics via CExtendedCharacteristics Object
138 const CExtendedCharacteristics* extendedChars = NULL;
140 TRAP_LOG(err,extendedChars = symmetricCipherImpl->GetExtendedCharacteristicsL());
142 //Retrieve Charcteristics via the ListExtendedCharacteristics() of the CExtendedCharacteristics Object
143 const CCryptoParams* extendedCryptoParams = NULL;
145 TRAP_LOG(err,extendedCryptoParams = extendedChars->ListExtendedCharacteristics());
147 //***********************************************************************
149 //Convert expected string atrributes an 8 Bit Descriptor
150 HBufC8* exTestChar3Str = HBufC8::NewLC(exExtendedTestChar3.Length());
151 TPtr8 tmpPtr = exTestChar3Str->Des();
153 tmpPtr.Copy(exExtendedTestChar3);
155 //Checks BOTH the returned Extended Characteristic values from the CExtendedCharacteristics 'GET' Methods and
156 //the CCryptoParams List returned from the ListExtendedCharacteristics() method
158 if((!(extendedChars->GetTIntCharacteristicL(KExtendCharType1Uid) == exExtendedTestChar1))
159 && (!(extendedCryptoParams->GetTIntL(KExtendCharType1Uid) == exExtendedTestChar1)))
161 ERR_PRINTF1(_L("** FAIL: Extended Characteristic 1 Mismatch **"));
162 User::Leave(KErrNotFound);
165 if((!(extendedChars->GetTIntCharacteristicL(KExtendCharType2Uid) == exExtendedTestChar2))
166 && (!(extendedCryptoParams->GetTIntL(KExtendCharType2Uid) == exExtendedTestChar2)))
168 ERR_PRINTF1(_L("** FAIL: Extended Characteristic 2 Mismatch **"));
169 User::Leave(KErrNotFound);
172 if((!(extendedChars->GetTDesC8CharacteristicL(KExtendCharType3Uid) == *exTestChar3Str))
173 && (!(extendedCryptoParams->GetTDesC8L(KExtendCharType3Uid) == *exTestChar3Str)))
175 ERR_PRINTF1(_L("** FAIL: Extended Characteristic 3 Mismatch **"));
176 User::Leave(KErrNotFound);
179 if((!(extendedChars->GetTIntCharacteristicL(KConcurrencyTypeUid) == exExtendedConcurrency))
180 && (!(extendedCryptoParams->GetTIntL(KConcurrencyTypeUid) == exExtendedConcurrency)))
182 ERR_PRINTF1(_L("** FAIL: 'Concurreny' Extended Characteristic Mismatch **"));
183 User::Leave(KErrNotFound);
186 if((!(extendedChars->GetTIntCharacteristicL(KExclusiveUseTypeUid) == exExtendedExclusiveUse))
187 && (!(extendedCryptoParams->GetTIntL(KExclusiveUseTypeUid) == exExtendedExclusiveUse)))
189 ERR_PRINTF1(_L("** FAIL: 'Exclusive Use' Extended Characteristic Mismatch **"));
190 User::Leave(KErrNotFound);
193 INFO_PRINTF1(_L("** PASS: Extended Characteristics Successfully Match **"));
194 SetTestStepResult(EPass);
196 CleanupStack::PopAndDestroy(exTestChar3Str);
199 CleanupStack::PopAndDestroy(symmetricCipherImpl);
203 ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Cipher Object - %d ***"), err);
206 CleanupStack::PopAndDestroy(3,keyStr);
210 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
211 return TestStepResult();
215 TVerdict CPluginCharsExtendedStep::doTestStepPostambleL()
217 return TestStepResult();