sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* ASN1 decoder
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
@publishedAll
|
sl@0
|
23 |
@released
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
|
sl@0
|
26 |
#ifndef __ASN1DEC_H__
|
sl@0
|
27 |
#define __ASN1DEC_H__
|
sl@0
|
28 |
|
sl@0
|
29 |
#include <e32std.h>
|
sl@0
|
30 |
#include <e32base.h>
|
sl@0
|
31 |
#include <asn1cons.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
class RInteger;
|
sl@0
|
34 |
|
sl@0
|
35 |
|
sl@0
|
36 |
class TASN1DecGeneric
|
sl@0
|
37 |
{
|
sl@0
|
38 |
public:
|
sl@0
|
39 |
IMPORT_C explicit TASN1DecGeneric(const TDesC8& aSource);
|
sl@0
|
40 |
IMPORT_C void InitL();
|
sl@0
|
41 |
IMPORT_C TPtrC8 Encoding() const;
|
sl@0
|
42 |
IMPORT_C TInt LengthDER() const;
|
sl@0
|
43 |
IMPORT_C TPtrC8 GetContentDER(void) const;
|
sl@0
|
44 |
IMPORT_C TInt LengthDERContent(void) const;
|
sl@0
|
45 |
IMPORT_C TInt LengthDERHeader() const;
|
sl@0
|
46 |
IMPORT_C TTagType Tag() const;
|
sl@0
|
47 |
IMPORT_C TASN1Class Class() const;
|
sl@0
|
48 |
private:
|
sl@0
|
49 |
TPtrC8 iEncoding;
|
sl@0
|
50 |
TInt iStartOfContents;
|
sl@0
|
51 |
TInt iLength;
|
sl@0
|
52 |
TTagType iExplicitTag;
|
sl@0
|
53 |
TASN1Class iClass;
|
sl@0
|
54 |
};
|
sl@0
|
55 |
|
sl@0
|
56 |
class TASN1DecString
|
sl@0
|
57 |
{
|
sl@0
|
58 |
public:
|
sl@0
|
59 |
protected:
|
sl@0
|
60 |
IMPORT_C TASN1DecString(const TTagType aTag);
|
sl@0
|
61 |
virtual TInt CheckValid(const TDesC8& aSource)=0;
|
sl@0
|
62 |
};
|
sl@0
|
63 |
|
sl@0
|
64 |
class TASN1DecBoolean
|
sl@0
|
65 |
{
|
sl@0
|
66 |
public:
|
sl@0
|
67 |
IMPORT_C TASN1DecBoolean();
|
sl@0
|
68 |
IMPORT_C TBool DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
69 |
IMPORT_C TBool DecodeDERL(const TASN1DecGeneric& Source);
|
sl@0
|
70 |
private:
|
sl@0
|
71 |
};
|
sl@0
|
72 |
|
sl@0
|
73 |
class TASN1DecNull
|
sl@0
|
74 |
{
|
sl@0
|
75 |
public:
|
sl@0
|
76 |
IMPORT_C TASN1DecNull();
|
sl@0
|
77 |
IMPORT_C void DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
78 |
IMPORT_C void DecodeDERL(const TASN1DecGeneric& aSource);
|
sl@0
|
79 |
};
|
sl@0
|
80 |
|
sl@0
|
81 |
class TASN1DecEnumerated
|
sl@0
|
82 |
{
|
sl@0
|
83 |
public:
|
sl@0
|
84 |
IMPORT_C TASN1DecEnumerated(void);
|
sl@0
|
85 |
};
|
sl@0
|
86 |
|
sl@0
|
87 |
class TASN1DecInteger
|
sl@0
|
88 |
{
|
sl@0
|
89 |
public:
|
sl@0
|
90 |
IMPORT_C TASN1DecInteger();
|
sl@0
|
91 |
IMPORT_C TInt DecodeDERShortL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
92 |
IMPORT_C TInt DecodeDERShortL(const TASN1DecGeneric& aSource);
|
sl@0
|
93 |
IMPORT_C RInteger DecodeDERLongL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
94 |
IMPORT_C RInteger DecodeDERLongL(const TASN1DecGeneric& aSource);
|
sl@0
|
95 |
};
|
sl@0
|
96 |
|
sl@0
|
97 |
const TInt KNumberOfIDs=15;
|
sl@0
|
98 |
|
sl@0
|
99 |
class TASN1DecObjectIdentifier
|
sl@0
|
100 |
{
|
sl@0
|
101 |
public:
|
sl@0
|
102 |
IMPORT_C TASN1DecObjectIdentifier();
|
sl@0
|
103 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
104 |
IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
|
sl@0
|
105 |
private:
|
sl@0
|
106 |
TInt DecodeContentsL(TFixedArray<TInt, KNumberOfIDs>& aOID, const TDesC8& aSource);
|
sl@0
|
107 |
};
|
sl@0
|
108 |
|
sl@0
|
109 |
class TASN1DecSet
|
sl@0
|
110 |
{
|
sl@0
|
111 |
public:
|
sl@0
|
112 |
IMPORT_C TASN1DecSet();
|
sl@0
|
113 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* NewDERLC(const TDesC8& aSource);
|
sl@0
|
114 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
115 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource);
|
sl@0
|
116 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax);
|
sl@0
|
117 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax);
|
sl@0
|
118 |
protected:
|
sl@0
|
119 |
/** @internalComponent */
|
sl@0
|
120 |
void DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat<TASN1DecGeneric>& aDest);
|
sl@0
|
121 |
/** @internalComponent */
|
sl@0
|
122 |
static void CleanupSet(TAny* aArray);
|
sl@0
|
123 |
};
|
sl@0
|
124 |
|
sl@0
|
125 |
class TASN1DecGraphicString
|
sl@0
|
126 |
{
|
sl@0
|
127 |
public:
|
sl@0
|
128 |
IMPORT_C TASN1DecGraphicString();
|
sl@0
|
129 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
130 |
protected:
|
sl@0
|
131 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
132 |
private:
|
sl@0
|
133 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
134 |
};
|
sl@0
|
135 |
|
sl@0
|
136 |
class TASN1DecVisibleString
|
sl@0
|
137 |
{
|
sl@0
|
138 |
public:
|
sl@0
|
139 |
IMPORT_C TASN1DecVisibleString(void);
|
sl@0
|
140 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
141 |
protected:
|
sl@0
|
142 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
143 |
private:
|
sl@0
|
144 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
145 |
};
|
sl@0
|
146 |
|
sl@0
|
147 |
class TASN1DecGeneralizedTime
|
sl@0
|
148 |
{
|
sl@0
|
149 |
public:
|
sl@0
|
150 |
IMPORT_C TASN1DecGeneralizedTime();
|
sl@0
|
151 |
IMPORT_C TTime DecodeDERL(const TDesC8& aSource, TInt& aPos);
|
sl@0
|
152 |
IMPORT_C TTime DecodeDERL(const TASN1DecGeneric& aGen);
|
sl@0
|
153 |
private:
|
sl@0
|
154 |
TTime GetTimeL(const TDesC8& aSource);
|
sl@0
|
155 |
};
|
sl@0
|
156 |
|
sl@0
|
157 |
class TASN1DecUTCTime
|
sl@0
|
158 |
{
|
sl@0
|
159 |
public:
|
sl@0
|
160 |
IMPORT_C TASN1DecUTCTime();
|
sl@0
|
161 |
IMPORT_C TTime DecodeDERL(const TASN1DecGeneric& aGen);
|
sl@0
|
162 |
IMPORT_C TTime DecodeDERL(const TDesC8& aSource, TInt& aPos);
|
sl@0
|
163 |
private:
|
sl@0
|
164 |
TTime GetTimeL(const TDesC8& aSource);
|
sl@0
|
165 |
};
|
sl@0
|
166 |
|
sl@0
|
167 |
class TASN1DecBitString
|
sl@0
|
168 |
{
|
sl@0
|
169 |
public:
|
sl@0
|
170 |
IMPORT_C TASN1DecBitString();
|
sl@0
|
171 |
IMPORT_C HBufC8* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
172 |
IMPORT_C HBufC8* DecodeDERL(const TASN1DecGeneric& aSource);
|
sl@0
|
173 |
//we need the next 2 functions because many standards encode things as bit
|
sl@0
|
174 |
//strings
|
sl@0
|
175 |
IMPORT_C HBufC8* ExtractOctetStringL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
176 |
IMPORT_C HBufC8* ExtractOctetStringL(const TASN1DecGeneric& aSource);
|
sl@0
|
177 |
};
|
sl@0
|
178 |
|
sl@0
|
179 |
class TASN1DecIA5String
|
sl@0
|
180 |
{
|
sl@0
|
181 |
public:
|
sl@0
|
182 |
IMPORT_C TASN1DecIA5String();
|
sl@0
|
183 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
184 |
IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
|
sl@0
|
185 |
protected:
|
sl@0
|
186 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
187 |
private:
|
sl@0
|
188 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
189 |
};
|
sl@0
|
190 |
|
sl@0
|
191 |
|
sl@0
|
192 |
class TASN1DecUTF8String
|
sl@0
|
193 |
{
|
sl@0
|
194 |
public:
|
sl@0
|
195 |
IMPORT_C TASN1DecUTF8String();
|
sl@0
|
196 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
197 |
IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
|
sl@0
|
198 |
protected:
|
sl@0
|
199 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
200 |
private:
|
sl@0
|
201 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
202 |
};
|
sl@0
|
203 |
|
sl@0
|
204 |
class TASN1DecGeneralString
|
sl@0
|
205 |
{
|
sl@0
|
206 |
public:
|
sl@0
|
207 |
IMPORT_C TASN1DecGeneralString();
|
sl@0
|
208 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
209 |
protected:
|
sl@0
|
210 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
211 |
private:
|
sl@0
|
212 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
213 |
};
|
sl@0
|
214 |
|
sl@0
|
215 |
class TASN1DecOctetString
|
sl@0
|
216 |
{
|
sl@0
|
217 |
public:
|
sl@0
|
218 |
IMPORT_C TASN1DecOctetString();
|
sl@0
|
219 |
IMPORT_C HBufC8* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
220 |
IMPORT_C HBufC8* DecodeDERL(const TASN1DecGeneric& aSource);
|
sl@0
|
221 |
protected:
|
sl@0
|
222 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
223 |
};
|
sl@0
|
224 |
|
sl@0
|
225 |
class TASN1DecNumericString
|
sl@0
|
226 |
{
|
sl@0
|
227 |
public:
|
sl@0
|
228 |
IMPORT_C TASN1DecNumericString();
|
sl@0
|
229 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
230 |
protected:
|
sl@0
|
231 |
/** @internalComponent */
|
sl@0
|
232 |
TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
233 |
private:
|
sl@0
|
234 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
235 |
};
|
sl@0
|
236 |
|
sl@0
|
237 |
class TASN1DecVideotexString
|
sl@0
|
238 |
{
|
sl@0
|
239 |
public:
|
sl@0
|
240 |
IMPORT_C TASN1DecVideotexString();
|
sl@0
|
241 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
242 |
protected:
|
sl@0
|
243 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
244 |
private:
|
sl@0
|
245 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
246 |
};
|
sl@0
|
247 |
|
sl@0
|
248 |
class TASN1DecPrintableString
|
sl@0
|
249 |
{
|
sl@0
|
250 |
public:
|
sl@0
|
251 |
IMPORT_C TASN1DecPrintableString();
|
sl@0
|
252 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
253 |
IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
|
sl@0
|
254 |
protected:
|
sl@0
|
255 |
/** @internalComponent */
|
sl@0
|
256 |
TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
257 |
private:
|
sl@0
|
258 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
259 |
};
|
sl@0
|
260 |
|
sl@0
|
261 |
/**
|
sl@0
|
262 |
* Class used for decoding Teletex strings.
|
sl@0
|
263 |
* The TeletexString type is not fully supported by this library.
|
sl@0
|
264 |
* Instead the decode methods perform a direct conversion from 8 to 16bits by adding
|
sl@0
|
265 |
* null characters in the second byte of each character. This will work as expected
|
sl@0
|
266 |
* for cases where the string contains ASCII data.
|
sl@0
|
267 |
* As this is non-destructive, the original data can be retrieved by performing
|
sl@0
|
268 |
* a Copy to an 8-bit descriptor.
|
sl@0
|
269 |
*/
|
sl@0
|
270 |
class TASN1DecTeletexString
|
sl@0
|
271 |
{
|
sl@0
|
272 |
public:
|
sl@0
|
273 |
IMPORT_C TASN1DecTeletexString();
|
sl@0
|
274 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
275 |
IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& Source);
|
sl@0
|
276 |
protected:
|
sl@0
|
277 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
278 |
private:
|
sl@0
|
279 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
280 |
};
|
sl@0
|
281 |
|
sl@0
|
282 |
/**
|
sl@0
|
283 |
Class used for decoding ASN.1 BMP strings.
|
sl@0
|
284 |
*/
|
sl@0
|
285 |
class TASN1DecBMPString
|
sl@0
|
286 |
{
|
sl@0
|
287 |
public:
|
sl@0
|
288 |
IMPORT_C TASN1DecBMPString();
|
sl@0
|
289 |
IMPORT_C HBufC* DecodeDERL(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
290 |
IMPORT_C HBufC* DecodeDERL(const TASN1DecGeneric& aSource);
|
sl@0
|
291 |
protected:
|
sl@0
|
292 |
IMPORT_C TInt CheckValid(const TDesC8& aSource);
|
sl@0
|
293 |
private:
|
sl@0
|
294 |
HBufC* DecodeContentsL(const TDesC8& aSource);
|
sl@0
|
295 |
};
|
sl@0
|
296 |
|
sl@0
|
297 |
class TASN1DecSequence
|
sl@0
|
298 |
{
|
sl@0
|
299 |
public:
|
sl@0
|
300 |
IMPORT_C TASN1DecSequence();
|
sl@0
|
301 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos);
|
sl@0
|
302 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource);
|
sl@0
|
303 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax);
|
sl@0
|
304 |
IMPORT_C CArrayPtrFlat<TASN1DecGeneric>* DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax);
|
sl@0
|
305 |
protected:
|
sl@0
|
306 |
/** @internalComponent */
|
sl@0
|
307 |
void DecodeContentsL(const TDesC8& aSource, CArrayPtrFlat<TASN1DecGeneric>& aDest);
|
sl@0
|
308 |
/** @internalComponent */
|
sl@0
|
309 |
static void CleanupSequence(TAny* aArray);
|
sl@0
|
310 |
};
|
sl@0
|
311 |
|
sl@0
|
312 |
#endif
|