sl@0: /* sl@0: * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Declares all classes used to decode ASN.1 data, including the sl@0: * base interface. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __ASN1ENC_H__ sl@0: #define __ASN1ENC_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: class CASN1EncBase; sl@0: class TASN1EncBase128DER; sl@0: sl@0: class TInteger; sl@0: sl@0: typedef void (CASN1EncBase::* WriteFunc)(TDes8& aBuf) const; sl@0: sl@0: /** sl@0: * Base class for all ASN.1 types that we can encode. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncBase : public CBase sl@0: { sl@0: public: sl@0: /** sl@0: * Gives total number of octets in the DER encoding of this sl@0: * object. sl@0: * @return Number of octets in DER encoding of this object. sl@0: */ sl@0: IMPORT_C TUint LengthDER() const; sl@0: sl@0: /** sl@0: * Writes entire DER encoding of this object into the given sl@0: * buffer. sl@0: * @param aBuf Buffer receiving the encoding. sl@0: * @param aPos Position to start writing at. sl@0: */ sl@0: IMPORT_C void WriteDERL(TDes8& aBuf, TUint& aPos) const; sl@0: sl@0: /** sl@0: * Sets tag type/class of the encoding object sl@0: * @param aType Tag type to set sl@0: * @param aClass Tag class to set. sl@0: */ sl@0: IMPORT_C void SetTag(const TTagType aType, sl@0: const TASN1Class aClass = EContextSpecific); sl@0: sl@0: IMPORT_C ~CASN1EncBase(); sl@0: sl@0: /** sl@0: * @internalComponent sl@0: * sl@0: * Sets parent for the object sl@0: * @param aParent Pointer to an ASN.1 object that becomes this sl@0: * object's parent. sl@0: */ sl@0: void SetParent(CASN1EncBase* aParent); sl@0: sl@0: protected: sl@0: /** sl@0: * Protected constructor sl@0: * @param aType Tag type of the new object sl@0: * @param aClass Tag class of the new object. sl@0: */ sl@0: IMPORT_C CASN1EncBase(const TTagType aType, const TASN1Class aClass); sl@0: sl@0: /** sl@0: * Must call this version from derived classes in their sl@0: * ConstructL, but only once they're ready to have sl@0: * CalculateContentsLengthDER called on them. sl@0: */ sl@0: IMPORT_C virtual void ConstructL(); sl@0: sl@0: /** sl@0: * @internalComponent sl@0: * sl@0: * Derived classes must call this if the length of their sl@0: * contents changes after construction. sl@0: */ sl@0: void ContentsLengthChanged(); sl@0: sl@0: protected: sl@0: /** sl@0: * @internalComponent sl@0: * sl@0: * Calculates number of octets in DER length encoding. Must set sl@0: * value of the appropriate data member. Made protected because it is sl@0: * needed by CASN1EncEncoding class. sl@0: */ sl@0: void CalculateLengthLengthDER(); sl@0: sl@0: private: sl@0: /** sl@0: * Calculates number of octets in DER tag encoding. Must set sl@0: * value of the appropriate data member. sl@0: */ sl@0: void CalculateTagLengthDER(); sl@0: sl@0: /** sl@0: * Calculates number of octets in DER content encoding. Must set sl@0: * value of the appropriate data member. sl@0: */ sl@0: virtual void CalculateContentsLengthDER() = 0; sl@0: sl@0: virtual TBool IsConstructed() const = 0; sl@0: sl@0: // Write the octet data in each section sl@0: // Note that buffer *will* be big enough: these are called only sl@0: // after checking. sl@0: sl@0: /** sl@0: * Writes DER tag encoding into supplied buffer, which is sl@0: * already verified to be big enough. sl@0: * @param aBuf Buffer to write to. sl@0: */ sl@0: void WriteTagDERL(TDes8& aBuf) const; sl@0: sl@0: /** sl@0: * Writes DER length encoding into supplied buffer, which is sl@0: * already verified to be big enough. sl@0: * @param aBuf Buffer to write to. sl@0: */ sl@0: virtual void WriteLengthDER(TDes8& aBuf) const; sl@0: sl@0: /** sl@0: * Writes DER content encoding into supplied buffer, which is sl@0: * already verified to be big enough. Must be implemented by sl@0: * derived classes. sl@0: * @param aBuf Buffer to write to. sl@0: */ sl@0: virtual void WriteContentsDERL(TDes8& aBuf) const = 0; sl@0: sl@0: /** sl@0: * Helper function, used for efficiency sl@0: * @param aBuf Buffer to write to sl@0: * @param aPos Position in the buffer to start writing at sl@0: * (updated on exit) sl@0: * @param aLength Length of data to write sl@0: * @param aWriteFunc Points to the function used to perform sl@0: * the actual write operation. sl@0: */ sl@0: void WriteHelperL(TDes8& aBuf, TUint& aPos, const TUint aLength, sl@0: WriteFunc aWriteFunc) const; sl@0: sl@0: protected: sl@0: // Cached length data - data set from the CalculateXxxx methods above sl@0: TUint iTagLengthDER; ///< Length of DER encoded tag sl@0: TUint iLengthLengthDER; ///< Length of DER encoded length sl@0: TUint iContentsLengthDER; ///< Length of DER encoded content sl@0: sl@0: private: sl@0: /** sl@0: * The object owning this one (if we're held in a sequence, sl@0: * for example). sl@0: */ sl@0: CASN1EncBase* iParent; sl@0: sl@0: // Tag data sl@0: TTagType iType; ///< Tag type of this object sl@0: TASN1Class iClass; ///< Tag class of this object sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Base class for all ASN1 constructed-type objects. Most of these sl@0: * are container classes, but another type is the explicit-tagging sl@0: * wrapper object. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncConstructed : public CASN1EncBase sl@0: { sl@0: protected: sl@0: /** sl@0: * @internalComponent sl@0: * sl@0: * Protected constructor sl@0: * @param aType Tag type for the new object sl@0: * @param aClass Tag class for the new object. sl@0: */ sl@0: CASN1EncConstructed(const TTagType aType, const TASN1Class aClass); sl@0: sl@0: private: sl@0: virtual const CASN1EncBase& Child(const TUint aIndex) const = 0; sl@0: virtual TUint NumChildren() const = 0; sl@0: sl@0: private: sl@0: // From CASN1EncBase sl@0: void CalculateContentsLengthDER(); sl@0: TBool IsConstructed() const; sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class used to wrap other encoding objects in order to give sl@0: * them an explicit tag. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncExplicitTag : public CASN1EncConstructed sl@0: { sl@0: public: sl@0: /** sl@0: * Takes ownership of the encoder, *including* the case when sl@0: * this method leaves. sl@0: * @param aEncoder ASN.1 encoding object to wrap sl@0: * @param aType Tag type to assign sl@0: * @param aClass Tag class to assign sl@0: * @return Wrapped encoding object pushed on the cleanup stack. sl@0: */ sl@0: IMPORT_C static CASN1EncExplicitTag* NewLC(CASN1EncBase* aEncoder, sl@0: const TTagType aType, const TASN1Class aClass = EContextSpecific); sl@0: sl@0: /** sl@0: * Takes ownership of the encoder, *including* the case when sl@0: * this method leaves. sl@0: * @param aEncoder ASN.1 encoding object to wrap sl@0: * @param aType Tag type to assign sl@0: * @param aClass Tag class to assign sl@0: * @return Wrapped encoding object. sl@0: */ sl@0: IMPORT_C static CASN1EncExplicitTag* NewL(CASN1EncBase* aEncoder, sl@0: const TTagType aType, const TASN1Class aClass = EContextSpecific); sl@0: sl@0: IMPORT_C ~CASN1EncExplicitTag(); // virtual from base sl@0: sl@0: private: sl@0: CASN1EncExplicitTag(CASN1EncBase* aEncoder, const TTagType aType, sl@0: const TASN1Class aClass); sl@0: sl@0: // From CASN1EncConstructed sl@0: TUint NumChildren() const; sl@0: const CASN1EncBase& Child(const TUint aIndex) const; sl@0: sl@0: private: sl@0: CASN1EncBase* iEncoder; // Inner encoding object sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Base class for all ASN1 container types - sequences, sl@0: * sets, etc. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncContainer : public CASN1EncConstructed sl@0: { sl@0: public: sl@0: /** sl@0: * Call this to add a child object to the container. sl@0: * Takes ownership if and only if it doesn't Leave. sl@0: * Checks for null input, calls AddChildInt, calls sl@0: * ContentsLengthChanged(). sl@0: * @param aChild Child ASN1 encoding object to add. sl@0: */ sl@0: IMPORT_C void AddChildL(CASN1EncBase* aChild); sl@0: sl@0: /** sl@0: * Call this to add a child object to the container. sl@0: * Takes ownership if and only if it doesn't Leave. sl@0: * Checks for null input, calls AddChildInt, calls sl@0: * ContentsLengthChanged(). Pops added child object sl@0: * off the cleanup stack. sl@0: * @param aChild Child ASN1 encoding object to add. sl@0: */ sl@0: IMPORT_C void AddAndPopChildL(CASN1EncBase* aChild); sl@0: sl@0: protected: sl@0: /** @internalComponent */ sl@0: CASN1EncContainer(const TTagType aType); sl@0: sl@0: private: sl@0: /** sl@0: * Internal method, derived classes implement to add a child. sl@0: * No need to check for null input or call sl@0: * ContentsLengthChanged(). Takes ownership, but only if you sl@0: * don't leave. sl@0: * @param aChild Child encoding object to add. sl@0: */ sl@0: virtual void AddChildIntL(const CASN1EncBase* aChild) = 0; sl@0: }; sl@0: sl@0: /** sl@0: * Class for encoding SEQUENCE and SEQUENCE-OF data types. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncSequence : public CASN1EncContainer sl@0: { sl@0: public: sl@0: IMPORT_C static CASN1EncSequence* NewL(); sl@0: IMPORT_C static CASN1EncSequence* NewLC(); sl@0: sl@0: IMPORT_C ~CASN1EncSequence(); // virtual from base sl@0: sl@0: protected: sl@0: /** @internalComponent */ sl@0: CASN1EncSequence(); sl@0: sl@0: private: sl@0: // From CASN1EncContainer sl@0: const CASN1EncBase& Child(const TUint aIndex) const; sl@0: void AddChildIntL(const CASN1EncBase* aChild); sl@0: TUint NumChildren() const; sl@0: sl@0: private: sl@0: RPointerArray iChildren; sl@0: }; sl@0: sl@0: /** sl@0: * Class for encoding SET and SET-OF data types. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncSet : public CASN1EncContainer sl@0: { sl@0: public: sl@0: /** sl@0: Creates an ASN.1 Set encoder. sl@0: @return The fully constructed object. sl@0: */ sl@0: IMPORT_C static CASN1EncSet* NewL(); sl@0: sl@0: /** sl@0: Creates an ASN.1 Set encoder, and puts it onto the cleanup stack. sl@0: @return The fully constructed object. sl@0: */ sl@0: IMPORT_C static CASN1EncSet* NewLC(); sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: IMPORT_C ~CASN1EncSet(); // virtual from base sl@0: sl@0: protected: sl@0: /** sl@0: * @internalComponent sl@0: * sl@0: * Constructor sl@0: */ sl@0: CASN1EncSet(); sl@0: sl@0: private: sl@0: // From CASN1EncContainer sl@0: const CASN1EncBase& Child(const TUint aIndex) const; sl@0: void AddChildIntL(const CASN1EncBase* aChild); sl@0: TUint NumChildren() const; sl@0: sl@0: private: sl@0: RPointerArray iChildren; sl@0: }; sl@0: sl@0: sl@0: sl@0: /** sl@0: * All ASN1 primitive type encoding classes derive from here. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncPrimitive : public CASN1EncBase sl@0: { sl@0: protected: sl@0: IMPORT_C CASN1EncPrimitive(const TTagType aType); sl@0: sl@0: private: sl@0: TBool IsConstructed() const; ///< Inherited from CASN1EncBase sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class for encoding NULLs. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncNull : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: IMPORT_C static CASN1EncNull* NewL(); sl@0: IMPORT_C static CASN1EncNull* NewLC(); sl@0: sl@0: private: sl@0: CASN1EncNull(); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER() ; sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class for encoding Boolean values. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncBoolean : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: IMPORT_C static CASN1EncBoolean* NewLC(const TBool aBool); sl@0: IMPORT_C static CASN1EncBoolean* NewL(const TBool aBool); sl@0: sl@0: private: sl@0: CASN1EncBoolean(const TBool aBool); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER() ; sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: const TBool iBool; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class for encoding TInts only. Use CASN1EncBigInt for encoding sl@0: * Big Integer objects. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncInt : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: IMPORT_C static CASN1EncInt* NewLC(const TInt aInt); sl@0: IMPORT_C static CASN1EncInt* NewL(const TInt aInt); sl@0: sl@0: private: sl@0: CASN1EncInt(const TInt aInt); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER() ; sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: private: sl@0: const TInt iInt; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class for encoding Big Integer objects only - use CASN1EncInt sl@0: * for TInts. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncBigInt : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: // Takes a deep copy sl@0: IMPORT_C static CASN1EncBigInt* NewLC(const TInteger& aInteger); sl@0: IMPORT_C static CASN1EncBigInt* NewL(const TInteger& aInteger); sl@0: sl@0: IMPORT_C ~CASN1EncBigInt(); // virtual from base sl@0: sl@0: private: sl@0: CASN1EncBigInt(); sl@0: void ConstructL(const TInteger& aInteger); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER(); sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: private: sl@0: HBufC8* iContents; sl@0: TPtrC8 iWriteContents; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class for encoding octet strings. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncOctetString : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: // Takes a deep copy sl@0: IMPORT_C static CASN1EncOctetString* NewLC(const TDesC8& aStr); sl@0: IMPORT_C static CASN1EncOctetString* NewL(const TDesC8& aStr); sl@0: sl@0: IMPORT_C ~CASN1EncOctetString(); // virtual from base sl@0: sl@0: private: sl@0: CASN1EncOctetString(); sl@0: void ConstructL(const TDesC8& aStr); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER(); sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: private: sl@0: HBufC8* iContents; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class for encoding printable strings. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncPrintableString : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: /** sl@0: Creates an ASN.1 Printable String encoder, and puts it onto the cleanup stack. sl@0: @return The fully constructed object. sl@0: */ sl@0: IMPORT_C static CASN1EncPrintableString* NewLC(const TDesC8& aStr); sl@0: sl@0: /** sl@0: Creates an ASN.1 Printable String encoder. sl@0: @return The fully constructed object. sl@0: */ sl@0: IMPORT_C static CASN1EncPrintableString* NewL(const TDesC8& aStr); sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: IMPORT_C ~CASN1EncPrintableString(); // virtual from base sl@0: sl@0: private: sl@0: CASN1EncPrintableString(); sl@0: void ConstructL(const TDesC8& aStr); sl@0: TInt CheckValid(const TDesC8& aStr); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER(); sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: private: sl@0: HBufC8* iContents; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class for encoding bit strings (keys, for example). sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncBitString : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: /** sl@0: * Constructs a new DER bit string encoder from a bit string that sl@0: * does not have unused bits at the end, i.e. is octet-aligned. sl@0: * The passed string must be in big-endian format. sl@0: * @param aBitStr Octet-aligned bit string. sl@0: * @return A new DER bit string encoder object, sl@0: * which is left on the cleanup stack. sl@0: */ sl@0: IMPORT_C static CASN1EncBitString* NewLC(const TDesC8& aBitStr); sl@0: sl@0: /** sl@0: * Constructs a new DER bit string encoder from a bit string that sl@0: * does not have unused bits at the end, i.e. is octet-aligned. sl@0: * The passed string must be in big-endian format. sl@0: * @param aBitStr Octet-aligned bit string. sl@0: * @return A new DER bit string encoder object. sl@0: */ sl@0: IMPORT_C static CASN1EncBitString* NewL(const TDesC8& aBitStr); sl@0: sl@0: /** sl@0: * Constructs a new DER bit string encoder from a bit string that sl@0: * is not octet-aligned, which means it has unused bits in its last sl@0: * octet. The passed string must be in big-endian format. sl@0: * @param aBitStr Bit string. sl@0: * @param aLengthBits Length in bits of the passed bit string. sl@0: * The function will panic if aLengthBits is greater than sl@0: * the actual bit length of aBitString, or the difference sl@0: * is more that 7 bits. sl@0: * @return A new DER bit string encoder object which is left on the sl@0: * cleanup stack. sl@0: */ sl@0: IMPORT_C static CASN1EncBitString* NewLC(const TDesC8& aBitStr, TUint aLengthBits); sl@0: sl@0: /** sl@0: * Constructs a new DER bit string encoder from a bit string that sl@0: * is not octet-aligned, which means it has unused bits in its last sl@0: * octet. The passed string must be in big-endian format. sl@0: * @param aBitStr Bit string. sl@0: * @param aLengthBits Length in bits of the passed bit string. sl@0: * The function will panic if aLengthBits is greater than sl@0: * the actual bit length of aBitString, or the difference sl@0: * is more that 7 bits. sl@0: * @return A new DER bit string encoder object. sl@0: */ sl@0: IMPORT_C static CASN1EncBitString* NewL(const TDesC8& aBitStr, TUint aLengthBits); sl@0: sl@0: /** sl@0: * Wraps the passed encoding object into a bit string. sl@0: * @param aAsnObj Encoding object to wrap. sl@0: * @return A new bit string containing the passed encoding object. sl@0: */ sl@0: IMPORT_C static CASN1EncBitString* NewL(const CASN1EncBase& aAsnObj); sl@0: sl@0: /** sl@0: * Wraps the passed encoding object into a bit string. sl@0: * @param aAsnObj Encoding object to wrap. sl@0: * @return A new bit string containing the passed encoding object sl@0: * on the cleanup stack. sl@0: */ sl@0: IMPORT_C static CASN1EncBitString* NewLC(const CASN1EncBase& aAsnObj); sl@0: sl@0: IMPORT_C ~CASN1EncBitString(); // virtual from base sl@0: sl@0: private: sl@0: CASN1EncBitString(); sl@0: void ConstructL(const TDesC8& aBitStr); sl@0: void ConstructL(const TDesC8& aBitStr, TUint aLengthBits); sl@0: void ConstructL(const CASN1EncBase& aAsnObj); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER(); sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: private: sl@0: HBufC8* iContents; sl@0: TUint8 iPadding; sl@0: }; sl@0: sl@0: /** sl@0: * Class for encoding object identifiers. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncObjectIdentifier : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: /** sl@0: * Takes ints in a string, delimited by '.' characters in sl@0: * between (not at ends). Takes a deep copy of the info. sl@0: * @param aStr OID string. sl@0: * @return New ASN.1 OID object on the cleanup stack. sl@0: */ sl@0: IMPORT_C static CASN1EncObjectIdentifier* NewLC(const TDesC& aStr); sl@0: sl@0: /** sl@0: * Takes ints in a string, delimited by '.' characters in sl@0: * between (not at ends). Takes a deep copy of the info. sl@0: * @param aStr OID string. sl@0: * @return New ASN.1 OID object. sl@0: */ sl@0: IMPORT_C static CASN1EncObjectIdentifier* NewL(const TDesC& aStr); sl@0: sl@0: /** Destructor */ sl@0: IMPORT_C ~CASN1EncObjectIdentifier(); // virtual from base sl@0: sl@0: private: sl@0: CASN1EncObjectIdentifier(); sl@0: void ConstructL(const TDesC& aStr); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER(); sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: private: sl@0: // Data to encode sl@0: RArray iData; sl@0: TUint8 iFirstOctet; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Class for encoding GeneralisedTime objects. sl@0: * sl@0: * Doesn't support fractions of seconds or regional time zone offsets. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncGeneralizedTime : public CASN1EncPrimitive sl@0: { sl@0: public: sl@0: IMPORT_C static CASN1EncGeneralizedTime* NewLC(const TTime& aTime); sl@0: IMPORT_C static CASN1EncGeneralizedTime* NewL(const TTime& aTime); sl@0: sl@0: private: sl@0: CASN1EncGeneralizedTime(const TTime& aTime); sl@0: sl@0: // Methods from CASN1EncBase sl@0: void CalculateContentsLengthDER(); sl@0: void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: private: sl@0: TDateTime iDateTime; sl@0: }; sl@0: sl@0: /** sl@0: * Class for encapsulation of already encoded data. sl@0: * sl@0: * Wraps it so that the data could be used in the ASN.1 hierarchy. sl@0: * It reverse-engineers and stores the encoded data, providing whatever sl@0: * information is needed to override pure virtual methods of the base sl@0: * class and write out the DER encoding in its initial form. sl@0: * sl@0: * @publishedAll sl@0: * @released sl@0: */ sl@0: class CASN1EncEncoding : public CASN1EncBase sl@0: { sl@0: public: sl@0: /** sl@0: * Creates a new object from raw DER encoding and places it on the sl@0: * cleanup stack. sl@0: * @param aEncoding Raw DER encoding. sl@0: * @return New wrapper object placed on the cleanup stack. sl@0: */ sl@0: IMPORT_C static CASN1EncEncoding* NewLC(const TDesC8& aEncoding); sl@0: sl@0: /** sl@0: * Creates a new object from raw DER encoding. sl@0: * @param aEncoding Raw DER encoding. sl@0: * @return New wrapper object. sl@0: */ sl@0: IMPORT_C static CASN1EncEncoding* NewL(const TDesC8& aEncoding); sl@0: sl@0: IMPORT_C static CASN1EncEncoding* NewLC(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass); sl@0: sl@0: IMPORT_C ~CASN1EncEncoding(); sl@0: sl@0: protected: sl@0: /** sl@0: * Protected constructor. sl@0: * sl@0: */ sl@0: IMPORT_C CASN1EncEncoding(); sl@0: sl@0: private: sl@0: /** sl@0: * Constructs the wrapper around the passed raw DER encoding. sl@0: * Calculates element sizes. Decodes it to get type and length. sl@0: * @param aEncoding Raw DER encoding. sl@0: */ sl@0: void ConstructL(const TDesC8& aEncoding); sl@0: sl@0: void ConstructL(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass); sl@0: sl@0: virtual TBool IsConstructed() const; sl@0: sl@0: /** sl@0: * Writes DER content encoding into supplied buffer, which is sl@0: * already verified to be big enough. sl@0: * @param aBuf Buffer to write to. sl@0: */ sl@0: virtual void WriteContentsDERL(TDes8& aBuf) const; sl@0: sl@0: /** sl@0: * Calculates number of octets in DER content encoding. Sets sl@0: * value of the appropriate data member. sl@0: */ sl@0: virtual void CalculateContentsLengthDER(); sl@0: sl@0: private: sl@0: HBufC8* iContents; ///< Copy of the supplied DER encoded data (contents only). sl@0: TASN1Class iClass; ///< ASN.1 class of the encoded object. sl@0: TTagType iTag; ///< ASN.1 tag of the encoding. sl@0: }; sl@0: sl@0: #endif // __ASN1ENC_H__