|
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 parameters interface |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @publishedAll |
|
23 @released |
|
24 */ |
|
25 |
|
26 #ifndef __CRYPTOPARAMS_H__ |
|
27 #define __CRYPTOPARAMS_H__ |
|
28 |
|
29 #include <bigint.h> |
|
30 |
|
31 namespace CryptoSpi |
|
32 { |
|
33 /** |
|
34 Abstract base class for generic crypto parameters to enable plug-in |
|
35 specific parameters and the externalisation of plug-ins. The type |
|
36 of the sub-class is identified by the GetType method. |
|
37 |
|
38 All sub-class contain copies of (instead of references to) the |
|
39 supplied values. |
|
40 */ |
|
41 NONSHARABLE_CLASS(CCryptoParam) : public CBase |
|
42 { |
|
43 public: |
|
44 |
|
45 /** |
|
46 The definition of the data type of the embedded value. |
|
47 Other data types may be added in future so applications |
|
48 should not panic if the type is not recognised. |
|
49 */ |
|
50 enum TParamType |
|
51 { |
|
52 /** |
|
53 RCryptoIntParam |
|
54 */ |
|
55 EInt = 1, |
|
56 /** |
|
57 RCryptoBigIntParam |
|
58 */ |
|
59 EBigInt = 2, |
|
60 /** |
|
61 RCryptoDesC8Param |
|
62 */ |
|
63 EDesC8 = 3, |
|
64 /** |
|
65 RCryptoDesC16Param |
|
66 */ |
|
67 EDesC16 = 4, |
|
68 }; |
|
69 |
|
70 /** |
|
71 Returns the data type of the crypto parameter |
|
72 @return The data type of the crypto parameter |
|
73 */ |
|
74 IMPORT_C TInt Type() const; |
|
75 |
|
76 /** |
|
77 Returns the Uid of the crypto parameter |
|
78 @return The Uid of the crypto parameter |
|
79 */ |
|
80 IMPORT_C TUid Uid() const; |
|
81 |
|
82 /** |
|
83 Destructor |
|
84 */ |
|
85 IMPORT_C ~CCryptoParam(); |
|
86 |
|
87 protected: |
|
88 /** |
|
89 * @internalComponent |
|
90 * |
|
91 * Constructor |
|
92 * @param aType The data type identifier for the sub-class. |
|
93 * @param aUid The Uid of the cryptoparam |
|
94 */ |
|
95 CCryptoParam(TParamType aType, TUid aUid); |
|
96 |
|
97 protected: |
|
98 /** |
|
99 The data type of the embedded value |
|
100 */ |
|
101 TParamType iType; |
|
102 |
|
103 /** |
|
104 The Uid of the crypto parameter |
|
105 */ |
|
106 TUid iUid; |
|
107 }; |
|
108 |
|
109 /** |
|
110 CryptoParam class that wraps a TInt |
|
111 */ |
|
112 NONSHARABLE_CLASS(CCryptoIntParam) : public CCryptoParam |
|
113 { |
|
114 public: |
|
115 /** |
|
116 Factory method for allocating a new CCryptoIntParam object |
|
117 that contains a copy of the supplied TInt |
|
118 @param aValue The TInt to be wrapped (copied) |
|
119 @param aUid The UID of the CryptoParam |
|
120 @return A pointer to a CCryptoIntParam instance |
|
121 */ |
|
122 IMPORT_C static CCryptoIntParam* NewL(TInt aValue, TUid aUid); |
|
123 |
|
124 /** |
|
125 Factory method for allocating a new CCryptoIntParam object |
|
126 that contains a copy of the supplied TInt |
|
127 Leaves the pointer of the CryptoParam on the cleanup stack |
|
128 @param aValue The TInt to be wrapped (copied) |
|
129 @param aUid The UID of the CryptoParam |
|
130 @return A pointer to a CCryptoIntParam instance |
|
131 */ |
|
132 IMPORT_C static CCryptoIntParam* NewLC(TInt aValue, TUid aUid); |
|
133 |
|
134 /** |
|
135 Returns the embedded value. |
|
136 @return The embedded integer |
|
137 */ |
|
138 IMPORT_C TInt Value() const; |
|
139 |
|
140 /** |
|
141 Destructor |
|
142 */ |
|
143 IMPORT_C ~CCryptoIntParam(); |
|
144 |
|
145 private: |
|
146 /** |
|
147 Constructor |
|
148 @param aValue The integer to wrap |
|
149 @param aUid The UID of the crypto parameter |
|
150 */ |
|
151 CCryptoIntParam(TInt aValue, TUid aUid); |
|
152 |
|
153 private: |
|
154 /** |
|
155 The embedded value |
|
156 */ |
|
157 TInt iValue; |
|
158 }; |
|
159 |
|
160 /** |
|
161 Crypto param class the wraps an RInteger |
|
162 */ |
|
163 NONSHARABLE_CLASS(CCryptoBigIntParam) : public CCryptoParam |
|
164 { |
|
165 public: |
|
166 /** |
|
167 Factory method for allocating a new CCryptoBigIntParam object |
|
168 that contains a copy of the supplied TInteger object. |
|
169 @param aValue The TInteger to be wrapped (copied) |
|
170 @param aUid The UID of the CryptoParam |
|
171 @return A pointer to a CCryptoBigIntParam instance |
|
172 */ |
|
173 IMPORT_C static CCryptoBigIntParam* NewL(const TInteger& aValue, TUid aUid); |
|
174 |
|
175 /** |
|
176 Factory method for allocating a new CCryptoBigIntParam object |
|
177 that contains a copy of the supplied TInteger object. |
|
178 Leaves the pointer of the CryptoParam onto the cleanup stack. |
|
179 @param aValue The TInteger to be wrapped (copied) |
|
180 @param aUid The UID of the CryptoParam |
|
181 @return A pointer to a CCryptoBigIntParam instance |
|
182 */ |
|
183 IMPORT_C static CCryptoBigIntParam* NewLC(const TInteger& aValue, TUid aUid); |
|
184 |
|
185 /** |
|
186 Returns the embedded value. |
|
187 @return A reference to the embedded TInteger |
|
188 */ |
|
189 IMPORT_C const TInteger& Value() const; |
|
190 |
|
191 /** |
|
192 Destructor |
|
193 */ |
|
194 IMPORT_C ~CCryptoBigIntParam(); |
|
195 |
|
196 private: |
|
197 /** |
|
198 Constructor |
|
199 */ |
|
200 CCryptoBigIntParam(); |
|
201 |
|
202 /** |
|
203 Constructor |
|
204 @param aUid The UID of the crypto parameter |
|
205 */ |
|
206 CCryptoBigIntParam(TUid aUid); |
|
207 |
|
208 /** |
|
209 Second Phase Constructor |
|
210 @param aValue The TInteger to wrap |
|
211 */ |
|
212 void ConstructL(const TInteger& aValue); |
|
213 |
|
214 private: |
|
215 /** |
|
216 The copied RInteger |
|
217 */ |
|
218 RInteger iValue; |
|
219 }; |
|
220 |
|
221 /** |
|
222 Crypto param class that wraps an 8-bit constant descriptor |
|
223 */ |
|
224 NONSHARABLE_CLASS(CCryptoDesC8Param) : public CCryptoParam |
|
225 { |
|
226 public: |
|
227 /** |
|
228 Factory method for allocating a new CCryptoDesC8Param object |
|
229 that contains a copy of the supplied RInteger object. |
|
230 @param aValue The TDesC* to be wrapped (copied) |
|
231 @param aUid The Uid of the CryptoParam |
|
232 @return A pointer to a CCryptoDesC8Param instance |
|
233 */ |
|
234 IMPORT_C static CCryptoDesC8Param* NewL(const TDesC8& aValue, TUid aUid); |
|
235 |
|
236 /** |
|
237 Factory method for allocating a new CCryptoDesC8Param object |
|
238 that contains a copy of the supplied RInteger object. |
|
239 Leaves the pointer of the CryptoParam on the cleanup stack |
|
240 @param aValue The TDesC* to be wrapped (copied) |
|
241 @param aUid The Uid of the CryptoParam |
|
242 @return A pointer to a CCryptoDesC8Param instance |
|
243 */ |
|
244 IMPORT_C static CCryptoDesC8Param* NewLC(const TDesC8& aValue, TUid aUid); |
|
245 |
|
246 /** |
|
247 Returns the embedded value. |
|
248 @return A reference to the embedded TDesC8 |
|
249 */ |
|
250 IMPORT_C const TDesC8& Value() const; |
|
251 |
|
252 /** |
|
253 Destructor |
|
254 */ |
|
255 IMPORT_C ~CCryptoDesC8Param(); |
|
256 |
|
257 private: |
|
258 /** |
|
259 Constructor |
|
260 */ |
|
261 CCryptoDesC8Param(); |
|
262 |
|
263 /** |
|
264 Constructor |
|
265 @param aUid The UID of the crypto parameter |
|
266 */ |
|
267 CCryptoDesC8Param(TUid aUid); |
|
268 |
|
269 /** |
|
270 Second Phase Constructor |
|
271 @param aValue The DesC8 to wrap |
|
272 */ |
|
273 void ConstructL(const TDesC8& aValue); |
|
274 |
|
275 private: |
|
276 /** |
|
277 The copied descriptor |
|
278 */ |
|
279 HBufC8* iValue; |
|
280 }; |
|
281 |
|
282 /** |
|
283 Crypto param class that wraps an 16-bit constant descriptor |
|
284 */ |
|
285 NONSHARABLE_CLASS(CCryptoDesC16Param) : public CCryptoParam |
|
286 { |
|
287 public: |
|
288 /** |
|
289 Factory method for allocating a new CCryptoDesC8Param object |
|
290 that contains a copy of the supplied RInteger object. |
|
291 @param aValue The TDesC* to be wrapped (copied) |
|
292 @param aUid The Uid of the CryptoParam |
|
293 @return A pointer to a CCryptoDesC8Param instance |
|
294 */ |
|
295 IMPORT_C static CCryptoDesC16Param* NewL(const TDesC16& aValue, TUid aUid); |
|
296 |
|
297 /** |
|
298 Factory method for allocating a new CCryptoDesC16Param object |
|
299 that contains a copy of the supplied RInteger object. |
|
300 Leaves the pointer of the CryptoParam on the cleanup stack |
|
301 @param aValue The TDesC* to be wrapped (copied) |
|
302 @param aUid The Uid of the CryptoParam |
|
303 @return A pointer to a CCryptoDesC16Param instance |
|
304 */ |
|
305 IMPORT_C static CCryptoDesC16Param* NewLC(const TDesC16& aValue, TUid aUid); |
|
306 |
|
307 /** |
|
308 Returns the embedded value. |
|
309 @return A reference to the embedded TDesC16 |
|
310 */ |
|
311 IMPORT_C const TDesC16& Value() const; |
|
312 |
|
313 /** |
|
314 Destructor |
|
315 */ |
|
316 IMPORT_C ~CCryptoDesC16Param(); |
|
317 |
|
318 private: |
|
319 /** |
|
320 Constructor |
|
321 */ |
|
322 CCryptoDesC16Param(); |
|
323 |
|
324 /** |
|
325 Constructor |
|
326 @param aUid The UID of the crypto parameter |
|
327 */ |
|
328 CCryptoDesC16Param(TUid aUid); |
|
329 |
|
330 /** |
|
331 Second Phase Constructor |
|
332 @param aValue The DesC16 to wrap |
|
333 */ |
|
334 void ConstructL(const TDesC16& aValue); |
|
335 |
|
336 private: |
|
337 /** |
|
338 The copied descriptor |
|
339 */ |
|
340 HBufC16* iValue; |
|
341 }; |
|
342 |
|
343 NONSHARABLE_CLASS(CCryptoParams) : public CBase |
|
344 { |
|
345 public: |
|
346 IMPORT_C static CCryptoParams* NewL(void); |
|
347 IMPORT_C static CCryptoParams* NewLC(void); |
|
348 |
|
349 /** |
|
350 * Various adding methods (CCryptoParams takes a copy) |
|
351 */ |
|
352 IMPORT_C void AddL(const TInteger& aParam, TUid aUid); |
|
353 IMPORT_C void AddL(const TInt aParam, TUid aUid); |
|
354 IMPORT_C void AddL(const TDesC8& aParam, TUid aUid); |
|
355 IMPORT_C void AddL(const TDesC16& aParam, TUid aUid); |
|
356 |
|
357 /** |
|
358 * Various retrieving methods |
|
359 */ |
|
360 IMPORT_C const TInteger& GetBigIntL(TUid aUid) const; |
|
361 IMPORT_C TInt GetTIntL(TUid aUid) const; |
|
362 IMPORT_C const TDesC8& GetTDesC8L(TUid aUid) const; |
|
363 IMPORT_C const TDesC16& GetTDesC16L(TUid aUid) const; |
|
364 IMPORT_C const RPointerArray<CCryptoParam>& GetParams() const; |
|
365 |
|
366 /// Queries if a parameter with the specified uid is present |
|
367 IMPORT_C TBool IsPresent(TUid aUid) const; |
|
368 |
|
369 /// Return the count of parameters present |
|
370 IMPORT_C TInt Count(void) const; |
|
371 |
|
372 /// Copy the passed CCryptoParams |
|
373 IMPORT_C CCryptoParams& CopyL(const CCryptoParams& aParams); |
|
374 |
|
375 /// Destructor |
|
376 IMPORT_C virtual ~CCryptoParams(); |
|
377 |
|
378 protected: |
|
379 /** @internalComponent */ |
|
380 CCryptoParams(); |
|
381 |
|
382 /** @internalComponent */ |
|
383 void ConstructL(void); |
|
384 /** @internalComponent */ |
|
385 CCryptoParam* GetCryptoParam(TUid aUid) const; |
|
386 /** @internalComponent */ |
|
387 CCryptoParam* GetCryptoParamL(TUid aUid) const; |
|
388 |
|
389 private: |
|
390 RPointerArray<CCryptoParam> iParams; |
|
391 }; |
|
392 } //End of namespace |
|
393 |
|
394 #endif // __CRYPTOPARAMS_H__ |
|
395 |