os/security/crypto/weakcryptospi/test/tcryptospi/src/keypairgeneratorpositiveobjectloadstep.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 "keypairgeneratorpositiveobjectloadstep.h"
27 #include <cryptospi/keypair.h>
28 #include <cryptospi/cryptokeypairgeneratorapi.h>
30 using namespace CryptoSpi;
33 CKeyPairGeneratorPositiveObjectLoadStep::~CKeyPairGeneratorPositiveObjectLoadStep()
37 CKeyPairGeneratorPositiveObjectLoadStep::CKeyPairGeneratorPositiveObjectLoadStep()
39 SetTestStepName(KKeyPairGeneratorPositiveObjectLoadStep);
42 TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepPreambleL()
44 SetTestStepResult(EPass);
45 return TestStepResult();
49 TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepL()
51 INFO_PRINTF1(_L("*** Key Pair Generator - 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);
70 //Create an new CryptoParams object to encapsulate the key type and secret key string
71 CCryptoParams* keyParams = CCryptoParams::NewL();
72 CleanupStack::PushL(keyParams);
73 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
74 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
76 INFO_PRINTF1(_L("Creating Key Pair Generator..."));
78 // create a key pair generator implementation interface
79 CKeyPairGenerator* impl = NULL;
81 TRAPD(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(impl,
82 KRSAKeyPairGeneratorUid,
85 if(impl && (err == KErrNone))
87 CleanupStack::PushL(impl);
89 INFO_PRINTF1(_L("Generating Key Pair..."));
90 // Create a Key Pair with the values from the ini
91 CKeyPair* keyPair = NULL;
93 TRAP(err,impl->GenerateKeyPairL(1024,
97 if(keyPair && (err == KErrNone))
100 INFO_PRINTF1(_L("*** PASS: Key Pair Successfully Generated ***"));
101 SetTestStepResult(EPass);
105 ERR_PRINTF2(_L("*** FAIL: Key Pair Generation Failure - %d ***"), err);
106 SetTestStepResult(EFail);
109 CleanupStack::PopAndDestroy(impl);
113 ERR_PRINTF2(_L("*** FAIL: Key Pair Generator Load Failure - %d ***"), err);
114 SetTestStepResult(EFail);
117 CleanupStack::PopAndDestroy(keyParams);
120 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
123 return TestStepResult();
128 TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepPostambleL()
130 return TestStepResult();