First public contribution.
2 * Copyright (c) 2006-2009 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 * crypto random API implementation
16 * crypto random API implementation
25 #include <cryptospi/cryptorandomapi.h>
26 #include <cryptospi/randomplugin.h>
27 #include <cryptospi/plugincharacteristics.h>
28 #include "legacyselector.h"
31 using namespace CryptoSpi;
34 // Synchronous Random Generator
37 CRandom* CRandom::NewL(MRandom* aRandom, TInt aHandle)
39 CRandom* self = new(ELeave) CRandom(aRandom, aHandle);
43 EXPORT_C CRandom::~CRandom()
47 EXPORT_C void CRandom::GenerateRandomBytesL(TDes8& aDest)
49 ((MRandom*)iPlugin)->GenerateRandomBytesL(aDest);
52 CRandom::CRandom(MRandom* aRandom, TInt aHandle)
53 : CCryptoBase(aRandom, aHandle)
58 // Random Factory Implementation
60 EXPORT_C void CRandomFactory::CreateRandomL(CRandom*& aRandom,
62 const CCryptoParams* aAlgorithmParams)
64 MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
67 selector->CreateRandomL(aRandom, aAlgorithmUid, aAlgorithmParams);
71 CLegacySelector* legacySelector=CLegacySelector::NewLC();
72 legacySelector->CreateRandomL(aRandom, aAlgorithmUid, aAlgorithmParams);
73 CleanupStack::PopAndDestroy(legacySelector); //legacySelector
78 // Asynchronous Random Generator
79 // (async methods not implemented, so no coverage)
82 #ifdef _BullseyeCoverage
83 #pragma suppress_warnings on
84 #pragma BullseyeCoverage off
85 #pragma suppress_warnings off
88 CAsyncRandom* CAsyncRandom::NewL(MAsyncRandom* aAsyncRandom, TInt aHandle)
90 CAsyncRandom* self = new(ELeave) CAsyncRandom(aAsyncRandom, aHandle);
94 EXPORT_C CAsyncRandom::~CAsyncRandom()
98 EXPORT_C void CAsyncRandom::GenerateRandomBytesL(TDes8& aDest, TRequestStatus& /*aStatus*/)
100 ((MRandom*)iPlugin)->GenerateRandomBytesL(aDest);
103 CAsyncRandom::CAsyncRandom(MAsyncRandom* aRandom, TInt aHandle)
104 : CCryptoBase(aRandom, aHandle)
108 EXPORT_C void CRandomFactory::CreateAsyncRandomL(CAsyncRandom*& aRandom,
110 const CCryptoParams* aAlgorithmParams)
112 MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
115 selector->CreateAsyncRandomL(aRandom, aAlgorithmUid, aAlgorithmParams);
119 CLegacySelector* legacySelector=CLegacySelector::NewLC();
120 legacySelector->CreateAsyncRandomL(aRandom, aAlgorithmUid, aAlgorithmParams);
121 CleanupStack::PopAndDestroy(legacySelector); //legacySelector