|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 * crypto asymmetric cipher API implementation |
|
16 * crypto asymmetric cipher API implementation |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 |
|
25 #include "cryptoasymmetriccipherapi.h" |
|
26 #include "asymmetriccipherplugin.h" |
|
27 #include "legacyselector.h" |
|
28 |
|
29 using namespace CryptoSpi; |
|
30 |
|
31 |
|
32 // |
|
33 // Implementation of Asymmetric Cipher base class |
|
34 // |
|
35 CAsymmetricCipherBase::CAsymmetricCipherBase(MAsymmetricCipherBase* aAsymmetricCipher, TInt aHandle) |
|
36 : CCryptoBase(aAsymmetricCipher, aHandle) |
|
37 { |
|
38 } |
|
39 |
|
40 CAsymmetricCipherBase::~CAsymmetricCipherBase() |
|
41 { |
|
42 } |
|
43 |
|
44 EXPORT_C void CAsymmetricCipherBase::SetKeyL(const CKey& aKey) |
|
45 { |
|
46 MAsymmetricCipherBase* ptr=static_cast<MAsymmetricCipherBase*>(iPlugin); |
|
47 ptr->SetKeyL(aKey); |
|
48 } |
|
49 |
|
50 EXPORT_C void CAsymmetricCipherBase::SetCryptoModeL(TUid aCryptoMode) |
|
51 { |
|
52 MAsymmetricCipherBase* ptr=static_cast<MAsymmetricCipherBase*>(iPlugin); |
|
53 ptr->SetCryptoModeL(aCryptoMode); |
|
54 } |
|
55 |
|
56 EXPORT_C void CAsymmetricCipherBase::SetPaddingModeL(TUid aPaddingMode) |
|
57 { |
|
58 MAsymmetricCipherBase* ptr=static_cast<MAsymmetricCipherBase*>(iPlugin); |
|
59 ptr->SetPaddingModeL(aPaddingMode); |
|
60 } |
|
61 |
|
62 EXPORT_C TInt CAsymmetricCipherBase::GetMaximumInputLengthL() |
|
63 { |
|
64 MAsymmetricCipherBase* ptr=static_cast<MAsymmetricCipherBase*>(iPlugin); |
|
65 return ptr->GetMaximumInputLengthL(); |
|
66 } |
|
67 |
|
68 EXPORT_C TInt CAsymmetricCipherBase::GetMaximumOutputLengthL() |
|
69 { |
|
70 MAsymmetricCipherBase* ptr=static_cast<MAsymmetricCipherBase*>(iPlugin); |
|
71 return ptr->GetMaximumOutputLengthL(); |
|
72 } |
|
73 |
|
74 |
|
75 // |
|
76 // Implementation of Synchronous Asymmetric Cipher |
|
77 // |
|
78 CAsymmetricCipher* CAsymmetricCipher::NewL(MAsymmetricCipher* aAsymmetricCipher, TInt aHandle) |
|
79 { |
|
80 CAsymmetricCipher* self=new(ELeave) CAsymmetricCipher(aAsymmetricCipher, aHandle); |
|
81 return self; |
|
82 } |
|
83 |
|
84 CAsymmetricCipher::CAsymmetricCipher(MAsymmetricCipher* aAsymmetricCipher, TInt aHandle) |
|
85 : CAsymmetricCipherBase(aAsymmetricCipher, aHandle) |
|
86 { |
|
87 } |
|
88 |
|
89 EXPORT_C CAsymmetricCipher::~CAsymmetricCipher() |
|
90 { |
|
91 } |
|
92 |
|
93 EXPORT_C void CAsymmetricCipher::ProcessL(const TDesC8& aInput, TDes8& aOutput) |
|
94 { |
|
95 MAsymmetricCipher* ptr=static_cast<MAsymmetricCipher*>(iPlugin); |
|
96 ptr->ProcessL(aInput, aOutput); |
|
97 } |
|
98 |
|
99 // |
|
100 // Implementation of Asymmetric Cipher Factory |
|
101 // |
|
102 EXPORT_C void CAsymmetricCipherFactory::CreateAsymmetricCipherL(CAsymmetricCipher*& aCipher, |
|
103 TUid aAlgorithmUid, |
|
104 const CKey& aKey, |
|
105 TUid aCryptoMode, |
|
106 TUid aPaddingMode, |
|
107 const CCryptoParams* aAlgorithmParams) |
|
108 |
|
109 { |
|
110 MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls()); |
|
111 if (selector) |
|
112 { |
|
113 selector->CreateAsymmetricCipherL(aCipher, aAlgorithmUid, aKey, aCryptoMode, aPaddingMode, aAlgorithmParams); |
|
114 } |
|
115 else |
|
116 { |
|
117 CLegacySelector* legacySelector=CLegacySelector::NewLC(); |
|
118 legacySelector->CreateAsymmetricCipherL(aCipher, aAlgorithmUid, aKey, aCryptoMode, aPaddingMode, aAlgorithmParams); |
|
119 CleanupStack::PopAndDestroy(legacySelector); //legacySelector |
|
120 } |
|
121 } |
|
122 |
|
123 |
|
124 // |
|
125 // Implementation of Asynchronous Asymmetric Cipher |
|
126 // (async methods not implemented, so no coverage) |
|
127 // |
|
128 |
|
129 #ifdef _BullseyeCoverage |
|
130 #pragma suppress_warnings on |
|
131 #pragma BullseyeCoverage off |
|
132 #pragma suppress_warnings off |
|
133 #endif |
|
134 |
|
135 CAsyncAsymmetricCipher* CAsyncAsymmetricCipher::NewL(MAsyncAsymmetricCipher* aAsyncAsymmetricCipher, TInt aHandle) |
|
136 { |
|
137 CAsyncAsymmetricCipher* self=new(ELeave) CAsyncAsymmetricCipher(aAsyncAsymmetricCipher, aHandle); |
|
138 return self; |
|
139 } |
|
140 |
|
141 CAsyncAsymmetricCipher::CAsyncAsymmetricCipher(MAsyncAsymmetricCipher* aAsyncAsymmetricCipher, TInt aHandle) |
|
142 :CAsymmetricCipherBase(aAsyncAsymmetricCipher, aHandle) |
|
143 { |
|
144 |
|
145 } |
|
146 |
|
147 EXPORT_C CAsyncAsymmetricCipher::~CAsyncAsymmetricCipher() |
|
148 { |
|
149 |
|
150 } |
|
151 |
|
152 EXPORT_C void CAsyncAsymmetricCipher::ProcessL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus) |
|
153 { |
|
154 MAsyncAsymmetricCipher* ptr=static_cast<MAsyncAsymmetricCipher*>(iPlugin); |
|
155 ptr->ProcessL(aInput, aOutput, aRequestStatus); |
|
156 } |
|
157 |
|
158 EXPORT_C void CAsyncAsymmetricCipher::Cancel() |
|
159 { |
|
160 MAsyncAsymmetricCipher* ptr=static_cast<MAsyncAsymmetricCipher*>(iPlugin); |
|
161 ptr->Cancel(); |
|
162 } |
|
163 |
|
164 EXPORT_C void CAsymmetricCipherFactory::CreateAsyncAsymmetricCipherL(CAsyncAsymmetricCipher*& aCipher, |
|
165 TUid aAlgorithmUid, |
|
166 const CKey& aKey, |
|
167 TUid aCryptoMode, |
|
168 TUid aPaddingMode, |
|
169 const CCryptoParams* aAlgorithmParams) |
|
170 { |
|
171 MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls()); |
|
172 if (selector) |
|
173 { |
|
174 selector->CreateAsyncAsymmetricCipherL(aCipher, aAlgorithmUid, aKey, aCryptoMode, aPaddingMode, aAlgorithmParams); |
|
175 } |
|
176 else |
|
177 { |
|
178 CLegacySelector* legacySelector=CLegacySelector::NewLC(); |
|
179 legacySelector->CreateAsyncAsymmetricCipherL(aCipher, aAlgorithmUid, aKey, aCryptoMode, aPaddingMode, aAlgorithmParams); |
|
180 CleanupStack::PopAndDestroy(legacySelector); //legacySelector |
|
181 } |
|
182 } |
|
183 |