1.1 --- a/epoc32/include/asn1dec.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/asn1dec.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,414 @@
1.4 -asn1dec.h
1.5 +/*
1.6 +* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.7 +* All rights reserved.
1.8 +* This component and the accompanying materials are made available
1.9 +* under the terms of the License "Eclipse Public License v1.0"
1.10 +* which accompanies this distribution, and is available
1.11 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.12 +*
1.13 +* Initial Contributors:
1.14 +* Nokia Corporation - initial contribution.
1.15 +*
1.16 +* Contributors:
1.17 +*
1.18 +* Description:
1.19 +* ASN1 decoder
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +
1.25 +
1.26 +/**
1.27 + @file
1.28 + @publishedAll
1.29 + @released
1.30 +*/
1.31 +
1.32 +#ifndef __ASN1DEC_H__
1.33 +#define __ASN1DEC_H__
1.34 +
1.35 +#include <e32std.h>
1.36 +#include <e32base.h>
1.37 +#include <asn1cons.h>
1.38 +
1.39 +class RInteger;
1.40 +
1.41 +
1.42 +/**
1.43 + * @publishedAll
1.44 + * @released
1.45 + */
1.46 +class TASN1DecGeneric
1.47 + {
1.48 +public:
1.49 + IMPORT_C explicit TASN1DecGeneric(const TDesC8& aSource);
1.50 + IMPORT_C void InitL();
1.51 + IMPORT_C TPtrC8 Encoding() const;
1.52 + IMPORT_C TInt LengthDER() const;
1.53 + IMPORT_C TPtrC8 GetContentDER(void) const;
1.54 + IMPORT_C TInt LengthDERContent(void) const;
1.55 + IMPORT_C TInt LengthDERHeader() const;
1.56 + IMPORT_C TTagType Tag() const;
1.57 + IMPORT_C TASN1Class Class() const;
1.58 +private:
1.59 + TPtrC8 iEncoding;
1.60 + TInt iStartOfContents;
1.61 + TInt iLength;
1.62 + TTagType iExplicitTag;
1.63 + TASN1Class iClass;
1.64 + };
1.65 +
1.66 +/**
1.67 + * @publishedAll
1.68 + * @released
1.69 + */
1.70 +class TASN1DecString
1.71 + {
1.72 +public:
1.73 +protected:
1.74 + IMPORT_C TASN1DecString(const TTagType aTag);
1.75 + virtual TInt CheckValid(const TDesC8& aSource)=0;
1.76 + };
1.77 +
1.78 +/**
1.79 + * @publishedAll
1.80 + * @released
1.81 + */
1.82 +class TASN1DecBoolean
1.83 + {
1.84 +public:
1.85 + IMPORT_C TASN1DecBoolean();
1.86 + IMPORT_C TBool DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.87 + IMPORT_C TBool DecodeDERL(const TASN1DecGeneric& Source);
1.88 +private:
1.89 + };
1.90 +
1.91 +/**
1.92 + * @publishedAll
1.93 + * @released
1.94 + */
1.95 +class TASN1DecNull
1.96 + {
1.97 +public:
1.98 + IMPORT_C TASN1DecNull();
1.99 + IMPORT_C void DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.100 + IMPORT_C void DecodeDERL(const TASN1DecGeneric& aSource);
1.101 + };
1.102 +
1.103 +/**
1.104 + * @publishedAll
1.105 + * @released
1.106 + */
1.107 +class TASN1DecEnumerated
1.108 + {
1.109 +public:
1.110 + IMPORT_C TASN1DecEnumerated(void);
1.111 + };
1.112 +
1.113 +/**
1.114 + * @publishedAll
1.115 + * @released
1.116 + */
1.117 +class TASN1DecInteger
1.118 + {
1.119 +public:
1.120 + IMPORT_C TASN1DecInteger();
1.121 + IMPORT_C TInt DecodeDERShortL(const TDesC8& aSource,TInt& aPos);
1.122 + IMPORT_C TInt DecodeDERShortL(const TASN1DecGeneric& aSource);
1.123 + IMPORT_C RInteger DecodeDERLongL(const TDesC8& aSource,TInt& aPos);
1.124 + IMPORT_C RInteger DecodeDERLongL(const TASN1DecGeneric& aSource);
1.125 + };
1.126 +
1.127 +const TInt KNumberOfIDs=15;
1.128 +
1.129 +/**
1.130 + * @publishedAll
1.131 + * @released
1.132 + */
1.133 +class TASN1DecObjectIdentifier
1.134 + {
1.135 +public:
1.136 + IMPORT_C TASN1DecObjectIdentifier();
1.137 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.138 + IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
1.139 +private:
1.140 + TInt DecodeContentsL(TFixedArray<TInt, KNumberOfIDs>& aOID, const TDesC8& aSource);
1.141 + };
1.142 +
1.143 +/**
1.144 + * @publishedAll
1.145 + * @released
1.146 + */
1.147 +class TASN1DecSet
1.148 + {
1.149 +public:
1.150 + IMPORT_C TASN1DecSet();
1.151 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* NewDERLC(const TDesC8& aSource);
1.152 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos);
1.153 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource);
1.154 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax);
1.155 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax);
1.156 +protected:
1.157 + /** @internalComponent */
1.158 + void DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat<TASN1DecGeneric>& aDest);
1.159 + /** @internalComponent */
1.160 + static void CleanupSet(TAny* aArray);
1.161 + };
1.162 +
1.163 +/**
1.164 + * @publishedAll
1.165 + * @released
1.166 + */
1.167 +class TASN1DecGraphicString
1.168 + {
1.169 +public:
1.170 + IMPORT_C TASN1DecGraphicString();
1.171 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.172 +protected:
1.173 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.174 +private:
1.175 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.176 + };
1.177 +
1.178 +/**
1.179 + * @publishedAll
1.180 + * @released
1.181 + */
1.182 +class TASN1DecVisibleString
1.183 + {
1.184 +public:
1.185 + IMPORT_C TASN1DecVisibleString(void);
1.186 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.187 +protected:
1.188 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.189 +private:
1.190 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.191 + };
1.192 +
1.193 +/**
1.194 + * @publishedAll
1.195 + * @released
1.196 + */
1.197 +class TASN1DecGeneralizedTime
1.198 + {
1.199 +public:
1.200 + IMPORT_C TASN1DecGeneralizedTime();
1.201 + IMPORT_C TTime DecodeDERL(const TDesC8& aSource, TInt& aPos);
1.202 + IMPORT_C TTime DecodeDERL(const TASN1DecGeneric& aGen);
1.203 +private:
1.204 + TTime GetTimeL(const TDesC8& aSource);
1.205 + };
1.206 +
1.207 +/**
1.208 + * @publishedAll
1.209 + * @released
1.210 + */
1.211 +class TASN1DecUTCTime
1.212 + {
1.213 +public:
1.214 + IMPORT_C TASN1DecUTCTime();
1.215 + IMPORT_C TTime DecodeDERL(const TASN1DecGeneric& aGen);
1.216 + IMPORT_C TTime DecodeDERL(const TDesC8& aSource, TInt& aPos);
1.217 +private:
1.218 + TTime GetTimeL(const TDesC8& aSource);
1.219 + };
1.220 +
1.221 +/**
1.222 + * @publishedAll
1.223 + * @released
1.224 + */
1.225 +class TASN1DecBitString
1.226 + {
1.227 +public:
1.228 + IMPORT_C TASN1DecBitString();
1.229 + IMPORT_C HBufC8* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.230 + IMPORT_C HBufC8* DecodeDERL(const TASN1DecGeneric& aSource);
1.231 + //we need the next 2 functions because many standards encode things as bit
1.232 + //strings
1.233 + IMPORT_C HBufC8* ExtractOctetStringL(const TDesC8& aSource,TInt& aPos);
1.234 + IMPORT_C HBufC8* ExtractOctetStringL(const TASN1DecGeneric& aSource);
1.235 + };
1.236 +
1.237 +/**
1.238 + * @publishedAll
1.239 + * @released
1.240 + */
1.241 +class TASN1DecIA5String
1.242 + {
1.243 +public:
1.244 + IMPORT_C TASN1DecIA5String();
1.245 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.246 + IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
1.247 +protected:
1.248 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.249 +private:
1.250 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.251 + };
1.252 +
1.253 +/**
1.254 + * @internalComponent
1.255 + * @released
1.256 + */
1.257 +class TASN1DecGenericString
1.258 + {
1.259 +public:
1.260 + TASN1DecGenericString();
1.261 + TInt GetContentDER(TDes8& aContent);
1.262 + TInt Length(void);
1.263 +private:
1.264 + };
1.265 +
1.266 +/**
1.267 + * @publishedAll
1.268 + * @released
1.269 + */
1.270 +class TASN1DecUTF8String
1.271 + {
1.272 +public:
1.273 + IMPORT_C TASN1DecUTF8String();
1.274 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.275 + IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
1.276 +protected:
1.277 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.278 +private:
1.279 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.280 + };
1.281 +
1.282 +/**
1.283 + * @publishedAll
1.284 + * @released
1.285 + */
1.286 +class TASN1DecGeneralString
1.287 + {
1.288 +public:
1.289 + IMPORT_C TASN1DecGeneralString();
1.290 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.291 +protected:
1.292 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.293 +private:
1.294 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.295 + };
1.296 +
1.297 +/**
1.298 + * @publishedAll
1.299 + * @released
1.300 + */
1.301 +class TASN1DecOctetString
1.302 + {
1.303 +public:
1.304 + IMPORT_C TASN1DecOctetString();
1.305 + IMPORT_C HBufC8* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.306 + IMPORT_C HBufC8* DecodeDERL(const TASN1DecGeneric& aSource);
1.307 +protected:
1.308 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.309 + };
1.310 +
1.311 +/**
1.312 + * @publishedAll
1.313 + * @released
1.314 + */
1.315 +class TASN1DecNumericString
1.316 + {
1.317 +public:
1.318 + IMPORT_C TASN1DecNumericString();
1.319 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.320 +protected:
1.321 + /** @internalComponent */
1.322 + TInt CheckValid(const TDesC8& aSource);
1.323 +private:
1.324 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.325 + };
1.326 +
1.327 +/**
1.328 + * @publishedAll
1.329 + * @released
1.330 + */
1.331 +class TASN1DecVideotexString
1.332 + {
1.333 +public:
1.334 + IMPORT_C TASN1DecVideotexString();
1.335 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.336 +protected:
1.337 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.338 +private:
1.339 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.340 + };
1.341 +
1.342 +/**
1.343 + * @publishedAll
1.344 + * @released
1.345 + */
1.346 +class TASN1DecPrintableString
1.347 + {
1.348 +public:
1.349 + IMPORT_C TASN1DecPrintableString();
1.350 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.351 + IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
1.352 +protected:
1.353 + /** @internalComponent */
1.354 + TInt CheckValid(const TDesC8& aSource);
1.355 +private:
1.356 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.357 + };
1.358 +
1.359 +/**
1.360 + * Class used for decoding Teletex strings.
1.361 + * The TeletexString type is not fully supported by this library.
1.362 + * Instead the decode methods perform a direct conversion from 8 to 16bits by adding
1.363 + * null characters in the second byte of each character. This will work as expected
1.364 + * for cases where the string contains ASCII data.
1.365 + * As this is non-destructive, the original data can be retrieved by performing
1.366 + * a Copy to an 8-bit descriptor.
1.367 + * @publishedAll
1.368 + * @released
1.369 + */
1.370 +class TASN1DecTeletexString
1.371 + {
1.372 +public:
1.373 + IMPORT_C TASN1DecTeletexString();
1.374 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.375 + IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& Source);
1.376 +protected:
1.377 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.378 +private:
1.379 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.380 + };
1.381 +
1.382 +/**
1.383 +Class used for decoding ASN.1 BMP strings.
1.384 +@publishedAll
1.385 +@released
1.386 + */
1.387 +class TASN1DecBMPString
1.388 + {
1.389 +public:
1.390 + IMPORT_C TASN1DecBMPString();
1.391 + IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
1.392 + IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
1.393 +protected:
1.394 + IMPORT_C TInt CheckValid(const TDesC8& aSource);
1.395 +private:
1.396 + HBufC* DecodeContentsL(const TDesC8& aSource);
1.397 + };
1.398 +
1.399 +/**
1.400 + * @publishedAll
1.401 + * @released
1.402 + */
1.403 +class TASN1DecSequence
1.404 + {
1.405 +public:
1.406 + IMPORT_C TASN1DecSequence();
1.407 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos);
1.408 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource);
1.409 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax);
1.410 + IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax);
1.411 +protected:
1.412 + /** @internalComponent */
1.413 + void DecodeContentsL(const TDesC8& aSource, CArrayPtrFlat<TASN1DecGeneric>& aDest);
1.414 + /** @internalComponent */
1.415 + static void CleanupSequence(TAny* aArray);
1.416 + };
1.417 +
1.418 +#endif