os/security/crypto/weakcryptospi/test/tcryptospi/src/asymmetriccipherpositiveobjectloadstep.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 "asymmetriccipherpositiveobjectloadstep.h"
26 #include <cryptospi/cryptoasymmetriccipherapi.h>
27 #include <cryptospi/cryptokeypairgeneratorapi.h>
28 #include <cryptospi/keypair.h>
29 #include "filereader.h"
31 using namespace CryptoSpi;
33 CASymmetricCipherPositiveObjectLoadStep::~CASymmetricCipherPositiveObjectLoadStep()
38 CASymmetricCipherPositiveObjectLoadStep::CASymmetricCipherPositiveObjectLoadStep()
40 SetTestStepName(KASymmetricCipherPositiveObjectLoadStep);
44 TVerdict CASymmetricCipherPositiveObjectLoadStep::doTestStepPreambleL()
46 SetTestStepResult(EPass);
47 return TestStepResult();
51 TVerdict CASymmetricCipherPositiveObjectLoadStep::doTestStepL()
54 INFO_PRINTF1(_L("*** Asymmetric Cipher - Positive Object Load ***"));
55 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
57 if (TestStepResult()==EPass)
60 //Assume faliure, unless all is successful
61 SetTestStepResult(EFail);
63 TVariantPtrC algorithm;
64 TVariantPtrC paddingMode;
67 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid, algorithm) ||
68 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode, paddingMode ))
70 User::Leave(KErrNotFound);
75 CCryptoParams* keyParams = CCryptoParams::NewLC();
77 //****************************************************
78 //Create Key Pair and Key Pair Generator Objects
79 CKeyPair* keyPair = NULL;
80 CKeyPairGenerator * keypairImpl = NULL;
82 INFO_PRINTF1(_L("Generating RSA keys"));
84 // create an RSA key pair
85 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
86 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
88 // create a key pair generator implementation interface
89 TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
91 KRSAKeyPairGeneratorUid,
94 CleanupStack::PushL(keypairImpl);
97 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
99 CleanupStack::PushL(keyPair);
101 //*****************************************************
103 INFO_PRINTF1(_L("Creating Asymmetric Cipher Object..."));
105 // Create a Symmetric Cipher
106 CryptoSpi::CAsymmetricCipher * impl = NULL;
108 TRAP(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL
112 keyPair->PrivateKey(),
113 KCryptoModeEncryptUid,
117 if(impl && (err == KErrNone))
119 // This is a basic test for load positivity
122 INFO_PRINTF1(_L("*** Asymmetric Cipher - Positive Object Load: PASS ***"));
123 SetTestStepResult(EPass);
127 ERR_PRINTF2(_L("*** FAIL: Failed to Create Asymmetric Cipher Object - %d ***"), err);
128 SetTestStepResult(EFail);
131 CleanupStack::PopAndDestroy(keyPair);
132 CleanupStack::PopAndDestroy(keypairImpl);
133 CleanupStack::PopAndDestroy(keyParams);
138 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
140 return TestStepResult();
145 TVerdict CASymmetricCipherPositiveObjectLoadStep::doTestStepPostambleL()
147 return TestStepResult();