author | andy simpson <andrews@symbian.org> |
Mon, 25 Oct 2010 16:13:35 +0100 | |
branch | RCL_3 |
changeset 107 | c3d26e45acc2 |
parent 53 | 030c4fbc13d7 |
permissions | -rw-r--r-- |
17 | 1 |
/* |
50
d07aa956024a
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
2 |
* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
17 | 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 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
/** |
|
20 |
@file |
|
21 |
*/ |
|
22 |
||
23 |
#include <e32std.h> |
|
24 |
#include <e32math.h> |
|
25 |
#include <random.h> |
|
26 |
#include <hash.h> |
|
27 |
#include "randomshim.h" |
|
28 |
||
29 |
extern "C" { |
|
30 |
EXPORT_C void RAND_bytes(unsigned char* buf,int bytes) |
|
31 |
{ |
|
32 |
TPtr8 ptr(buf,bytes,bytes); |
|
33 |
buf[0]++; |
|
34 |
TRandom::Random(ptr); |
|
35 |
} |
|
36 |
} |
|
37 |
||
38 |
EXPORT_C CRandom::CRandom(void) |
|
39 |
{ |
|
40 |
} |
|
41 |
||
42 |
EXPORT_C CSystemRandom* CSystemRandom::NewL(void) |
|
43 |
{ |
|
44 |
CSystemRandom* self = NewLC(); |
|
45 |
CleanupStack::Pop(self); |
|
46 |
return self; |
|
47 |
} |
|
48 |
||
49 |
EXPORT_C CSystemRandom* CSystemRandom::NewLC(void) |
|
50 |
{ |
|
51 |
CSystemRandom* self = new(ELeave)CSystemRandom(); |
|
52 |
CleanupStack::PushL(self); |
|
53 |
self->ConstructL(); |
|
54 |
return self; |
|
55 |
} |
|
56 |
||
57 |
void CSystemRandom::GenerateBytesL(TDes8& aDest) |
|
58 |
{ |
|
50
d07aa956024a
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
59 |
TRAPD(error, iShim->GenerateBytesL(aDest)); |
d07aa956024a
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
60 |
// This method must leave on low memory conditions. |
d07aa956024a
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
61 |
if(error == KErrNoMemory) |
d07aa956024a
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
62 |
{ |
d07aa956024a
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
63 |
User::Leave(error); |
d07aa956024a
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
64 |
} |
d07aa956024a
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
43
diff
changeset
|
65 |
} |
17 | 66 |
|
67 |
CSystemRandom::CSystemRandom(void) |
|
68 |
{ |
|
69 |
} |
|
70 |
||
71 |
CSystemRandom::~CSystemRandom() |
|
72 |
{ |
|
73 |
delete iShim; |
|
74 |
} |
|
75 |
||
76 |
void CSystemRandom::ConstructL() |
|
77 |
{ |
|
78 |
iShim = CRandomShim::NewL(); |
|
79 |
} |
|
80 |
||
81 |
// Methods replace by shim are excluded from coverage. |
|
82 |
#ifdef _BullseyeCoverage |
|
83 |
#pragma suppress_warnings on |
|
84 |
#pragma BullseyeCoverage off |
|
85 |
#pragma suppress_warnings off |
|
86 |
#endif |
|
87 |
EXPORT_C void TRandom::Random(TDes8& aDestination) |
|
88 |
{ |
|
89 |
// Method replaced by shim |
|
90 |
TRandomShim::Random(aDestination); |
|
91 |
} |
|
92 |
||
93 |
EXPORT_C void TRandom::RandomL(TDes8& aDestination) |
|
94 |
{ |
|
95 |
// Method replaced by shim |
|
96 |
TRandomShim::RandomL(aDestination); |
|
97 |
} |
|
43
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
98 |
|
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
99 |
EXPORT_C void TRandom::SecureRandomL(TDes8& aDestination) |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
100 |
{ |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
101 |
// Method replaced by shim |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
102 |
TRandomShim::SecureRandomL(aDestination); |
9b5a3a9fddf8
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
17
diff
changeset
|
103 |
} |
17 | 104 |
|
105 |
EXPORT_C RRandomSession::RRandomSession(void) |
|
106 |
{ |
|
107 |
} |
|
108 |
||
109 |
EXPORT_C void RRandomSession::ConnectL(void) |
|
110 |
{ |
|
53
030c4fbc13d7
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
50
diff
changeset
|
111 |
// No action required |
17 | 112 |
} |
113 |
||
114 |
EXPORT_C TInt RRandomSession::GetRandom(TDes8& aDestination) |
|
115 |
{ |
|
116 |
// Method replaced by shim |
|
117 |
TRandomShim::Random(aDestination); |
|
118 |
return KErrNone; |
|
119 |
} |