os/security/crypto/weakcryptospi/test/tcryptospi/src/keypairgeneratorpositiveobjectloadstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Example CTestStep derived implementation
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
 @internalTechnology
sl@0
    23
*/
sl@0
    24
#include "keypairgeneratorpositiveobjectloadstep.h"
sl@0
    25
sl@0
    26
sl@0
    27
#include <cryptospi/keypair.h>
sl@0
    28
#include <cryptospi/cryptokeypairgeneratorapi.h>
sl@0
    29
sl@0
    30
using namespace CryptoSpi;
sl@0
    31
sl@0
    32
sl@0
    33
CKeyPairGeneratorPositiveObjectLoadStep::~CKeyPairGeneratorPositiveObjectLoadStep()
sl@0
    34
	{
sl@0
    35
	}
sl@0
    36
sl@0
    37
CKeyPairGeneratorPositiveObjectLoadStep::CKeyPairGeneratorPositiveObjectLoadStep()
sl@0
    38
	{
sl@0
    39
	SetTestStepName(KKeyPairGeneratorPositiveObjectLoadStep);
sl@0
    40
	}
sl@0
    41
sl@0
    42
TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepPreambleL()
sl@0
    43
	{
sl@0
    44
	SetTestStepResult(EPass);
sl@0
    45
	return TestStepResult();
sl@0
    46
	}
sl@0
    47
sl@0
    48
sl@0
    49
TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepL()
sl@0
    50
	{
sl@0
    51
	INFO_PRINTF1(_L("*** Key Pair Generator - Positive Object Load ***"));
sl@0
    52
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
sl@0
    53
	
sl@0
    54
  	if (TestStepResult()==EPass)
sl@0
    55
		{
sl@0
    56
		//Assume faliure, unless all is successful
sl@0
    57
		SetTestStepResult(EFail);
sl@0
    58
sl@0
    59
		TVariantPtrC testVariant;
sl@0
    60
		TVariantPtrC keyVariant;
sl@0
    61
sl@0
    62
		if(	!GetStringFromConfig(ConfigSection(),KConfigExchangeKey, keyVariant))
sl@0
    63
			{
sl@0
    64
			// Leave if there's any error.
sl@0
    65
			User::Leave(KErrNotFound);
sl@0
    66
			}
sl@0
    67
		else
sl@0
    68
			{
sl@0
    69
sl@0
    70
			//Create an new CryptoParams object to encapsulate the key type and secret key string
sl@0
    71
			CCryptoParams* keyParams = CCryptoParams::NewL();
sl@0
    72
			CleanupStack::PushL(keyParams);
sl@0
    73
			keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
sl@0
    74
			keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
sl@0
    75
			
sl@0
    76
			INFO_PRINTF1(_L("Creating Key Pair Generator...")); 
sl@0
    77
sl@0
    78
			// create a key pair generator implementation interface
sl@0
    79
			CKeyPairGenerator* impl = NULL;	
sl@0
    80
			
sl@0
    81
			TRAPD(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(impl, 
sl@0
    82
															KRSAKeyPairGeneratorUid, 
sl@0
    83
															keyParams));
sl@0
    84
			
sl@0
    85
			if(impl && (err == KErrNone))
sl@0
    86
				{
sl@0
    87
				CleanupStack::PushL(impl);
sl@0
    88
sl@0
    89
				INFO_PRINTF1(_L("Generating Key Pair...")); 
sl@0
    90
				// Create a Key Pair with the values from the ini	
sl@0
    91
				CKeyPair* keyPair = NULL;
sl@0
    92
				
sl@0
    93
				TRAP(err,impl->GenerateKeyPairL(1024, 
sl@0
    94
											*keyParams, 
sl@0
    95
											keyPair));
sl@0
    96
				
sl@0
    97
				if(keyPair && (err == KErrNone))
sl@0
    98
					{
sl@0
    99
					delete keyPair;
sl@0
   100
					INFO_PRINTF1(_L("*** PASS: Key Pair Successfully Generated ***"));
sl@0
   101
					SetTestStepResult(EPass);	
sl@0
   102
					}
sl@0
   103
				else
sl@0
   104
					{
sl@0
   105
					ERR_PRINTF2(_L("*** FAIL: Key Pair Generation Failure - %d ***"), err);
sl@0
   106
					SetTestStepResult(EFail);	
sl@0
   107
					}
sl@0
   108
	
sl@0
   109
				CleanupStack::PopAndDestroy(impl);	
sl@0
   110
				}
sl@0
   111
			else
sl@0
   112
				{
sl@0
   113
				ERR_PRINTF2(_L("*** FAIL: Key Pair Generator Load Failure - %d ***"), err);
sl@0
   114
				SetTestStepResult(EFail);	
sl@0
   115
				}
sl@0
   116
			
sl@0
   117
			CleanupStack::PopAndDestroy(keyParams);
sl@0
   118
			}
sl@0
   119
sl@0
   120
		INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
sl@0
   121
		
sl@0
   122
		}
sl@0
   123
	  return TestStepResult();
sl@0
   124
	}
sl@0
   125
sl@0
   126
sl@0
   127
sl@0
   128
TVerdict CKeyPairGeneratorPositiveObjectLoadStep::doTestStepPostambleL()
sl@0
   129
	{
sl@0
   130
	return TestStepResult();
sl@0
   131
	}