os/security/crypto/weakcryptospi/test/tcryptospi/src/keypairgeneratorpositiveobjectloadstep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/keypairgeneratorpositiveobjectloadstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,131 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Example CTestStep derived implementation
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalTechnology
1.26 +*/
1.27 +#include "keypairgeneratorpositiveobjectloadstep.h"
1.28 +
1.29 +
1.30 +#include <cryptospi/keypair.h>
1.31 +#include <cryptospi/cryptokeypairgeneratorapi.h>
1.32 +
1.33 +using namespace CryptoSpi;
1.34 +
1.35 +
1.36 +CKeyPairGeneratorPositiveObjectLoadStep::~CKeyPairGeneratorPositiveObjectLoadStep()
1.37 + {
1.38 + }
1.39 +
1.40 +CKeyPairGeneratorPositiveObjectLoadStep::CKeyPairGeneratorPositiveObjectLoadStep()
1.41 + {
1.42 + SetTestStepName(KKeyPairGeneratorPositiveObjectLoadStep);
1.43 + }
1.44 +
1.45 +TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepPreambleL()
1.46 + {
1.47 + SetTestStepResult(EPass);
1.48 + return TestStepResult();
1.49 + }
1.50 +
1.51 +
1.52 +TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepL()
1.53 + {
1.54 + INFO_PRINTF1(_L("*** Key Pair Generator - Positive Object Load ***"));
1.55 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.56 +
1.57 + if (TestStepResult()==EPass)
1.58 + {
1.59 + //Assume faliure, unless all is successful
1.60 + SetTestStepResult(EFail);
1.61 +
1.62 + TVariantPtrC testVariant;
1.63 + TVariantPtrC keyVariant;
1.64 +
1.65 + if( !GetStringFromConfig(ConfigSection(),KConfigExchangeKey, keyVariant))
1.66 + {
1.67 + // Leave if there's any error.
1.68 + User::Leave(KErrNotFound);
1.69 + }
1.70 + else
1.71 + {
1.72 +
1.73 + //Create an new CryptoParams object to encapsulate the key type and secret key string
1.74 + CCryptoParams* keyParams = CCryptoParams::NewL();
1.75 + CleanupStack::PushL(keyParams);
1.76 + keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
1.77 + keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
1.78 +
1.79 + INFO_PRINTF1(_L("Creating Key Pair Generator..."));
1.80 +
1.81 + // create a key pair generator implementation interface
1.82 + CKeyPairGenerator* impl = NULL;
1.83 +
1.84 + TRAPD(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(impl,
1.85 + KRSAKeyPairGeneratorUid,
1.86 + keyParams));
1.87 +
1.88 + if(impl && (err == KErrNone))
1.89 + {
1.90 + CleanupStack::PushL(impl);
1.91 +
1.92 + INFO_PRINTF1(_L("Generating Key Pair..."));
1.93 + // Create a Key Pair with the values from the ini
1.94 + CKeyPair* keyPair = NULL;
1.95 +
1.96 + TRAP(err,impl->GenerateKeyPairL(1024,
1.97 + *keyParams,
1.98 + keyPair));
1.99 +
1.100 + if(keyPair && (err == KErrNone))
1.101 + {
1.102 + delete keyPair;
1.103 + INFO_PRINTF1(_L("*** PASS: Key Pair Successfully Generated ***"));
1.104 + SetTestStepResult(EPass);
1.105 + }
1.106 + else
1.107 + {
1.108 + ERR_PRINTF2(_L("*** FAIL: Key Pair Generation Failure - %d ***"), err);
1.109 + SetTestStepResult(EFail);
1.110 + }
1.111 +
1.112 + CleanupStack::PopAndDestroy(impl);
1.113 + }
1.114 + else
1.115 + {
1.116 + ERR_PRINTF2(_L("*** FAIL: Key Pair Generator Load Failure - %d ***"), err);
1.117 + SetTestStepResult(EFail);
1.118 + }
1.119 +
1.120 + CleanupStack::PopAndDestroy(keyParams);
1.121 + }
1.122 +
1.123 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.124 +
1.125 + }
1.126 + return TestStepResult();
1.127 + }
1.128 +
1.129 +
1.130 +
1.131 +TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepPostambleL()
1.132 + {
1.133 + return TestStepResult();
1.134 + }