sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* crypto signature API implementation
|
sl@0
|
16 |
* crypto signature API implementation
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
@file
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#include <cryptospi/cryptosignatureapi.h>
|
sl@0
|
26 |
#include <cryptospi/signerplugin.h>
|
sl@0
|
27 |
#include <cryptospi/verifierplugin.h>
|
sl@0
|
28 |
#include "legacyselector.h"
|
sl@0
|
29 |
|
sl@0
|
30 |
using namespace CryptoSpi;
|
sl@0
|
31 |
|
sl@0
|
32 |
|
sl@0
|
33 |
//
|
sl@0
|
34 |
// Implementation of signature base class
|
sl@0
|
35 |
//
|
sl@0
|
36 |
CSignatureBase::CSignatureBase(MSignatureBase* aSignatureProcessor, TInt aHandle)
|
sl@0
|
37 |
: CCryptoBase(aSignatureProcessor, aHandle)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
CSignatureBase::~CSignatureBase()
|
sl@0
|
42 |
{
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
EXPORT_C void CSignatureBase::SetPaddingModeL(TUid aPaddingMode)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
MSignatureBase* ptr=static_cast<MSignatureBase*>(iPlugin);
|
sl@0
|
48 |
ptr->SetPaddingModeL(aPaddingMode);
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
EXPORT_C void CSignatureBase::SetKeyL(const CKey& aPrivateKey)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
MSignatureBase* ptr=static_cast<MSignatureBase*>(iPlugin);
|
sl@0
|
54 |
ptr->SetKeyL(aPrivateKey);
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
EXPORT_C TInt CSignatureBase::GetMaximumInputLengthL() const
|
sl@0
|
58 |
{
|
sl@0
|
59 |
MSignatureBase* ptr=static_cast<MSignatureBase*>(iPlugin);
|
sl@0
|
60 |
return ptr->GetMaximumInputLengthL();
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
EXPORT_C TInt CSignatureBase::GetMaximumOutputLengthL() const
|
sl@0
|
64 |
{
|
sl@0
|
65 |
MSignatureBase* ptr=static_cast<MSignatureBase*>(iPlugin);
|
sl@0
|
66 |
return ptr->GetMaximumOutputLengthL();
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
//
|
sl@0
|
70 |
// Implementation of Signer
|
sl@0
|
71 |
//
|
sl@0
|
72 |
CSigner* CSigner::NewL(MSigner* aSigner, TInt aHandle)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
CSigner* self=new(ELeave) CSigner(aSigner, aHandle);
|
sl@0
|
75 |
return self;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
CSigner::CSigner(MSigner* aSigner, TInt aHandle) : CSignatureBase(aSigner, aHandle)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
EXPORT_C CSigner::~CSigner()
|
sl@0
|
83 |
{
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
EXPORT_C void CSigner::SignL(const TDesC8& aInput, CCryptoParams& aSignature)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
MSigner* ptr=static_cast<MSigner*>(iPlugin);
|
sl@0
|
89 |
ptr->SignL(aInput, aSignature);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
|
sl@0
|
93 |
//
|
sl@0
|
94 |
// Implementation of Verifier
|
sl@0
|
95 |
//
|
sl@0
|
96 |
CVerifier* CVerifier::NewL(MVerifier* aVerifier, TInt aHandle)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
CVerifier* self=new(ELeave) CVerifier(aVerifier, aHandle);
|
sl@0
|
99 |
return self;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
CVerifier::CVerifier(MVerifier* aVerifier, TInt aHandle)
|
sl@0
|
103 |
: CSignatureBase(aVerifier, aHandle)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
EXPORT_C CVerifier::~CVerifier()
|
sl@0
|
108 |
{
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
EXPORT_C void CVerifier::VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
MVerifier* ptr=static_cast<MVerifier*>(iPlugin);
|
sl@0
|
114 |
ptr->VerifyL(aInput, aSignature, aVerificationResult);
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
EXPORT_C void CVerifier::InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
MVerifier* ptr=static_cast<MVerifier*>(iPlugin);
|
sl@0
|
120 |
ptr->InverseSignL(aOutput, aSignature);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
//
|
sl@0
|
124 |
// Implementation of Signer and Verifier Factory
|
sl@0
|
125 |
//
|
sl@0
|
126 |
EXPORT_C void CSignatureFactory::CreateSignerL(CSigner*& aSigner,
|
sl@0
|
127 |
TUid aAlgorithmUid,
|
sl@0
|
128 |
const CKey& aKey,
|
sl@0
|
129 |
TUid aPaddingMode,
|
sl@0
|
130 |
const CCryptoParams* aAlgorithmParams)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
|
sl@0
|
133 |
if (selector)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
selector->CreateSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
|
sl@0
|
136 |
}
|
sl@0
|
137 |
else
|
sl@0
|
138 |
{
|
sl@0
|
139 |
CLegacySelector* legacySelector=CLegacySelector::NewLC();
|
sl@0
|
140 |
legacySelector->CreateSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
|
sl@0
|
141 |
CleanupStack::PopAndDestroy(legacySelector); //selector
|
sl@0
|
142 |
}
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
EXPORT_C void CSignatureFactory::CreateVerifierL(CVerifier*& aVerifier,
|
sl@0
|
146 |
TUid aAlgorithmUid,
|
sl@0
|
147 |
const CKey& aKey,
|
sl@0
|
148 |
TUid aPaddingMode,
|
sl@0
|
149 |
const CCryptoParams* aAlgorithmParams)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
|
sl@0
|
152 |
if (selector)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
selector->CreateVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
else
|
sl@0
|
157 |
{
|
sl@0
|
158 |
CLegacySelector* legacySelector=CLegacySelector::NewLC();
|
sl@0
|
159 |
legacySelector->CreateVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
|
sl@0
|
160 |
CleanupStack::PopAndDestroy(legacySelector); //legacySelector
|
sl@0
|
161 |
}
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
//
|
sl@0
|
165 |
// Implementation of Asynchronous Signer
|
sl@0
|
166 |
// (async methods not implemented, so no coverage)
|
sl@0
|
167 |
//
|
sl@0
|
168 |
|
sl@0
|
169 |
#ifdef _BullseyeCoverage
|
sl@0
|
170 |
#pragma suppress_warnings on
|
sl@0
|
171 |
#pragma BullseyeCoverage off
|
sl@0
|
172 |
#pragma suppress_warnings off
|
sl@0
|
173 |
#endif
|
sl@0
|
174 |
|
sl@0
|
175 |
CAsyncSigner* CAsyncSigner::NewL(MAsyncSigner* aSigner, TInt aHandle)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
CAsyncSigner* self=new(ELeave) CAsyncSigner(aSigner, aHandle);
|
sl@0
|
178 |
return self;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
CAsyncSigner::CAsyncSigner(MAsyncSigner* aSigner, TInt aHandle)
|
sl@0
|
182 |
: CSignatureBase(aSigner, aHandle)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
EXPORT_C CAsyncSigner::~CAsyncSigner()
|
sl@0
|
187 |
{
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
EXPORT_C void CAsyncSigner::SignL(const TDesC8& aInput, CCryptoParams& aSignature, TRequestStatus& aRequestStatus)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
MAsyncSigner* ptr=static_cast<MAsyncSigner*>(iPlugin);
|
sl@0
|
193 |
ptr->SignL(aInput, aSignature, aRequestStatus);
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
EXPORT_C void CAsyncSigner::Cancel()
|
sl@0
|
197 |
{
|
sl@0
|
198 |
MAsyncSigner* ptr=static_cast<MAsyncSigner*>(iPlugin);
|
sl@0
|
199 |
ptr->Cancel();
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
//
|
sl@0
|
203 |
// Implementation of Asynchronous Verifier
|
sl@0
|
204 |
//
|
sl@0
|
205 |
CAsyncVerifier* CAsyncVerifier::NewL(MAsyncVerifier* aVerifier, TInt aHandle)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
CAsyncVerifier* self=new(ELeave) CAsyncVerifier(aVerifier, aHandle);
|
sl@0
|
208 |
return self;
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
CAsyncVerifier::CAsyncVerifier(MAsyncVerifier* aVerifier, TInt aHandle)
|
sl@0
|
212 |
: CSignatureBase(aVerifier, aHandle)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
EXPORT_C CAsyncVerifier::~CAsyncVerifier()
|
sl@0
|
217 |
{
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
EXPORT_C void CAsyncVerifier::VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult, TRequestStatus& aRequestStatus)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
MAsyncVerifier* ptr=static_cast<MAsyncVerifier*>(iPlugin);
|
sl@0
|
223 |
ptr->VerifyL(aInput, aSignature, aVerificationResult, aRequestStatus);
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
EXPORT_C void CAsyncVerifier::InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature, TRequestStatus& aRequestStatus)
|
sl@0
|
227 |
{
|
sl@0
|
228 |
MAsyncVerifier* ptr=static_cast<MAsyncVerifier*>(iPlugin);
|
sl@0
|
229 |
ptr->InverseSignL(aOutput, aSignature, aRequestStatus);
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
EXPORT_C void CAsyncVerifier::Cancel()
|
sl@0
|
233 |
{
|
sl@0
|
234 |
MAsyncVerifier* ptr=static_cast<MAsyncVerifier*>(iPlugin);
|
sl@0
|
235 |
ptr->Cancel();
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
//
|
sl@0
|
239 |
// Implementation of Signer and Verifier Factory
|
sl@0
|
240 |
//
|
sl@0
|
241 |
EXPORT_C void CSignatureFactory::CreateAsyncSignerL(CAsyncSigner*& aSigner,
|
sl@0
|
242 |
TUid aAlgorithmUid,
|
sl@0
|
243 |
const CKey& aKey,
|
sl@0
|
244 |
TUid aPaddingMode,
|
sl@0
|
245 |
const CCryptoParams* aAlgorithmParams)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
|
sl@0
|
248 |
if (selector)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
selector->CreateAsyncSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
|
sl@0
|
251 |
}
|
sl@0
|
252 |
else
|
sl@0
|
253 |
{
|
sl@0
|
254 |
CLegacySelector* legacySelector=CLegacySelector::NewLC();
|
sl@0
|
255 |
legacySelector->CreateAsyncSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
|
sl@0
|
256 |
CleanupStack::PopAndDestroy(legacySelector); //selector
|
sl@0
|
257 |
}
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
EXPORT_C void CSignatureFactory::CreateAsyncVerifierL(CAsyncVerifier*& aVerifier,
|
sl@0
|
261 |
TUid aAlgorithmUid,
|
sl@0
|
262 |
const CKey& aKey,
|
sl@0
|
263 |
TUid aPaddingMode,
|
sl@0
|
264 |
const CCryptoParams* aAlgorithmParams)
|
sl@0
|
265 |
{
|
sl@0
|
266 |
MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
|
sl@0
|
267 |
if (selector)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
selector->CreateAsyncVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
|
sl@0
|
270 |
}
|
sl@0
|
271 |
else
|
sl@0
|
272 |
{
|
sl@0
|
273 |
CLegacySelector* legacySelector=CLegacySelector::NewLC();
|
sl@0
|
274 |
legacySelector->CreateAsyncVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
|
sl@0
|
275 |
CleanupStack::PopAndDestroy(legacySelector); //legacySelector
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
}
|
sl@0
|
279 |
|
sl@0
|
280 |
|