os/security/crypto/weakcryptospi/test/tcryptospi/src/asymmetriccipherpositiveobjectloadstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * Example CTestStep derived implementation
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22  @internalTechnology
    23 */
    24 #include "asymmetriccipherpositiveobjectloadstep.h"
    25 
    26 #include <cryptospi/cryptoasymmetriccipherapi.h>
    27 #include <cryptospi/cryptokeypairgeneratorapi.h>
    28 #include <cryptospi/keypair.h>
    29 #include "filereader.h"
    30 
    31 using namespace CryptoSpi;
    32 
    33 CASymmetricCipherPositiveObjectLoadStep::~CASymmetricCipherPositiveObjectLoadStep()
    34 	{
    35 	}
    36 
    37 
    38 CASymmetricCipherPositiveObjectLoadStep::CASymmetricCipherPositiveObjectLoadStep()
    39 	{
    40 	SetTestStepName(KASymmetricCipherPositiveObjectLoadStep);
    41 	}
    42 
    43 
    44 TVerdict CASymmetricCipherPositiveObjectLoadStep::doTestStepPreambleL()
    45 	{
    46 	SetTestStepResult(EPass);
    47 	return TestStepResult();
    48 	}
    49 
    50 
    51 TVerdict CASymmetricCipherPositiveObjectLoadStep::doTestStepL()
    52 	{
    53 
    54 	INFO_PRINTF1(_L("*** Asymmetric Cipher - Positive Object Load ***"));
    55 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    56 	
    57   	if (TestStepResult()==EPass)
    58 		{
    59 		
    60 		//Assume faliure, unless all is successful
    61 		SetTestStepResult(EFail);
    62 		
    63 		TVariantPtrC algorithm;
    64 		TVariantPtrC paddingMode;
    65 		
    66 		
    67 		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid, algorithm) || 
    68 			!GetStringFromConfig(ConfigSection(),KConfigPaddingMode, paddingMode ))
    69 			{
    70 			User::Leave(KErrNotFound);
    71 			}
    72 		else
    73 			{
    74 				
    75 			CCryptoParams* keyParams = CCryptoParams::NewLC(); 
    76 			
    77 			//****************************************************
    78 			//Create Key Pair and Key Pair Generator Objects
    79    			CKeyPair* keyPair = NULL;
    80 			CKeyPairGenerator * keypairImpl = NULL;
    81 			
    82 			INFO_PRINTF1(_L("Generating RSA keys"));
    83 			
    84 			// create an RSA key pair
    85 			keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
    86 			keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
    87 
    88 			// create a key pair generator implementation interface
    89 			TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
    90 											keypairImpl, 
    91 											KRSAKeyPairGeneratorUid, 
    92 											keyParams));
    93 											
    94 			CleanupStack::PushL(keypairImpl);
    95 
    96 			// Create a Key Pair	
    97 			TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
    98 			
    99 			CleanupStack::PushL(keyPair);
   100 			
   101 			//*****************************************************
   102 		
   103 			INFO_PRINTF1(_L("Creating Asymmetric Cipher Object..."));
   104 			
   105 			// Create a Symmetric Cipher 
   106 			CryptoSpi::CAsymmetricCipher * impl = NULL;
   107 				
   108 			TRAP(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL
   109 												(
   110 												impl,
   111 												algorithm,
   112 												keyPair->PrivateKey(),
   113 												KCryptoModeEncryptUid,
   114 												paddingMode,
   115 												NULL));
   116 	
   117 			if(impl && (err == KErrNone))
   118 				{
   119 				// This is a basic test for load positivity
   120 				// from the Factory
   121 				delete impl;
   122 				INFO_PRINTF1(_L("*** Asymmetric Cipher - Positive Object Load: PASS ***"));
   123 				SetTestStepResult(EPass);
   124 				}
   125 			else
   126 				{
   127 				ERR_PRINTF2(_L("*** FAIL: Failed to Create Asymmetric Cipher Object - %d ***"), err);
   128 				SetTestStepResult(EFail);
   129 				}
   130 				
   131 			CleanupStack::PopAndDestroy(keyPair);
   132 			CleanupStack::PopAndDestroy(keypairImpl);			
   133 			CleanupStack::PopAndDestroy(keyParams);			
   134 			}
   135 			
   136 		}
   137 	
   138 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
   139 
   140 	return TestStepResult();
   141 	}
   142 
   143 
   144 
   145 TVerdict CASymmetricCipherPositiveObjectLoadStep::doTestStepPostambleL()
   146 	{
   147 	return TestStepResult();
   148 	}