crypto/weakcryptospi/source/spi/cryptorandomapi.cpp
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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 * crypto random API implementation
       
    16 * crypto random API implementation
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include <cryptospi/cryptorandomapi.h>
       
    26 #include <cryptospi/randomplugin.h>
       
    27 #include <cryptospi/plugincharacteristics.h>
       
    28 #include "legacyselector.h"
       
    29 
       
    30 
       
    31 using namespace CryptoSpi;
       
    32 
       
    33 //
       
    34 // Synchronous Random Generator
       
    35 //
       
    36 
       
    37 CRandom* CRandom::NewL(MRandom* aRandom, TInt aHandle)
       
    38 	{
       
    39 	CRandom* self = new(ELeave) CRandom(aRandom, aHandle);
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 EXPORT_C CRandom::~CRandom()
       
    44 	{
       
    45 	}
       
    46 
       
    47 EXPORT_C void CRandom::GenerateRandomBytesL(TDes8& aDest)
       
    48 	{
       
    49 	((MRandom*)iPlugin)->GenerateRandomBytesL(aDest);
       
    50 	}
       
    51 	
       
    52 CRandom::CRandom(MRandom* aRandom, TInt aHandle) 
       
    53 : CCryptoBase(aRandom, aHandle)
       
    54 	{
       
    55 	}
       
    56 
       
    57 //
       
    58 // Random Factory Implementation
       
    59 //
       
    60 EXPORT_C void CRandomFactory::CreateRandomL(CRandom*& aRandom,
       
    61 										TUid aAlgorithmUid,
       
    62 										const CCryptoParams* aAlgorithmParams)
       
    63 	{
       
    64 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
    65 	if (selector)
       
    66 		{
       
    67 		selector->CreateRandomL(aRandom, aAlgorithmUid, aAlgorithmParams);	
       
    68 		}
       
    69 	else
       
    70 		{
       
    71 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
    72 		legacySelector->CreateRandomL(aRandom, aAlgorithmUid, aAlgorithmParams);
       
    73 		CleanupStack::PopAndDestroy(legacySelector); //legacySelector			
       
    74 		}
       
    75 	}
       
    76 
       
    77 //
       
    78 // Asynchronous Random Generator
       
    79 // (async methods not implemented, so no coverage)
       
    80 //
       
    81 
       
    82 #ifdef _BullseyeCoverage
       
    83 #pragma suppress_warnings on
       
    84 #pragma BullseyeCoverage off
       
    85 #pragma suppress_warnings off
       
    86 #endif
       
    87 
       
    88 CAsyncRandom* CAsyncRandom::NewL(MAsyncRandom* aAsyncRandom, TInt aHandle)
       
    89 	{
       
    90 	CAsyncRandom* self = new(ELeave) CAsyncRandom(aAsyncRandom, aHandle);
       
    91 	return self;
       
    92 	}
       
    93 
       
    94 EXPORT_C CAsyncRandom::~CAsyncRandom()
       
    95 	{
       
    96 	}
       
    97 	
       
    98 EXPORT_C void CAsyncRandom::GenerateRandomBytesL(TDes8& aDest, TRequestStatus& /*aStatus*/)
       
    99 	{
       
   100 	((MRandom*)iPlugin)->GenerateRandomBytesL(aDest);
       
   101 	}
       
   102 
       
   103 CAsyncRandom::CAsyncRandom(MAsyncRandom* aRandom, TInt aHandle)
       
   104 : CCryptoBase(aRandom, aHandle)
       
   105 	{
       
   106 	}
       
   107 
       
   108 EXPORT_C void CRandomFactory::CreateAsyncRandomL(CAsyncRandom*& aRandom,
       
   109 										TUid aAlgorithmUid,
       
   110 										const CCryptoParams* aAlgorithmParams)
       
   111 	{
       
   112 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   113 	if (selector)
       
   114 		{
       
   115 		selector->CreateAsyncRandomL(aRandom, aAlgorithmUid, aAlgorithmParams);	
       
   116 		}
       
   117 	else
       
   118 		{
       
   119 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   120 		legacySelector->CreateAsyncRandomL(aRandom, aAlgorithmUid, aAlgorithmParams);
       
   121 		CleanupStack::PopAndDestroy(legacySelector); //legacySelector			
       
   122 		}	
       
   123 	}
       
   124