os/security/crypto/weakcryptospi/test/tcryptospi/src/signerpositiveobjectloadstep.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 "signerpositiveobjectloadstep.h"
26 #include <cryptospi/keypair.h>
27 #include <cryptospi/cryptosignatureapi.h>
28 #include <cryptospi/cryptokeypairgeneratorapi.h>
30 using namespace CryptoSpi;
33 CSignerPositiveObjectLoadStep::~CSignerPositiveObjectLoadStep()
37 CSignerPositiveObjectLoadStep::CSignerPositiveObjectLoadStep()
39 SetTestStepName(KSignerPositiveObjectLoadStep);
42 TVerdict CSignerPositiveObjectLoadStep::doTestStepPreambleL()
44 SetTestStepResult(EPass);
45 return TestStepResult();
49 TVerdict CSignerPositiveObjectLoadStep::doTestStepL()
51 INFO_PRINTF1(_L("*** Signer - 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,
86 CleanupStack::PushL(keypairImpl);
89 // Generate a Key Pair
90 INFO_PRINTF1(_L("Generating Key Pair..."));
92 CKeyPair* keyPair = NULL;
94 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024,
98 CleanupStack::PushL(keyPair);
100 // Creating Signer 1 with the necessary values from the ini file
101 INFO_PRINTF1(_L("Constructing Signer 1 (No Padding)..."));
102 CSigner * impl1 = NULL;
103 TRAP_LOG(err,CSignatureFactory::CreateSignerL(impl1,
105 keyPair->PublicKey(),
109 CleanupStack::PushL(impl1);
111 // Creating Signer 2 with the necessary values from the ini file
112 INFO_PRINTF1(_L("Constructing Signer 2 (Pkcs1_v1_5 Padding)..."));
113 CSigner * impl2 = NULL;
114 TRAP_LOG(err,CSignatureFactory::CreateSignerL(impl2,
116 keyPair->PublicKey(),
117 KPaddingModePkcs1_v1_5_SignatureUid,
120 CleanupStack::PushL(impl2);
122 if((impl1) && (impl2) && (err == KErrNone))
124 // This is a basic test for load positivity
126 INFO_PRINTF1(_L("PASS: Signer - Positive Object Load"));
127 SetTestStepResult(EPass);
131 ERR_PRINTF2(_L("FAIL: Signer Object Construction Failure - %d"), err);
132 SetTestStepResult(EFail);
135 CleanupStack::PopAndDestroy(impl2);
136 CleanupStack::PopAndDestroy(impl1);
138 CleanupStack::PopAndDestroy(keyPair);
139 CleanupStack::PopAndDestroy(keypairImpl);
140 CleanupStack::PopAndDestroy(keyParams);
143 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
146 return TestStepResult();
151 TVerdict CSignerPositiveObjectLoadStep::doTestStepPostambleL()
153 return TestStepResult();