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