sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * crypto random API implementation sl@0: * crypto random API implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "legacyselector.h" sl@0: sl@0: sl@0: using namespace CryptoSpi; sl@0: sl@0: // sl@0: // Synchronous Random Generator sl@0: // sl@0: sl@0: CRandom* CRandom::NewL(MRandom* aRandom, TInt aHandle) sl@0: { sl@0: CRandom* self = new(ELeave) CRandom(aRandom, aHandle); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CRandom::~CRandom() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CRandom::GenerateRandomBytesL(TDes8& aDest) sl@0: { sl@0: ((MRandom*)iPlugin)->GenerateRandomBytesL(aDest); sl@0: } sl@0: sl@0: CRandom::CRandom(MRandom* aRandom, TInt aHandle) sl@0: : CCryptoBase(aRandom, aHandle) sl@0: { sl@0: } sl@0: sl@0: // sl@0: // Random Factory Implementation sl@0: // sl@0: EXPORT_C void CRandomFactory::CreateRandomL(CRandom*& aRandom, sl@0: TUid aAlgorithmUid, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: MPluginSelector* selector=reinterpret_cast(Dll::Tls()); sl@0: if (selector) sl@0: { sl@0: selector->CreateRandomL(aRandom, aAlgorithmUid, aAlgorithmParams); sl@0: } sl@0: else sl@0: { sl@0: CLegacySelector* legacySelector=CLegacySelector::NewLC(); sl@0: legacySelector->CreateRandomL(aRandom, aAlgorithmUid, aAlgorithmParams); sl@0: CleanupStack::PopAndDestroy(legacySelector); //legacySelector sl@0: } sl@0: } sl@0: sl@0: // sl@0: // Asynchronous Random Generator sl@0: // (async methods not implemented, so no coverage) sl@0: // sl@0: sl@0: #ifdef _BullseyeCoverage sl@0: #pragma suppress_warnings on sl@0: #pragma BullseyeCoverage off sl@0: #pragma suppress_warnings off sl@0: #endif sl@0: sl@0: CAsyncRandom* CAsyncRandom::NewL(MAsyncRandom* aAsyncRandom, TInt aHandle) sl@0: { sl@0: CAsyncRandom* self = new(ELeave) CAsyncRandom(aAsyncRandom, aHandle); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CAsyncRandom::~CAsyncRandom() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CAsyncRandom::GenerateRandomBytesL(TDes8& aDest, TRequestStatus& /*aStatus*/) sl@0: { sl@0: ((MRandom*)iPlugin)->GenerateRandomBytesL(aDest); sl@0: } sl@0: sl@0: CAsyncRandom::CAsyncRandom(MAsyncRandom* aRandom, TInt aHandle) sl@0: : CCryptoBase(aRandom, aHandle) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CRandomFactory::CreateAsyncRandomL(CAsyncRandom*& aRandom, sl@0: TUid aAlgorithmUid, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: MPluginSelector* selector=reinterpret_cast(Dll::Tls()); sl@0: if (selector) sl@0: { sl@0: selector->CreateAsyncRandomL(aRandom, aAlgorithmUid, aAlgorithmParams); sl@0: } sl@0: else sl@0: { sl@0: CLegacySelector* legacySelector=CLegacySelector::NewLC(); sl@0: legacySelector->CreateAsyncRandomL(aRandom, aAlgorithmUid, aAlgorithmParams); sl@0: CleanupStack::PopAndDestroy(legacySelector); //legacySelector sl@0: } sl@0: } sl@0: