os/security/crypto/weakcryptospi/test/tcryptospi/src/verifierpositiveobjectloadstep.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.
15 * Example CTestStep derived implementation
24 #include "verifierpositiveobjectloadstep.h"
26 #include <cryptospi/keys.h>
27 #include <cryptospi/keypair.h>
28 #include <cryptospi/cryptosignatureapi.h>
29 #include <cryptospi/cryptokeypairgeneratorapi.h>
31 using namespace CryptoSpi;
33 CVerifierPositiveObjectLoadStep::~CVerifierPositiveObjectLoadStep()
37 CVerifierPositiveObjectLoadStep::CVerifierPositiveObjectLoadStep()
39 SetTestStepName(KVerifierPositiveObjectLoadStep);
42 TVerdict CVerifierPositiveObjectLoadStep::doTestStepPreambleL()
44 SetTestStepResult(EPass);
45 return TestStepResult();
49 TVerdict CVerifierPositiveObjectLoadStep::doTestStepL()
51 INFO_PRINTF1(_L("*** Verifier - Positive Object Load ***"));
52 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
54 if (TestStepResult()==EPass)
56 //Assume faliure, unless all is successful
57 SetTestStepResult(EFail);
59 TVariantPtrC testVariant;
60 TVariantPtrC keyVariant;
62 if( !GetStringFromConfig(ConfigSection(),KConfigExchangeKey, keyVariant))
64 // Leave if there's any error.
65 User::Leave(KErrNotFound);
69 //Create an new CryptoParams object to encapsulate the key type and secret key string
70 CCryptoParams* keyParams = CCryptoParams::NewL();
71 CleanupStack::PushL(keyParams);
73 //Set the Key Parameters
74 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
75 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
77 // Create a Key Pair Generator implementation
78 INFO_PRINTF1(_L("Creating Key Pair Generator..."));
80 CKeyPairGenerator * keypairImpl = NULL;
82 TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
83 KRSAKeyPairGeneratorUid,
85 CleanupStack::PushL(keypairImpl);
88 // Generate a Key Pair
89 INFO_PRINTF1(_L("Generating Key Pair..."));
91 CKeyPair* keyPair = NULL;
93 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024,
97 CleanupStack::PushL(keyPair);
100 // Creating Verifier 1 with necessary values from the ini file
101 INFO_PRINTF1(_L("Constructing Verifier 1 (No Padding)..."));
103 CVerifier * impl1 = NULL;
104 TRAP_LOG(err,CSignatureFactory::CreateVerifierL
107 keyPair->PrivateKey(),
111 CleanupStack::PushL(impl1);
114 // Creating Verifier 2 with the necessary values from the ini file
115 INFO_PRINTF1(_L("Constructing Verifier 1 (No Padding)..."));
117 CVerifier * impl2 = NULL;
118 TRAP_LOG(err,CSignatureFactory::CreateVerifierL
121 keyPair->PrivateKey(),
122 KPaddingModePkcs1_v1_5_SignatureUid,
125 CleanupStack::PushL(impl2);
127 if((impl1) && (impl2) && (err == KErrNone))
129 // This is a basic test for load positivity
131 INFO_PRINTF1(_L("PASS: Verifier - Positive Object Load"));
132 SetTestStepResult(EPass);
136 ERR_PRINTF2(_L("FAIL: Verifier Object Construction Failure - %d"), err);
137 SetTestStepResult(EFail);
140 CleanupStack::PopAndDestroy(impl2);
141 CleanupStack::PopAndDestroy(impl1);
143 CleanupStack::PopAndDestroy(keyPair);
144 CleanupStack::PopAndDestroy(keypairImpl);
145 CleanupStack::PopAndDestroy(keyParams);
148 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
151 return TestStepResult();
156 TVerdict CVerifierPositiveObjectLoadStep::doTestStepPostambleL()
158 return TestStepResult();