cryptoservices/certificateandkeymgmt/inc/asn1dec.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 1998-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 * ASN1 decoder
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file 
       
    24  @publishedAll
       
    25  @released
       
    26 */
       
    27  
       
    28 #ifndef __ASN1DEC_H__
       
    29 #define __ASN1DEC_H__
       
    30 
       
    31 #include <e32std.h>
       
    32 #include <e32base.h>
       
    33 #include <asn1cons.h>
       
    34 
       
    35 class RInteger;
       
    36 
       
    37 
       
    38 /**
       
    39  * @publishedAll
       
    40  * @released
       
    41  */
       
    42 class TASN1DecGeneric
       
    43 	{
       
    44 public:
       
    45 	IMPORT_C explicit TASN1DecGeneric(const TDesC8& aSource);
       
    46 	IMPORT_C void InitL();
       
    47 	IMPORT_C TPtrC8 Encoding() const;
       
    48 	IMPORT_C TInt LengthDER() const;
       
    49 	IMPORT_C TPtrC8 GetContentDER(void) const;
       
    50 	IMPORT_C TInt LengthDERContent(void) const;
       
    51 	IMPORT_C TInt LengthDERHeader() const;
       
    52 	IMPORT_C TTagType Tag() const;
       
    53 	IMPORT_C TASN1Class Class() const;
       
    54 private:
       
    55 	TPtrC8 iEncoding;
       
    56 	TInt iStartOfContents;
       
    57 	TInt iLength;
       
    58 	TTagType iExplicitTag;
       
    59 	TASN1Class iClass;
       
    60 	};
       
    61 
       
    62 /**
       
    63  * @publishedAll
       
    64  * @released
       
    65  */
       
    66 class TASN1DecString
       
    67 	{
       
    68 public:
       
    69 protected:
       
    70 	IMPORT_C TASN1DecString(const TTagType aTag);
       
    71 	virtual TInt CheckValid(const TDesC8& aSource)=0;
       
    72 	};
       
    73 
       
    74 /**
       
    75  * @publishedAll
       
    76  * @released
       
    77  */
       
    78 class TASN1DecBoolean
       
    79 	{
       
    80 public:
       
    81 	IMPORT_C TASN1DecBoolean();
       
    82 	IMPORT_C TBool DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
    83 	IMPORT_C TBool DecodeDERL(const TASN1DecGeneric& Source);
       
    84 private:
       
    85 	};
       
    86 
       
    87 /**
       
    88  * @publishedAll
       
    89  * @released
       
    90  */
       
    91 class TASN1DecNull
       
    92 	{
       
    93 public:
       
    94 	IMPORT_C TASN1DecNull();
       
    95 	IMPORT_C void DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
    96 	IMPORT_C void DecodeDERL(const TASN1DecGeneric& aSource);
       
    97 	};
       
    98 
       
    99 /**
       
   100  * @publishedAll
       
   101  * @released
       
   102  */
       
   103 class TASN1DecEnumerated
       
   104 	{
       
   105 public:
       
   106 	IMPORT_C TASN1DecEnumerated(void);
       
   107 	};
       
   108 
       
   109 /**
       
   110  * @publishedAll
       
   111  * @released
       
   112  */
       
   113 class TASN1DecInteger
       
   114 	{
       
   115 public:
       
   116 	IMPORT_C TASN1DecInteger();
       
   117 	IMPORT_C TInt DecodeDERShortL(const TDesC8& aSource,TInt& aPos);
       
   118 	IMPORT_C TInt DecodeDERShortL(const TASN1DecGeneric& aSource);
       
   119 	IMPORT_C RInteger DecodeDERLongL(const TDesC8& aSource,TInt& aPos);
       
   120 	IMPORT_C RInteger DecodeDERLongL(const TASN1DecGeneric& aSource);
       
   121 	};
       
   122 
       
   123 const TInt KNumberOfIDs=15;
       
   124 
       
   125 /**
       
   126  * @publishedAll
       
   127  * @released
       
   128  */
       
   129 class TASN1DecObjectIdentifier
       
   130 	{
       
   131 public:
       
   132 	IMPORT_C TASN1DecObjectIdentifier();
       
   133 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   134 	IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
       
   135 private:
       
   136 	TInt DecodeContentsL(TFixedArray<TInt, KNumberOfIDs>& aOID, const TDesC8& aSource);
       
   137 	};
       
   138 
       
   139 /**
       
   140  * @publishedAll
       
   141  * @released
       
   142  */
       
   143 class TASN1DecSet
       
   144 	{
       
   145 public:
       
   146 	IMPORT_C TASN1DecSet();
       
   147 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* NewDERLC(const TDesC8& aSource);
       
   148 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos);
       
   149 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource);
       
   150 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax);
       
   151 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax);
       
   152 protected:
       
   153 	/** @internalComponent */
       
   154 	void DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat<TASN1DecGeneric>& aDest);
       
   155 	/** @internalComponent */
       
   156 	static void CleanupSet(TAny* aArray);	
       
   157 	};
       
   158 
       
   159 /**
       
   160  * @publishedAll
       
   161  * @released
       
   162  */
       
   163 class TASN1DecGraphicString
       
   164 	{
       
   165 public:
       
   166 	IMPORT_C TASN1DecGraphicString();
       
   167 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   168 protected:
       
   169 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   170 private:
       
   171 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   172 	};
       
   173 
       
   174 /**
       
   175  * @publishedAll
       
   176  * @released
       
   177  */
       
   178 class TASN1DecVisibleString
       
   179 	{
       
   180 public:
       
   181 	IMPORT_C TASN1DecVisibleString(void);
       
   182 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   183 protected:
       
   184 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   185 private:
       
   186 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   187 	};
       
   188 
       
   189 /**
       
   190  * @publishedAll
       
   191  * @released
       
   192  */
       
   193 class TASN1DecGeneralizedTime
       
   194 	{
       
   195 public:
       
   196 	IMPORT_C TASN1DecGeneralizedTime();
       
   197 	IMPORT_C TTime DecodeDERL(const TDesC8& aSource, TInt& aPos);
       
   198 	IMPORT_C TTime DecodeDERL(const TASN1DecGeneric& aGen);
       
   199 private:
       
   200 	TTime GetTimeL(const TDesC8& aSource);
       
   201 	};
       
   202 
       
   203 /**
       
   204  * @publishedAll
       
   205  * @released
       
   206  */
       
   207 class TASN1DecUTCTime
       
   208 	{
       
   209 public:
       
   210 	IMPORT_C TASN1DecUTCTime();
       
   211 	IMPORT_C TTime DecodeDERL(const TASN1DecGeneric& aGen);
       
   212 	IMPORT_C TTime DecodeDERL(const TDesC8& aSource, TInt& aPos);
       
   213 private:
       
   214 	TTime GetTimeL(const TDesC8& aSource);
       
   215 	};
       
   216 
       
   217 /**
       
   218  * @publishedAll
       
   219  * @released
       
   220  */
       
   221 class TASN1DecBitString
       
   222 	{
       
   223 public:
       
   224 	IMPORT_C TASN1DecBitString();
       
   225 	IMPORT_C HBufC8* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   226 	IMPORT_C HBufC8* DecodeDERL(const TASN1DecGeneric& aSource);
       
   227 	//we need the next 2 functions because many standards encode things as bit
       
   228 	//strings
       
   229 	IMPORT_C HBufC8* ExtractOctetStringL(const TDesC8& aSource,TInt& aPos);
       
   230 	IMPORT_C HBufC8* ExtractOctetStringL(const TASN1DecGeneric& aSource);
       
   231 	};
       
   232 
       
   233 /**
       
   234  * @publishedAll
       
   235  * @released
       
   236  */
       
   237 class TASN1DecIA5String
       
   238 	{
       
   239 public:
       
   240 	IMPORT_C TASN1DecIA5String();
       
   241 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   242 	IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
       
   243 protected:
       
   244 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   245 private:
       
   246 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   247 	};
       
   248 
       
   249 /**
       
   250  * @internalComponent
       
   251  * @released
       
   252  */
       
   253 class TASN1DecGenericString
       
   254 	{
       
   255 public:
       
   256 	TASN1DecGenericString();
       
   257 	TInt GetContentDER(TDes8& aContent);
       
   258 	TInt Length(void);
       
   259 private:
       
   260 	};
       
   261 
       
   262 /**
       
   263  * @publishedAll
       
   264  * @released
       
   265  */
       
   266 class TASN1DecUTF8String
       
   267 	{
       
   268 public:
       
   269 	IMPORT_C TASN1DecUTF8String();
       
   270 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   271 	IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
       
   272 protected:
       
   273 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   274 private:
       
   275 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   276 	};
       
   277 
       
   278 /**
       
   279  * @publishedAll
       
   280  * @released
       
   281  */
       
   282 class TASN1DecGeneralString
       
   283 	{
       
   284 public:
       
   285 	IMPORT_C TASN1DecGeneralString();
       
   286 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   287 protected:
       
   288 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   289 private:
       
   290 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   291 	};
       
   292 
       
   293 /**
       
   294  * @publishedAll
       
   295  * @released
       
   296  */
       
   297 class TASN1DecOctetString
       
   298 	{
       
   299 public:
       
   300 	IMPORT_C TASN1DecOctetString();
       
   301 	IMPORT_C HBufC8* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   302 	IMPORT_C HBufC8* DecodeDERL(const TASN1DecGeneric& aSource);
       
   303 protected:
       
   304 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   305 	};
       
   306 
       
   307 /**
       
   308  * @publishedAll
       
   309  * @released
       
   310  */
       
   311 class TASN1DecNumericString
       
   312 	{
       
   313 public:
       
   314 	IMPORT_C TASN1DecNumericString();
       
   315 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   316 protected:
       
   317 	/** @internalComponent */
       
   318 	TInt CheckValid(const TDesC8& aSource);
       
   319 private:
       
   320 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   321 	};
       
   322 
       
   323 /**
       
   324  * @publishedAll
       
   325  * @released
       
   326  */
       
   327 class TASN1DecVideotexString
       
   328 	{
       
   329 public:
       
   330 	IMPORT_C TASN1DecVideotexString();
       
   331 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   332 protected:
       
   333 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   334 private:
       
   335 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   336 	};
       
   337 
       
   338 /**
       
   339  * @publishedAll
       
   340  * @released
       
   341  */
       
   342 class TASN1DecPrintableString
       
   343 	{
       
   344 public:
       
   345 	IMPORT_C TASN1DecPrintableString();
       
   346 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   347 	IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
       
   348 protected:
       
   349 	/** @internalComponent */
       
   350 	TInt CheckValid(const TDesC8& aSource);
       
   351 private:
       
   352 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   353 	};
       
   354 
       
   355 /**
       
   356  * Class used for decoding Teletex strings.
       
   357  * The TeletexString type is not fully supported by this library.
       
   358  * Instead the decode methods perform a direct conversion from 8 to 16bits by adding 
       
   359  * null characters in the second byte of each character. This will work as expected 
       
   360  * for cases where the string contains ASCII data.
       
   361  * As this is non-destructive, the original data can be retrieved by performing 
       
   362  * a Copy to an 8-bit descriptor.
       
   363  * @publishedAll
       
   364  * @released
       
   365  */
       
   366 class TASN1DecTeletexString
       
   367 	{
       
   368 public:
       
   369 	IMPORT_C TASN1DecTeletexString();
       
   370 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   371 	IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& Source);
       
   372 protected:
       
   373 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   374 private:
       
   375 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   376 	};
       
   377 
       
   378 /**
       
   379 Class used for decoding ASN.1 BMP strings.
       
   380 @publishedAll
       
   381 @released
       
   382  */
       
   383 class TASN1DecBMPString
       
   384 	{
       
   385 public:
       
   386 	IMPORT_C TASN1DecBMPString();
       
   387 	IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
       
   388 	IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
       
   389 protected:
       
   390 	IMPORT_C TInt CheckValid(const TDesC8& aSource);
       
   391 private:
       
   392 	HBufC* DecodeContentsL(const TDesC8& aSource);
       
   393 	};
       
   394 
       
   395 /**
       
   396  * @publishedAll
       
   397  * @released
       
   398  */
       
   399 class TASN1DecSequence
       
   400 	{
       
   401 public:
       
   402 	IMPORT_C TASN1DecSequence();
       
   403 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos);
       
   404 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource);
       
   405 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax);
       
   406 	IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax);
       
   407 protected:
       
   408 	/** @internalComponent */
       
   409 	void DecodeContentsL(const TDesC8& aSource, CArrayPtrFlat<TASN1DecGeneric>& aDest);
       
   410 	/** @internalComponent */
       
   411 	static void CleanupSequence(TAny* aArray);
       
   412 	};
       
   413 
       
   414 #endif