sl@0: /* sl@0: * Copyright (c) 1998-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: * ASN1 decoder 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 __ASN1DEC_H__ sl@0: #define __ASN1DEC_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: class RInteger; sl@0: sl@0: sl@0: class TASN1DecGeneric sl@0: { sl@0: public: sl@0: IMPORT_C explicit TASN1DecGeneric(const TDesC8& aSource); sl@0: IMPORT_C void InitL(); sl@0: IMPORT_C TPtrC8 Encoding() const; sl@0: IMPORT_C TInt LengthDER() const; sl@0: IMPORT_C TPtrC8 GetContentDER(void) const; sl@0: IMPORT_C TInt LengthDERContent(void) const; sl@0: IMPORT_C TInt LengthDERHeader() const; sl@0: IMPORT_C TTagType Tag() const; sl@0: IMPORT_C TASN1Class Class() const; sl@0: private: sl@0: TPtrC8 iEncoding; sl@0: TInt iStartOfContents; sl@0: TInt iLength; sl@0: TTagType iExplicitTag; sl@0: TASN1Class iClass; sl@0: }; sl@0: sl@0: class TASN1DecString sl@0: { sl@0: public: sl@0: protected: sl@0: IMPORT_C TASN1DecString(const TTagType aTag); sl@0: virtual TInt CheckValid(const TDesC8& aSource)=0; sl@0: }; sl@0: sl@0: class TASN1DecBoolean sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecBoolean(); sl@0: IMPORT_C TBool DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C TBool DecodeDERL(const TASN1DecGeneric& Source); sl@0: private: sl@0: }; sl@0: sl@0: class TASN1DecNull sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecNull(); sl@0: IMPORT_C void DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C void DecodeDERL(const TASN1DecGeneric& aSource); sl@0: }; sl@0: sl@0: class TASN1DecEnumerated sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecEnumerated(void); sl@0: }; sl@0: sl@0: class TASN1DecInteger sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecInteger(); sl@0: IMPORT_C TInt DecodeDERShortL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C TInt DecodeDERShortL(const TASN1DecGeneric& aSource); sl@0: IMPORT_C RInteger DecodeDERLongL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C RInteger DecodeDERLongL(const TASN1DecGeneric& aSource); sl@0: }; sl@0: sl@0: const TInt KNumberOfIDs=15; sl@0: sl@0: class TASN1DecObjectIdentifier sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecObjectIdentifier(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource); sl@0: private: sl@0: TInt DecodeContentsL(TFixedArray& aOID, const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecSet sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecSet(); sl@0: IMPORT_C CArrayPtrFlat* NewDERLC(const TDesC8& aSource); sl@0: IMPORT_C CArrayPtrFlat* DecodeDERLC(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C CArrayPtrFlat* DecodeDERLC(const TASN1DecGeneric& aSource); sl@0: IMPORT_C CArrayPtrFlat* DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax); sl@0: IMPORT_C CArrayPtrFlat* DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax); sl@0: protected: sl@0: /** @internalComponent */ sl@0: void DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat& aDest); sl@0: /** @internalComponent */ sl@0: static void CleanupSet(TAny* aArray); sl@0: }; sl@0: sl@0: class TASN1DecGraphicString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecGraphicString(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecVisibleString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecVisibleString(void); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecGeneralizedTime sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecGeneralizedTime(); sl@0: IMPORT_C TTime DecodeDERL(const TDesC8& aSource, TInt& aPos); sl@0: IMPORT_C TTime DecodeDERL(const TASN1DecGeneric& aGen); sl@0: private: sl@0: TTime GetTimeL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecUTCTime sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecUTCTime(); sl@0: IMPORT_C TTime DecodeDERL(const TASN1DecGeneric& aGen); sl@0: IMPORT_C TTime DecodeDERL(const TDesC8& aSource, TInt& aPos); sl@0: private: sl@0: TTime GetTimeL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecBitString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecBitString(); sl@0: IMPORT_C HBufC8* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC8* DecodeDERL(const TASN1DecGeneric& aSource); sl@0: //we need the next 2 functions because many standards encode things as bit sl@0: //strings sl@0: IMPORT_C HBufC8* ExtractOctetStringL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC8* ExtractOctetStringL(const TASN1DecGeneric& aSource); sl@0: }; sl@0: sl@0: class TASN1DecIA5String sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecIA5String(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: sl@0: class TASN1DecUTF8String sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecUTF8String(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecGeneralString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecGeneralString(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecOctetString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecOctetString(); sl@0: IMPORT_C HBufC8* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC8* DecodeDERL(const TASN1DecGeneric& aSource); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecNumericString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecNumericString(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: protected: sl@0: /** @internalComponent */ sl@0: TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecVideotexString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecVideotexString(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecPrintableString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecPrintableString(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource); sl@0: protected: sl@0: /** @internalComponent */ sl@0: TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: /** sl@0: * Class used for decoding Teletex strings. sl@0: * The TeletexString type is not fully supported by this library. sl@0: * Instead the decode methods perform a direct conversion from 8 to 16bits by adding sl@0: * null characters in the second byte of each character. This will work as expected sl@0: * for cases where the string contains ASCII data. sl@0: * As this is non-destructive, the original data can be retrieved by performing sl@0: * a Copy to an 8-bit descriptor. sl@0: */ sl@0: class TASN1DecTeletexString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecTeletexString(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& Source); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: /** sl@0: Class used for decoding ASN.1 BMP strings. sl@0: */ sl@0: class TASN1DecBMPString sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecBMPString(); sl@0: IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource); sl@0: protected: sl@0: IMPORT_C TInt CheckValid(const TDesC8& aSource); sl@0: private: sl@0: HBufC* DecodeContentsL(const TDesC8& aSource); sl@0: }; sl@0: sl@0: class TASN1DecSequence sl@0: { sl@0: public: sl@0: IMPORT_C TASN1DecSequence(); sl@0: IMPORT_C CArrayPtrFlat* DecodeDERLC(const TDesC8& aSource,TInt& aPos); sl@0: IMPORT_C CArrayPtrFlat* DecodeDERLC(const TASN1DecGeneric& aSource); sl@0: IMPORT_C CArrayPtrFlat* DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax); sl@0: IMPORT_C CArrayPtrFlat* DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax); sl@0: protected: sl@0: /** @internalComponent */ sl@0: void DecodeContentsL(const TDesC8& aSource, CArrayPtrFlat& aDest); sl@0: /** @internalComponent */ sl@0: static void CleanupSequence(TAny* aArray); sl@0: }; sl@0: sl@0: #endif