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