|
1 /* |
|
2 * Copyright (c) 2001-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 * Declares all classes used to decode ASN.1 data, including the |
|
16 * base interface. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 @publishedAll |
|
26 @released |
|
27 */ |
|
28 |
|
29 #ifndef __ASN1ENC_H__ |
|
30 #define __ASN1ENC_H__ |
|
31 |
|
32 #include <e32base.h> |
|
33 #include <asn1cons.h> |
|
34 |
|
35 class CASN1EncBase; |
|
36 class TASN1EncBase128DER; |
|
37 |
|
38 class TInteger; |
|
39 |
|
40 typedef void (CASN1EncBase::* WriteFunc)(TDes8& aBuf) const; |
|
41 |
|
42 /** |
|
43 * Base class for all ASN.1 types that we can encode. |
|
44 * |
|
45 * @publishedAll |
|
46 * @released |
|
47 */ |
|
48 class CASN1EncBase : public CBase |
|
49 { |
|
50 public: |
|
51 /** |
|
52 * Gives total number of octets in the DER encoding of this |
|
53 * object. |
|
54 * @return Number of octets in DER encoding of this object. |
|
55 */ |
|
56 IMPORT_C TUint LengthDER() const; |
|
57 |
|
58 /** |
|
59 * Writes entire DER encoding of this object into the given |
|
60 * buffer. |
|
61 * @param aBuf Buffer receiving the encoding. |
|
62 * @param aPos Position to start writing at. |
|
63 */ |
|
64 IMPORT_C void WriteDERL(TDes8& aBuf, TUint& aPos) const; |
|
65 |
|
66 /** |
|
67 * Sets tag type/class of the encoding object |
|
68 * @param aType Tag type to set |
|
69 * @param aClass Tag class to set. |
|
70 */ |
|
71 IMPORT_C void SetTag(const TTagType aType, |
|
72 const TASN1Class aClass = EContextSpecific); |
|
73 |
|
74 IMPORT_C ~CASN1EncBase(); |
|
75 |
|
76 /** |
|
77 * @internalComponent |
|
78 * |
|
79 * Sets parent for the object |
|
80 * @param aParent Pointer to an ASN.1 object that becomes this |
|
81 * object's parent. |
|
82 */ |
|
83 void SetParent(CASN1EncBase* aParent); |
|
84 |
|
85 protected: |
|
86 /** |
|
87 * Protected constructor |
|
88 * @param aType Tag type of the new object |
|
89 * @param aClass Tag class of the new object. |
|
90 */ |
|
91 IMPORT_C CASN1EncBase(const TTagType aType, const TASN1Class aClass); |
|
92 |
|
93 /** |
|
94 * Must call this version from derived classes in their |
|
95 * ConstructL, but only once they're ready to have |
|
96 * CalculateContentsLengthDER called on them. |
|
97 */ |
|
98 IMPORT_C virtual void ConstructL(); |
|
99 |
|
100 /** |
|
101 * @internalComponent |
|
102 * |
|
103 * Derived classes must call this if the length of their |
|
104 * contents changes after construction. |
|
105 */ |
|
106 void ContentsLengthChanged(); |
|
107 |
|
108 protected: |
|
109 /** |
|
110 * @internalComponent |
|
111 * |
|
112 * Calculates number of octets in DER length encoding. Must set |
|
113 * value of the appropriate data member. Made protected because it is |
|
114 * needed by CASN1EncEncoding class. |
|
115 */ |
|
116 void CalculateLengthLengthDER(); |
|
117 |
|
118 private: |
|
119 /** |
|
120 * Calculates number of octets in DER tag encoding. Must set |
|
121 * value of the appropriate data member. |
|
122 */ |
|
123 void CalculateTagLengthDER(); |
|
124 |
|
125 /** |
|
126 * Calculates number of octets in DER content encoding. Must set |
|
127 * value of the appropriate data member. |
|
128 */ |
|
129 virtual void CalculateContentsLengthDER() = 0; |
|
130 |
|
131 virtual TBool IsConstructed() const = 0; |
|
132 |
|
133 // Write the octet data in each section |
|
134 // Note that buffer *will* be big enough: these are called only |
|
135 // after checking. |
|
136 |
|
137 /** |
|
138 * Writes DER tag encoding into supplied buffer, which is |
|
139 * already verified to be big enough. |
|
140 * @param aBuf Buffer to write to. |
|
141 */ |
|
142 void WriteTagDERL(TDes8& aBuf) const; |
|
143 |
|
144 /** |
|
145 * Writes DER length encoding into supplied buffer, which is |
|
146 * already verified to be big enough. |
|
147 * @param aBuf Buffer to write to. |
|
148 */ |
|
149 virtual void WriteLengthDER(TDes8& aBuf) const; |
|
150 |
|
151 /** |
|
152 * Writes DER content encoding into supplied buffer, which is |
|
153 * already verified to be big enough. Must be implemented by |
|
154 * derived classes. |
|
155 * @param aBuf Buffer to write to. |
|
156 */ |
|
157 virtual void WriteContentsDERL(TDes8& aBuf) const = 0; |
|
158 |
|
159 /** |
|
160 * Helper function, used for efficiency |
|
161 * @param aBuf Buffer to write to |
|
162 * @param aPos Position in the buffer to start writing at |
|
163 * (updated on exit) |
|
164 * @param aLength Length of data to write |
|
165 * @param aWriteFunc Points to the function used to perform |
|
166 * the actual write operation. |
|
167 */ |
|
168 void WriteHelperL(TDes8& aBuf, TUint& aPos, const TUint aLength, |
|
169 WriteFunc aWriteFunc) const; |
|
170 |
|
171 protected: |
|
172 // Cached length data - data set from the CalculateXxxx methods above |
|
173 TUint iTagLengthDER; ///< Length of DER encoded tag |
|
174 TUint iLengthLengthDER; ///< Length of DER encoded length |
|
175 TUint iContentsLengthDER; ///< Length of DER encoded content |
|
176 |
|
177 private: |
|
178 /** |
|
179 * The object owning this one (if we're held in a sequence, |
|
180 * for example). |
|
181 */ |
|
182 CASN1EncBase* iParent; |
|
183 |
|
184 // Tag data |
|
185 TTagType iType; ///< Tag type of this object |
|
186 TASN1Class iClass; ///< Tag class of this object |
|
187 }; |
|
188 |
|
189 |
|
190 /** |
|
191 * Base class for all ASN1 constructed-type objects. Most of these |
|
192 * are container classes, but another type is the explicit-tagging |
|
193 * wrapper object. |
|
194 * |
|
195 * @publishedAll |
|
196 * @released |
|
197 */ |
|
198 class CASN1EncConstructed : public CASN1EncBase |
|
199 { |
|
200 protected: |
|
201 /** |
|
202 * @internalComponent |
|
203 * |
|
204 * Protected constructor |
|
205 * @param aType Tag type for the new object |
|
206 * @param aClass Tag class for the new object. |
|
207 */ |
|
208 CASN1EncConstructed(const TTagType aType, const TASN1Class aClass); |
|
209 |
|
210 private: |
|
211 virtual const CASN1EncBase& Child(const TUint aIndex) const = 0; |
|
212 virtual TUint NumChildren() const = 0; |
|
213 |
|
214 private: |
|
215 // From CASN1EncBase |
|
216 void CalculateContentsLengthDER(); |
|
217 TBool IsConstructed() const; |
|
218 void WriteContentsDERL(TDes8& aBuf) const; |
|
219 }; |
|
220 |
|
221 |
|
222 /** |
|
223 * Class used to wrap other encoding objects in order to give |
|
224 * them an explicit tag. |
|
225 * |
|
226 * @publishedAll |
|
227 * @released |
|
228 */ |
|
229 class CASN1EncExplicitTag : public CASN1EncConstructed |
|
230 { |
|
231 public: |
|
232 /** |
|
233 * Takes ownership of the encoder, *including* the case when |
|
234 * this method leaves. |
|
235 * @param aEncoder ASN.1 encoding object to wrap |
|
236 * @param aType Tag type to assign |
|
237 * @param aClass Tag class to assign |
|
238 * @return Wrapped encoding object pushed on the cleanup stack. |
|
239 */ |
|
240 IMPORT_C static CASN1EncExplicitTag* NewLC(CASN1EncBase* aEncoder, |
|
241 const TTagType aType, const TASN1Class aClass = EContextSpecific); |
|
242 |
|
243 /** |
|
244 * Takes ownership of the encoder, *including* the case when |
|
245 * this method leaves. |
|
246 * @param aEncoder ASN.1 encoding object to wrap |
|
247 * @param aType Tag type to assign |
|
248 * @param aClass Tag class to assign |
|
249 * @return Wrapped encoding object. |
|
250 */ |
|
251 IMPORT_C static CASN1EncExplicitTag* NewL(CASN1EncBase* aEncoder, |
|
252 const TTagType aType, const TASN1Class aClass = EContextSpecific); |
|
253 |
|
254 IMPORT_C ~CASN1EncExplicitTag(); // virtual from base |
|
255 |
|
256 private: |
|
257 CASN1EncExplicitTag(CASN1EncBase* aEncoder, const TTagType aType, |
|
258 const TASN1Class aClass); |
|
259 |
|
260 // From CASN1EncConstructed |
|
261 TUint NumChildren() const; |
|
262 const CASN1EncBase& Child(const TUint aIndex) const; |
|
263 |
|
264 private: |
|
265 CASN1EncBase* iEncoder; // Inner encoding object |
|
266 }; |
|
267 |
|
268 |
|
269 /** |
|
270 * Base class for all ASN1 container types - sequences, |
|
271 * sets, etc. |
|
272 * |
|
273 * @publishedAll |
|
274 * @released |
|
275 */ |
|
276 class CASN1EncContainer : public CASN1EncConstructed |
|
277 { |
|
278 public: |
|
279 /** |
|
280 * Call this to add a child object to the container. |
|
281 * Takes ownership if and only if it doesn't Leave. |
|
282 * Checks for null input, calls AddChildInt, calls |
|
283 * ContentsLengthChanged(). |
|
284 * @param aChild Child ASN1 encoding object to add. |
|
285 */ |
|
286 IMPORT_C void AddChildL(CASN1EncBase* aChild); |
|
287 |
|
288 /** |
|
289 * Call this to add a child object to the container. |
|
290 * Takes ownership if and only if it doesn't Leave. |
|
291 * Checks for null input, calls AddChildInt, calls |
|
292 * ContentsLengthChanged(). Pops added child object |
|
293 * off the cleanup stack. |
|
294 * @param aChild Child ASN1 encoding object to add. |
|
295 */ |
|
296 IMPORT_C void AddAndPopChildL(CASN1EncBase* aChild); |
|
297 |
|
298 protected: |
|
299 /** @internalComponent */ |
|
300 CASN1EncContainer(const TTagType aType); |
|
301 |
|
302 private: |
|
303 /** |
|
304 * Internal method, derived classes implement to add a child. |
|
305 * No need to check for null input or call |
|
306 * ContentsLengthChanged(). Takes ownership, but only if you |
|
307 * don't leave. |
|
308 * @param aChild Child encoding object to add. |
|
309 */ |
|
310 virtual void AddChildIntL(const CASN1EncBase* aChild) = 0; |
|
311 }; |
|
312 |
|
313 /** |
|
314 * Class for encoding SEQUENCE and SEQUENCE-OF data types. |
|
315 * |
|
316 * @publishedAll |
|
317 * @released |
|
318 */ |
|
319 class CASN1EncSequence : public CASN1EncContainer |
|
320 { |
|
321 public: |
|
322 IMPORT_C static CASN1EncSequence* NewL(); |
|
323 IMPORT_C static CASN1EncSequence* NewLC(); |
|
324 |
|
325 IMPORT_C ~CASN1EncSequence(); // virtual from base |
|
326 |
|
327 protected: |
|
328 /** @internalComponent */ |
|
329 CASN1EncSequence(); |
|
330 |
|
331 private: |
|
332 // From CASN1EncContainer |
|
333 const CASN1EncBase& Child(const TUint aIndex) const; |
|
334 void AddChildIntL(const CASN1EncBase* aChild); |
|
335 TUint NumChildren() const; |
|
336 |
|
337 private: |
|
338 RPointerArray<CASN1EncBase> iChildren; |
|
339 }; |
|
340 |
|
341 /** |
|
342 * Class for encoding SET and SET-OF data types. |
|
343 * |
|
344 * @publishedAll |
|
345 * @released |
|
346 */ |
|
347 class CASN1EncSet : public CASN1EncContainer |
|
348 { |
|
349 public: |
|
350 /** |
|
351 Creates an ASN.1 Set encoder. |
|
352 @return The fully constructed object. |
|
353 */ |
|
354 IMPORT_C static CASN1EncSet* NewL(); |
|
355 |
|
356 /** |
|
357 Creates an ASN.1 Set encoder, and puts it onto the cleanup stack. |
|
358 @return The fully constructed object. |
|
359 */ |
|
360 IMPORT_C static CASN1EncSet* NewLC(); |
|
361 |
|
362 /** |
|
363 Destructor. |
|
364 */ |
|
365 IMPORT_C ~CASN1EncSet(); // virtual from base |
|
366 |
|
367 protected: |
|
368 /** |
|
369 * @internalComponent |
|
370 * |
|
371 * Constructor |
|
372 */ |
|
373 CASN1EncSet(); |
|
374 |
|
375 private: |
|
376 // From CASN1EncContainer |
|
377 const CASN1EncBase& Child(const TUint aIndex) const; |
|
378 void AddChildIntL(const CASN1EncBase* aChild); |
|
379 TUint NumChildren() const; |
|
380 |
|
381 private: |
|
382 RPointerArray<CASN1EncBase> iChildren; |
|
383 }; |
|
384 |
|
385 |
|
386 |
|
387 /** |
|
388 * All ASN1 primitive type encoding classes derive from here. |
|
389 * |
|
390 * @publishedAll |
|
391 * @released |
|
392 */ |
|
393 class CASN1EncPrimitive : public CASN1EncBase |
|
394 { |
|
395 protected: |
|
396 IMPORT_C CASN1EncPrimitive(const TTagType aType); |
|
397 |
|
398 private: |
|
399 TBool IsConstructed() const; ///< Inherited from CASN1EncBase |
|
400 }; |
|
401 |
|
402 |
|
403 /** |
|
404 * Class for encoding NULLs. |
|
405 * |
|
406 * @publishedAll |
|
407 * @released |
|
408 */ |
|
409 class CASN1EncNull : public CASN1EncPrimitive |
|
410 { |
|
411 public: |
|
412 IMPORT_C static CASN1EncNull* NewL(); |
|
413 IMPORT_C static CASN1EncNull* NewLC(); |
|
414 |
|
415 private: |
|
416 CASN1EncNull(); |
|
417 |
|
418 // Methods from CASN1EncBase |
|
419 void CalculateContentsLengthDER() ; |
|
420 void WriteContentsDERL(TDes8& aBuf) const; |
|
421 }; |
|
422 |
|
423 |
|
424 /** |
|
425 * Class for encoding Boolean values. |
|
426 * |
|
427 * @publishedAll |
|
428 * @released |
|
429 */ |
|
430 class CASN1EncBoolean : public CASN1EncPrimitive |
|
431 { |
|
432 public: |
|
433 IMPORT_C static CASN1EncBoolean* NewLC(const TBool aBool); |
|
434 IMPORT_C static CASN1EncBoolean* NewL(const TBool aBool); |
|
435 |
|
436 private: |
|
437 CASN1EncBoolean(const TBool aBool); |
|
438 |
|
439 // Methods from CASN1EncBase |
|
440 void CalculateContentsLengthDER() ; |
|
441 void WriteContentsDERL(TDes8& aBuf) const; |
|
442 |
|
443 const TBool iBool; |
|
444 }; |
|
445 |
|
446 |
|
447 /** |
|
448 * Class for encoding TInts only. Use CASN1EncBigInt for encoding |
|
449 * Big Integer objects. |
|
450 * |
|
451 * @publishedAll |
|
452 * @released |
|
453 */ |
|
454 class CASN1EncInt : public CASN1EncPrimitive |
|
455 { |
|
456 public: |
|
457 IMPORT_C static CASN1EncInt* NewLC(const TInt aInt); |
|
458 IMPORT_C static CASN1EncInt* NewL(const TInt aInt); |
|
459 |
|
460 private: |
|
461 CASN1EncInt(const TInt aInt); |
|
462 |
|
463 // Methods from CASN1EncBase |
|
464 void CalculateContentsLengthDER() ; |
|
465 void WriteContentsDERL(TDes8& aBuf) const; |
|
466 |
|
467 private: |
|
468 const TInt iInt; |
|
469 }; |
|
470 |
|
471 |
|
472 /** |
|
473 * Class for encoding Big Integer objects only - use CASN1EncInt |
|
474 * for TInts. |
|
475 * |
|
476 * @publishedAll |
|
477 * @released |
|
478 */ |
|
479 class CASN1EncBigInt : public CASN1EncPrimitive |
|
480 { |
|
481 public: |
|
482 // Takes a deep copy |
|
483 IMPORT_C static CASN1EncBigInt* NewLC(const TInteger& aInteger); |
|
484 IMPORT_C static CASN1EncBigInt* NewL(const TInteger& aInteger); |
|
485 |
|
486 IMPORT_C ~CASN1EncBigInt(); // virtual from base |
|
487 |
|
488 private: |
|
489 CASN1EncBigInt(); |
|
490 void ConstructL(const TInteger& aInteger); |
|
491 |
|
492 // Methods from CASN1EncBase |
|
493 void CalculateContentsLengthDER(); |
|
494 void WriteContentsDERL(TDes8& aBuf) const; |
|
495 |
|
496 private: |
|
497 HBufC8* iContents; |
|
498 TPtrC8 iWriteContents; |
|
499 }; |
|
500 |
|
501 |
|
502 /** |
|
503 * Class for encoding octet strings. |
|
504 * |
|
505 * @publishedAll |
|
506 * @released |
|
507 */ |
|
508 class CASN1EncOctetString : public CASN1EncPrimitive |
|
509 { |
|
510 public: |
|
511 // Takes a deep copy |
|
512 IMPORT_C static CASN1EncOctetString* NewLC(const TDesC8& aStr); |
|
513 IMPORT_C static CASN1EncOctetString* NewL(const TDesC8& aStr); |
|
514 |
|
515 IMPORT_C ~CASN1EncOctetString(); // virtual from base |
|
516 |
|
517 private: |
|
518 CASN1EncOctetString(); |
|
519 void ConstructL(const TDesC8& aStr); |
|
520 |
|
521 // Methods from CASN1EncBase |
|
522 void CalculateContentsLengthDER(); |
|
523 void WriteContentsDERL(TDes8& aBuf) const; |
|
524 |
|
525 private: |
|
526 HBufC8* iContents; |
|
527 }; |
|
528 |
|
529 |
|
530 /** |
|
531 * Class for encoding printable strings. |
|
532 * |
|
533 * @publishedAll |
|
534 * @released |
|
535 */ |
|
536 class CASN1EncPrintableString : public CASN1EncPrimitive |
|
537 { |
|
538 public: |
|
539 /** |
|
540 Creates an ASN.1 Printable String encoder, and puts it onto the cleanup stack. |
|
541 @return The fully constructed object. |
|
542 */ |
|
543 IMPORT_C static CASN1EncPrintableString* NewLC(const TDesC8& aStr); |
|
544 |
|
545 /** |
|
546 Creates an ASN.1 Printable String encoder. |
|
547 @return The fully constructed object. |
|
548 */ |
|
549 IMPORT_C static CASN1EncPrintableString* NewL(const TDesC8& aStr); |
|
550 |
|
551 /** |
|
552 Destructor. |
|
553 */ |
|
554 IMPORT_C ~CASN1EncPrintableString(); // virtual from base |
|
555 |
|
556 private: |
|
557 CASN1EncPrintableString(); |
|
558 void ConstructL(const TDesC8& aStr); |
|
559 TInt CheckValid(const TDesC8& aStr); |
|
560 |
|
561 // Methods from CASN1EncBase |
|
562 void CalculateContentsLengthDER(); |
|
563 void WriteContentsDERL(TDes8& aBuf) const; |
|
564 |
|
565 private: |
|
566 HBufC8* iContents; |
|
567 }; |
|
568 |
|
569 |
|
570 /** |
|
571 * Class for encoding bit strings (keys, for example). |
|
572 * |
|
573 * @publishedAll |
|
574 * @released |
|
575 */ |
|
576 class CASN1EncBitString : public CASN1EncPrimitive |
|
577 { |
|
578 public: |
|
579 /** |
|
580 * Constructs a new DER bit string encoder from a bit string that |
|
581 * does not have unused bits at the end, i.e. is octet-aligned. |
|
582 * The passed string must be in big-endian format. |
|
583 * @param aBitStr Octet-aligned bit string. |
|
584 * @return A new DER bit string encoder object, |
|
585 * which is left on the cleanup stack. |
|
586 */ |
|
587 IMPORT_C static CASN1EncBitString* NewLC(const TDesC8& aBitStr); |
|
588 |
|
589 /** |
|
590 * Constructs a new DER bit string encoder from a bit string that |
|
591 * does not have unused bits at the end, i.e. is octet-aligned. |
|
592 * The passed string must be in big-endian format. |
|
593 * @param aBitStr Octet-aligned bit string. |
|
594 * @return A new DER bit string encoder object. |
|
595 */ |
|
596 IMPORT_C static CASN1EncBitString* NewL(const TDesC8& aBitStr); |
|
597 |
|
598 /** |
|
599 * Constructs a new DER bit string encoder from a bit string that |
|
600 * is not octet-aligned, which means it has unused bits in its last |
|
601 * octet. The passed string must be in big-endian format. |
|
602 * @param aBitStr Bit string. |
|
603 * @param aLengthBits Length in bits of the passed bit string. |
|
604 * The function will panic if aLengthBits is greater than |
|
605 * the actual bit length of aBitString, or the difference |
|
606 * is more that 7 bits. |
|
607 * @return A new DER bit string encoder object which is left on the |
|
608 * cleanup stack. |
|
609 */ |
|
610 IMPORT_C static CASN1EncBitString* NewLC(const TDesC8& aBitStr, TUint aLengthBits); |
|
611 |
|
612 /** |
|
613 * Constructs a new DER bit string encoder from a bit string that |
|
614 * is not octet-aligned, which means it has unused bits in its last |
|
615 * octet. The passed string must be in big-endian format. |
|
616 * @param aBitStr Bit string. |
|
617 * @param aLengthBits Length in bits of the passed bit string. |
|
618 * The function will panic if aLengthBits is greater than |
|
619 * the actual bit length of aBitString, or the difference |
|
620 * is more that 7 bits. |
|
621 * @return A new DER bit string encoder object. |
|
622 */ |
|
623 IMPORT_C static CASN1EncBitString* NewL(const TDesC8& aBitStr, TUint aLengthBits); |
|
624 |
|
625 /** |
|
626 * Wraps the passed encoding object into a bit string. |
|
627 * @param aAsnObj Encoding object to wrap. |
|
628 * @return A new bit string containing the passed encoding object. |
|
629 */ |
|
630 IMPORT_C static CASN1EncBitString* NewL(const CASN1EncBase& aAsnObj); |
|
631 |
|
632 /** |
|
633 * Wraps the passed encoding object into a bit string. |
|
634 * @param aAsnObj Encoding object to wrap. |
|
635 * @return A new bit string containing the passed encoding object |
|
636 * on the cleanup stack. |
|
637 */ |
|
638 IMPORT_C static CASN1EncBitString* NewLC(const CASN1EncBase& aAsnObj); |
|
639 |
|
640 IMPORT_C ~CASN1EncBitString(); // virtual from base |
|
641 |
|
642 private: |
|
643 CASN1EncBitString(); |
|
644 void ConstructL(const TDesC8& aBitStr); |
|
645 void ConstructL(const TDesC8& aBitStr, TUint aLengthBits); |
|
646 void ConstructL(const CASN1EncBase& aAsnObj); |
|
647 |
|
648 // Methods from CASN1EncBase |
|
649 void CalculateContentsLengthDER(); |
|
650 void WriteContentsDERL(TDes8& aBuf) const; |
|
651 |
|
652 private: |
|
653 HBufC8* iContents; |
|
654 TUint8 iPadding; |
|
655 }; |
|
656 |
|
657 /** |
|
658 * Class for encoding object identifiers. |
|
659 * |
|
660 * @publishedAll |
|
661 * @released |
|
662 */ |
|
663 class CASN1EncObjectIdentifier : public CASN1EncPrimitive |
|
664 { |
|
665 public: |
|
666 /** |
|
667 * Takes ints in a string, delimited by '.' characters in |
|
668 * between (not at ends). Takes a deep copy of the info. |
|
669 * @param aStr OID string. |
|
670 * @return New ASN.1 OID object on the cleanup stack. |
|
671 */ |
|
672 IMPORT_C static CASN1EncObjectIdentifier* NewLC(const TDesC& aStr); |
|
673 |
|
674 /** |
|
675 * Takes ints in a string, delimited by '.' characters in |
|
676 * between (not at ends). Takes a deep copy of the info. |
|
677 * @param aStr OID string. |
|
678 * @return New ASN.1 OID object. |
|
679 */ |
|
680 IMPORT_C static CASN1EncObjectIdentifier* NewL(const TDesC& aStr); |
|
681 |
|
682 /** Destructor */ |
|
683 IMPORT_C ~CASN1EncObjectIdentifier(); // virtual from base |
|
684 |
|
685 private: |
|
686 CASN1EncObjectIdentifier(); |
|
687 void ConstructL(const TDesC& aStr); |
|
688 |
|
689 // Methods from CASN1EncBase |
|
690 void CalculateContentsLengthDER(); |
|
691 void WriteContentsDERL(TDes8& aBuf) const; |
|
692 |
|
693 private: |
|
694 // Data to encode |
|
695 RArray<TASN1EncBase128DER> iData; |
|
696 TUint8 iFirstOctet; |
|
697 }; |
|
698 |
|
699 |
|
700 /** |
|
701 * Class for encoding GeneralisedTime objects. |
|
702 * |
|
703 * Doesn't support fractions of seconds or regional time zone offsets. |
|
704 * |
|
705 * @publishedAll |
|
706 * @released |
|
707 */ |
|
708 class CASN1EncGeneralizedTime : public CASN1EncPrimitive |
|
709 { |
|
710 public: |
|
711 IMPORT_C static CASN1EncGeneralizedTime* NewLC(const TTime& aTime); |
|
712 IMPORT_C static CASN1EncGeneralizedTime* NewL(const TTime& aTime); |
|
713 |
|
714 private: |
|
715 CASN1EncGeneralizedTime(const TTime& aTime); |
|
716 |
|
717 // Methods from CASN1EncBase |
|
718 void CalculateContentsLengthDER(); |
|
719 void WriteContentsDERL(TDes8& aBuf) const; |
|
720 |
|
721 private: |
|
722 TDateTime iDateTime; |
|
723 }; |
|
724 |
|
725 /** |
|
726 * Class for encapsulation of already encoded data. |
|
727 * |
|
728 * Wraps it so that the data could be used in the ASN.1 hierarchy. |
|
729 * It reverse-engineers and stores the encoded data, providing whatever |
|
730 * information is needed to override pure virtual methods of the base |
|
731 * class and write out the DER encoding in its initial form. |
|
732 * |
|
733 * @publishedAll |
|
734 * @released |
|
735 */ |
|
736 class CASN1EncEncoding : public CASN1EncBase |
|
737 { |
|
738 public: |
|
739 /** |
|
740 * Creates a new object from raw DER encoding and places it on the |
|
741 * cleanup stack. |
|
742 * @param aEncoding Raw DER encoding. |
|
743 * @return New wrapper object placed on the cleanup stack. |
|
744 */ |
|
745 IMPORT_C static CASN1EncEncoding* NewLC(const TDesC8& aEncoding); |
|
746 |
|
747 /** |
|
748 * Creates a new object from raw DER encoding. |
|
749 * @param aEncoding Raw DER encoding. |
|
750 * @return New wrapper object. |
|
751 */ |
|
752 IMPORT_C static CASN1EncEncoding* NewL(const TDesC8& aEncoding); |
|
753 |
|
754 IMPORT_C static CASN1EncEncoding* NewLC(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass); |
|
755 |
|
756 IMPORT_C ~CASN1EncEncoding(); |
|
757 |
|
758 protected: |
|
759 /** |
|
760 * Protected constructor. |
|
761 * <!-- |
|
762 * @param aType Tag type of the new object |
|
763 * @param aClass Tag class of the new object. |
|
764 * --> |
|
765 */ |
|
766 IMPORT_C CASN1EncEncoding(); |
|
767 |
|
768 private: |
|
769 /** |
|
770 * Constructs the wrapper around the passed raw DER encoding. |
|
771 * Calculates element sizes. Decodes it to get type and length. |
|
772 * @param aEncoding Raw DER encoding. |
|
773 */ |
|
774 void ConstructL(const TDesC8& aEncoding); |
|
775 |
|
776 void ConstructL(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass); |
|
777 |
|
778 virtual TBool IsConstructed() const; |
|
779 |
|
780 /** |
|
781 * Writes DER content encoding into supplied buffer, which is |
|
782 * already verified to be big enough. |
|
783 * @param aBuf Buffer to write to. |
|
784 */ |
|
785 virtual void WriteContentsDERL(TDes8& aBuf) const; |
|
786 |
|
787 /** |
|
788 * Calculates number of octets in DER content encoding. Sets |
|
789 * value of the appropriate data member. |
|
790 */ |
|
791 virtual void CalculateContentsLengthDER(); |
|
792 |
|
793 private: |
|
794 HBufC8* iContents; ///< Copy of the supplied DER encoded data (contents only). |
|
795 TASN1Class iClass; ///< ASN.1 class of the encoded object. |
|
796 TTagType iTag; ///< ASN.1 tag of the encoding. |
|
797 }; |
|
798 |
|
799 #endif // __ASN1ENC_H__ |