os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsasymkeypairstep.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.
24 #include "plugincharsasymkeypairstep.h"
25 #include "plugincharschecker.h"
27 #include <cryptospi/keypair.h>
28 #include <cryptospi/cryptokeypairgeneratorapi.h>
30 using namespace CryptoSpi;
32 CPluginCharsAsymKeyPairStep::~CPluginCharsAsymKeyPairStep()
36 CPluginCharsAsymKeyPairStep::CPluginCharsAsymKeyPairStep()
38 SetTestStepName(KPluginCharsAsymKeyPairStep);
41 TVerdict CPluginCharsAsymKeyPairStep::doTestStepPreambleL()
43 SetTestStepResult(EPass);
44 return TestStepResult();
47 TVerdict CPluginCharsAsymKeyPairStep::doTestStepL()
50 INFO_PRINTF1(_L("Plugin Characteristics - Asymmetric Key Pair Generator Chracteristics"));
51 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
53 if (TestStepResult()==EPass)
56 //Assume faliure, unless all is successful
57 SetTestStepResult(EFail);
59 TVariantPtrC algorithmUid;
61 //Each of the individual parameters required to create the Asymmetric Key Pair Generator object
62 //are read in from the specified INI configuration file
63 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid))
65 ERR_PRINTF1(_L("** .INI Error: Asymmetric Key Pair Generator Cipher Arguments Not Located **"));
66 SetTestStepResult(EFail);
70 CCryptoParams* keyParams = CCryptoParams::NewLC();
72 //Create Key Pair Generator Object
73 CKeyPairGenerator* keyPairGenImpl = NULL;
75 //Create a Asymmetric Key Pair Generator Implementation
76 TRAPD(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keyPairGenImpl,
80 if(keyPairGenImpl && (err == KErrNone))
83 CleanupStack::PushL(keyPairGenImpl);
85 INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Key Pair Generator Object **"));
87 //Define a pointer of type TCharacteristics in order to store the asymmetric key pair generator
88 //object's characterisctics
89 const TCharacteristics* chars(NULL);
91 //Retrieve the characteristics for the asymmetric key pair generator implementation object
92 keyPairGenImpl->GetCharacteristicsL(chars);
94 //Static cast the characteristics to type TKeyAgreementCharacteristics
95 const TAsymmetricKeypairGeneratorCharacteristics* asymkeypairgenChars = static_cast<const TAsymmetricKeypairGeneratorCharacteristics*>(chars);
97 //Retrieve all the Common characteristics that are required for the test
98 TVariantPtrC exInterfaceUid;
99 TVariantPtrC exAlgorithmUid;
100 TVariantPtrC exImplementationUid;
101 TVariantPtrC exCreatorName;
102 TBool exFIPSApproved;
103 TBool exHardwareSupported;
104 TInt exMaxConcurrencySupported;
105 TVariantPtrC exAlgorithmName;
109 //Retrieve all the Asymmetric Key Pair Generator characteristics that are required for the test
110 TInt exAsymKeyPairMaxKeyLength;
112 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
113 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
114 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
115 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
116 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
117 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
118 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
119 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
120 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
121 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
122 !GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exAsymKeyPairMaxKeyLength))
124 ERR_PRINTF1(_L("** .INI Error: Expected Asymmetric Key Pair Generator/Common Characteristics Not Located **"));
125 SetTestStepResult(EFail);
130 INFO_PRINTF1(_L("** Checking Asymmetric Key Pair Generator/Common Characteristics.... **"));
132 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
134 //Retrieve the Common Characteristics from TAsymmetricKeypairGeneratorCharacteristics
135 const TCommonCharacteristics* asymkeypairgenCommonChars = &asymkeypairgenChars->cmn;
139 //Perform Key Agreement/Common Characteristic Checks
140 if(pluginCheck->checkCommonCharacteristics(asymkeypairgenCommonChars,
147 exMaxConcurrencySupported,
152 pluginCheck->checkAsymKeypairGenCharacteristics(asymkeypairgenChars,
153 exAsymKeyPairMaxKeyLength,
156 INFO_PRINTF1(_L("** PASS : Asymmetric Key Pair Generator/Common characteristics successfully match expected values **"));
157 SetTestStepResult(EPass);
161 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
164 CleanupStack::PopAndDestroy(pluginCheck);
167 CleanupStack::PopAndDestroy(keyPairGenImpl);
171 ERR_PRINTF2(_L("*** FAIL: Failed to Create Asymmetric Key Pair Generator Object - %d ***"), err);
174 CleanupStack::PopAndDestroy(keyParams);
179 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
180 return TestStepResult();
183 TVerdict CPluginCharsAsymKeyPairStep::doTestStepPostambleL()
185 return TestStepResult();