sl@0: /* sl@0: * Copyright (c) 2005-2010 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: * 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 sl@0: #include "randomshim.h" sl@0: sl@0: extern "C" { sl@0: EXPORT_C void RAND_bytes(unsigned char* buf,int bytes) sl@0: { sl@0: TPtr8 ptr(buf,bytes,bytes); sl@0: buf[0]++; sl@0: TRandom::Random(ptr); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C CRandom::CRandom(void) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CSystemRandom* CSystemRandom::NewL(void) sl@0: { sl@0: CSystemRandom* self = NewLC(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CSystemRandom* CSystemRandom::NewLC(void) sl@0: { sl@0: CSystemRandom* self = new(ELeave)CSystemRandom(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: void CSystemRandom::GenerateBytesL(TDes8& aDest) sl@0: { sl@0: TRAPD(error, iShim->GenerateBytesL(aDest)); sl@0: // This method must leave on low memory conditions. sl@0: if(error == KErrNoMemory) sl@0: { sl@0: User::Leave(error); sl@0: } sl@0: } sl@0: sl@0: CSystemRandom::CSystemRandom(void) sl@0: { sl@0: } sl@0: sl@0: CSystemRandom::~CSystemRandom() sl@0: { sl@0: delete iShim; sl@0: } sl@0: sl@0: void CSystemRandom::ConstructL() sl@0: { sl@0: iShim = CRandomShim::NewL(); sl@0: } sl@0: sl@0: // Methods replace by shim are excluded from coverage. 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: EXPORT_C void TRandom::Random(TDes8& aDestination) sl@0: { sl@0: // Method replaced by shim sl@0: TRandomShim::Random(aDestination); sl@0: } sl@0: sl@0: EXPORT_C void TRandom::RandomL(TDes8& aDestination) sl@0: { sl@0: // Method replaced by shim sl@0: TRandomShim::RandomL(aDestination); sl@0: } sl@0: sl@0: EXPORT_C void TRandom::SecureRandomL(TDes8& aDestination) sl@0: { sl@0: // Method replaced by shim sl@0: TRandomShim::SecureRandomL(aDestination); sl@0: } sl@0: sl@0: EXPORT_C RRandomSession::RRandomSession(void) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void RRandomSession::ConnectL(void) sl@0: { sl@0: // No action required sl@0: } sl@0: sl@0: EXPORT_C TInt RRandomSession::GetRandom(TDes8& aDestination) sl@0: { sl@0: // Method replaced by shim sl@0: TRandomShim::Random(aDestination); sl@0: return KErrNone; sl@0: }