sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2001-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 |
* Declares all classes used to decode ASN.1 data, including the
|
sl@0
|
16 |
* base interface.
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
@file
|
sl@0
|
23 |
@publishedAll
|
sl@0
|
24 |
@released
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
|
sl@0
|
27 |
#ifndef __ASN1ENC_H__
|
sl@0
|
28 |
#define __ASN1ENC_H__
|
sl@0
|
29 |
|
sl@0
|
30 |
#include <e32base.h>
|
sl@0
|
31 |
#include <asn1cons.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
class CASN1EncBase;
|
sl@0
|
34 |
class TASN1EncBase128DER;
|
sl@0
|
35 |
|
sl@0
|
36 |
class TInteger;
|
sl@0
|
37 |
|
sl@0
|
38 |
typedef void (CASN1EncBase::* WriteFunc)(TDes8& aBuf) const;
|
sl@0
|
39 |
|
sl@0
|
40 |
/**
|
sl@0
|
41 |
* Base class for all ASN.1 types that we can encode.
|
sl@0
|
42 |
*
|
sl@0
|
43 |
* @publishedAll
|
sl@0
|
44 |
* @released
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
class CASN1EncBase : public CBase
|
sl@0
|
47 |
{
|
sl@0
|
48 |
public:
|
sl@0
|
49 |
/**
|
sl@0
|
50 |
* Gives total number of octets in the DER encoding of this
|
sl@0
|
51 |
* object.
|
sl@0
|
52 |
* @return Number of octets in DER encoding of this object.
|
sl@0
|
53 |
*/
|
sl@0
|
54 |
IMPORT_C TUint LengthDER() const;
|
sl@0
|
55 |
|
sl@0
|
56 |
/**
|
sl@0
|
57 |
* Writes entire DER encoding of this object into the given
|
sl@0
|
58 |
* buffer.
|
sl@0
|
59 |
* @param aBuf Buffer receiving the encoding.
|
sl@0
|
60 |
* @param aPos Position to start writing at.
|
sl@0
|
61 |
*/
|
sl@0
|
62 |
IMPORT_C void WriteDERL(TDes8& aBuf, TUint& aPos) const;
|
sl@0
|
63 |
|
sl@0
|
64 |
/**
|
sl@0
|
65 |
* Sets tag type/class of the encoding object
|
sl@0
|
66 |
* @param aType Tag type to set
|
sl@0
|
67 |
* @param aClass Tag class to set.
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
IMPORT_C void SetTag(const TTagType aType,
|
sl@0
|
70 |
const TASN1Class aClass = EContextSpecific);
|
sl@0
|
71 |
|
sl@0
|
72 |
IMPORT_C ~CASN1EncBase();
|
sl@0
|
73 |
|
sl@0
|
74 |
/**
|
sl@0
|
75 |
* @internalComponent
|
sl@0
|
76 |
*
|
sl@0
|
77 |
* Sets parent for the object
|
sl@0
|
78 |
* @param aParent Pointer to an ASN.1 object that becomes this
|
sl@0
|
79 |
* object's parent.
|
sl@0
|
80 |
*/
|
sl@0
|
81 |
void SetParent(CASN1EncBase* aParent);
|
sl@0
|
82 |
|
sl@0
|
83 |
protected:
|
sl@0
|
84 |
/**
|
sl@0
|
85 |
* Protected constructor
|
sl@0
|
86 |
* @param aType Tag type of the new object
|
sl@0
|
87 |
* @param aClass Tag class of the new object.
|
sl@0
|
88 |
*/
|
sl@0
|
89 |
IMPORT_C CASN1EncBase(const TTagType aType, const TASN1Class aClass);
|
sl@0
|
90 |
|
sl@0
|
91 |
/**
|
sl@0
|
92 |
* Must call this version from derived classes in their
|
sl@0
|
93 |
* ConstructL, but only once they're ready to have
|
sl@0
|
94 |
* CalculateContentsLengthDER called on them.
|
sl@0
|
95 |
*/
|
sl@0
|
96 |
IMPORT_C virtual void ConstructL();
|
sl@0
|
97 |
|
sl@0
|
98 |
/**
|
sl@0
|
99 |
* @internalComponent
|
sl@0
|
100 |
*
|
sl@0
|
101 |
* Derived classes must call this if the length of their
|
sl@0
|
102 |
* contents changes after construction.
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
void ContentsLengthChanged();
|
sl@0
|
105 |
|
sl@0
|
106 |
protected:
|
sl@0
|
107 |
/**
|
sl@0
|
108 |
* @internalComponent
|
sl@0
|
109 |
*
|
sl@0
|
110 |
* Calculates number of octets in DER length encoding. Must set
|
sl@0
|
111 |
* value of the appropriate data member. Made protected because it is
|
sl@0
|
112 |
* needed by CASN1EncEncoding class.
|
sl@0
|
113 |
*/
|
sl@0
|
114 |
void CalculateLengthLengthDER();
|
sl@0
|
115 |
|
sl@0
|
116 |
private:
|
sl@0
|
117 |
/**
|
sl@0
|
118 |
* Calculates number of octets in DER tag encoding. Must set
|
sl@0
|
119 |
* value of the appropriate data member.
|
sl@0
|
120 |
*/
|
sl@0
|
121 |
void CalculateTagLengthDER();
|
sl@0
|
122 |
|
sl@0
|
123 |
/**
|
sl@0
|
124 |
* Calculates number of octets in DER content encoding. Must set
|
sl@0
|
125 |
* value of the appropriate data member.
|
sl@0
|
126 |
*/
|
sl@0
|
127 |
virtual void CalculateContentsLengthDER() = 0;
|
sl@0
|
128 |
|
sl@0
|
129 |
virtual TBool IsConstructed() const = 0;
|
sl@0
|
130 |
|
sl@0
|
131 |
// Write the octet data in each section
|
sl@0
|
132 |
// Note that buffer *will* be big enough: these are called only
|
sl@0
|
133 |
// after checking.
|
sl@0
|
134 |
|
sl@0
|
135 |
/**
|
sl@0
|
136 |
* Writes DER tag encoding into supplied buffer, which is
|
sl@0
|
137 |
* already verified to be big enough.
|
sl@0
|
138 |
* @param aBuf Buffer to write to.
|
sl@0
|
139 |
*/
|
sl@0
|
140 |
void WriteTagDERL(TDes8& aBuf) const;
|
sl@0
|
141 |
|
sl@0
|
142 |
/**
|
sl@0
|
143 |
* Writes DER length encoding into supplied buffer, which is
|
sl@0
|
144 |
* already verified to be big enough.
|
sl@0
|
145 |
* @param aBuf Buffer to write to.
|
sl@0
|
146 |
*/
|
sl@0
|
147 |
virtual void WriteLengthDER(TDes8& aBuf) const;
|
sl@0
|
148 |
|
sl@0
|
149 |
/**
|
sl@0
|
150 |
* Writes DER content encoding into supplied buffer, which is
|
sl@0
|
151 |
* already verified to be big enough. Must be implemented by
|
sl@0
|
152 |
* derived classes.
|
sl@0
|
153 |
* @param aBuf Buffer to write to.
|
sl@0
|
154 |
*/
|
sl@0
|
155 |
virtual void WriteContentsDERL(TDes8& aBuf) const = 0;
|
sl@0
|
156 |
|
sl@0
|
157 |
/**
|
sl@0
|
158 |
* Helper function, used for efficiency
|
sl@0
|
159 |
* @param aBuf Buffer to write to
|
sl@0
|
160 |
* @param aPos Position in the buffer to start writing at
|
sl@0
|
161 |
* (updated on exit)
|
sl@0
|
162 |
* @param aLength Length of data to write
|
sl@0
|
163 |
* @param aWriteFunc Points to the function used to perform
|
sl@0
|
164 |
* the actual write operation.
|
sl@0
|
165 |
*/
|
sl@0
|
166 |
void WriteHelperL(TDes8& aBuf, TUint& aPos, const TUint aLength,
|
sl@0
|
167 |
WriteFunc aWriteFunc) const;
|
sl@0
|
168 |
|
sl@0
|
169 |
protected:
|
sl@0
|
170 |
// Cached length data - data set from the CalculateXxxx methods above
|
sl@0
|
171 |
TUint iTagLengthDER; ///< Length of DER encoded tag
|
sl@0
|
172 |
TUint iLengthLengthDER; ///< Length of DER encoded length
|
sl@0
|
173 |
TUint iContentsLengthDER; ///< Length of DER encoded content
|
sl@0
|
174 |
|
sl@0
|
175 |
private:
|
sl@0
|
176 |
/**
|
sl@0
|
177 |
* The object owning this one (if we're held in a sequence,
|
sl@0
|
178 |
* for example).
|
sl@0
|
179 |
*/
|
sl@0
|
180 |
CASN1EncBase* iParent;
|
sl@0
|
181 |
|
sl@0
|
182 |
// Tag data
|
sl@0
|
183 |
TTagType iType; ///< Tag type of this object
|
sl@0
|
184 |
TASN1Class iClass; ///< Tag class of this object
|
sl@0
|
185 |
};
|
sl@0
|
186 |
|
sl@0
|
187 |
|
sl@0
|
188 |
/**
|
sl@0
|
189 |
* Base class for all ASN1 constructed-type objects. Most of these
|
sl@0
|
190 |
* are container classes, but another type is the explicit-tagging
|
sl@0
|
191 |
* wrapper object.
|
sl@0
|
192 |
*
|
sl@0
|
193 |
* @publishedAll
|
sl@0
|
194 |
* @released
|
sl@0
|
195 |
*/
|
sl@0
|
196 |
class CASN1EncConstructed : public CASN1EncBase
|
sl@0
|
197 |
{
|
sl@0
|
198 |
protected:
|
sl@0
|
199 |
/**
|
sl@0
|
200 |
* @internalComponent
|
sl@0
|
201 |
*
|
sl@0
|
202 |
* Protected constructor
|
sl@0
|
203 |
* @param aType Tag type for the new object
|
sl@0
|
204 |
* @param aClass Tag class for the new object.
|
sl@0
|
205 |
*/
|
sl@0
|
206 |
CASN1EncConstructed(const TTagType aType, const TASN1Class aClass);
|
sl@0
|
207 |
|
sl@0
|
208 |
private:
|
sl@0
|
209 |
virtual const CASN1EncBase& Child(const TUint aIndex) const = 0;
|
sl@0
|
210 |
virtual TUint NumChildren() const = 0;
|
sl@0
|
211 |
|
sl@0
|
212 |
private:
|
sl@0
|
213 |
// From CASN1EncBase
|
sl@0
|
214 |
void CalculateContentsLengthDER();
|
sl@0
|
215 |
TBool IsConstructed() const;
|
sl@0
|
216 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
217 |
};
|
sl@0
|
218 |
|
sl@0
|
219 |
|
sl@0
|
220 |
/**
|
sl@0
|
221 |
* Class used to wrap other encoding objects in order to give
|
sl@0
|
222 |
* them an explicit tag.
|
sl@0
|
223 |
*
|
sl@0
|
224 |
* @publishedAll
|
sl@0
|
225 |
* @released
|
sl@0
|
226 |
*/
|
sl@0
|
227 |
class CASN1EncExplicitTag : public CASN1EncConstructed
|
sl@0
|
228 |
{
|
sl@0
|
229 |
public:
|
sl@0
|
230 |
/**
|
sl@0
|
231 |
* Takes ownership of the encoder, *including* the case when
|
sl@0
|
232 |
* this method leaves.
|
sl@0
|
233 |
* @param aEncoder ASN.1 encoding object to wrap
|
sl@0
|
234 |
* @param aType Tag type to assign
|
sl@0
|
235 |
* @param aClass Tag class to assign
|
sl@0
|
236 |
* @return Wrapped encoding object pushed on the cleanup stack.
|
sl@0
|
237 |
*/
|
sl@0
|
238 |
IMPORT_C static CASN1EncExplicitTag* NewLC(CASN1EncBase* aEncoder,
|
sl@0
|
239 |
const TTagType aType, const TASN1Class aClass = EContextSpecific);
|
sl@0
|
240 |
|
sl@0
|
241 |
/**
|
sl@0
|
242 |
* Takes ownership of the encoder, *including* the case when
|
sl@0
|
243 |
* this method leaves.
|
sl@0
|
244 |
* @param aEncoder ASN.1 encoding object to wrap
|
sl@0
|
245 |
* @param aType Tag type to assign
|
sl@0
|
246 |
* @param aClass Tag class to assign
|
sl@0
|
247 |
* @return Wrapped encoding object.
|
sl@0
|
248 |
*/
|
sl@0
|
249 |
IMPORT_C static CASN1EncExplicitTag* NewL(CASN1EncBase* aEncoder,
|
sl@0
|
250 |
const TTagType aType, const TASN1Class aClass = EContextSpecific);
|
sl@0
|
251 |
|
sl@0
|
252 |
IMPORT_C ~CASN1EncExplicitTag(); // virtual from base
|
sl@0
|
253 |
|
sl@0
|
254 |
private:
|
sl@0
|
255 |
CASN1EncExplicitTag(CASN1EncBase* aEncoder, const TTagType aType,
|
sl@0
|
256 |
const TASN1Class aClass);
|
sl@0
|
257 |
|
sl@0
|
258 |
// From CASN1EncConstructed
|
sl@0
|
259 |
TUint NumChildren() const;
|
sl@0
|
260 |
const CASN1EncBase& Child(const TUint aIndex) const;
|
sl@0
|
261 |
|
sl@0
|
262 |
private:
|
sl@0
|
263 |
CASN1EncBase* iEncoder; // Inner encoding object
|
sl@0
|
264 |
};
|
sl@0
|
265 |
|
sl@0
|
266 |
|
sl@0
|
267 |
/**
|
sl@0
|
268 |
* Base class for all ASN1 container types - sequences,
|
sl@0
|
269 |
* sets, etc.
|
sl@0
|
270 |
*
|
sl@0
|
271 |
* @publishedAll
|
sl@0
|
272 |
* @released
|
sl@0
|
273 |
*/
|
sl@0
|
274 |
class CASN1EncContainer : public CASN1EncConstructed
|
sl@0
|
275 |
{
|
sl@0
|
276 |
public:
|
sl@0
|
277 |
/**
|
sl@0
|
278 |
* Call this to add a child object to the container.
|
sl@0
|
279 |
* Takes ownership if and only if it doesn't Leave.
|
sl@0
|
280 |
* Checks for null input, calls AddChildInt, calls
|
sl@0
|
281 |
* ContentsLengthChanged().
|
sl@0
|
282 |
* @param aChild Child ASN1 encoding object to add.
|
sl@0
|
283 |
*/
|
sl@0
|
284 |
IMPORT_C void AddChildL(CASN1EncBase* aChild);
|
sl@0
|
285 |
|
sl@0
|
286 |
/**
|
sl@0
|
287 |
* Call this to add a child object to the container.
|
sl@0
|
288 |
* Takes ownership if and only if it doesn't Leave.
|
sl@0
|
289 |
* Checks for null input, calls AddChildInt, calls
|
sl@0
|
290 |
* ContentsLengthChanged(). Pops added child object
|
sl@0
|
291 |
* off the cleanup stack.
|
sl@0
|
292 |
* @param aChild Child ASN1 encoding object to add.
|
sl@0
|
293 |
*/
|
sl@0
|
294 |
IMPORT_C void AddAndPopChildL(CASN1EncBase* aChild);
|
sl@0
|
295 |
|
sl@0
|
296 |
protected:
|
sl@0
|
297 |
/** @internalComponent */
|
sl@0
|
298 |
CASN1EncContainer(const TTagType aType);
|
sl@0
|
299 |
|
sl@0
|
300 |
private:
|
sl@0
|
301 |
/**
|
sl@0
|
302 |
* Internal method, derived classes implement to add a child.
|
sl@0
|
303 |
* No need to check for null input or call
|
sl@0
|
304 |
* ContentsLengthChanged(). Takes ownership, but only if you
|
sl@0
|
305 |
* don't leave.
|
sl@0
|
306 |
* @param aChild Child encoding object to add.
|
sl@0
|
307 |
*/
|
sl@0
|
308 |
virtual void AddChildIntL(const CASN1EncBase* aChild) = 0;
|
sl@0
|
309 |
};
|
sl@0
|
310 |
|
sl@0
|
311 |
/**
|
sl@0
|
312 |
* Class for encoding SEQUENCE and SEQUENCE-OF data types.
|
sl@0
|
313 |
*
|
sl@0
|
314 |
* @publishedAll
|
sl@0
|
315 |
* @released
|
sl@0
|
316 |
*/
|
sl@0
|
317 |
class CASN1EncSequence : public CASN1EncContainer
|
sl@0
|
318 |
{
|
sl@0
|
319 |
public:
|
sl@0
|
320 |
IMPORT_C static CASN1EncSequence* NewL();
|
sl@0
|
321 |
IMPORT_C static CASN1EncSequence* NewLC();
|
sl@0
|
322 |
|
sl@0
|
323 |
IMPORT_C ~CASN1EncSequence(); // virtual from base
|
sl@0
|
324 |
|
sl@0
|
325 |
protected:
|
sl@0
|
326 |
/** @internalComponent */
|
sl@0
|
327 |
CASN1EncSequence();
|
sl@0
|
328 |
|
sl@0
|
329 |
private:
|
sl@0
|
330 |
// From CASN1EncContainer
|
sl@0
|
331 |
const CASN1EncBase& Child(const TUint aIndex) const;
|
sl@0
|
332 |
void AddChildIntL(const CASN1EncBase* aChild);
|
sl@0
|
333 |
TUint NumChildren() const;
|
sl@0
|
334 |
|
sl@0
|
335 |
private:
|
sl@0
|
336 |
RPointerArray<CASN1EncBase> iChildren;
|
sl@0
|
337 |
};
|
sl@0
|
338 |
|
sl@0
|
339 |
/**
|
sl@0
|
340 |
* Class for encoding SET and SET-OF data types.
|
sl@0
|
341 |
*
|
sl@0
|
342 |
* @publishedAll
|
sl@0
|
343 |
* @released
|
sl@0
|
344 |
*/
|
sl@0
|
345 |
class CASN1EncSet : public CASN1EncContainer
|
sl@0
|
346 |
{
|
sl@0
|
347 |
public:
|
sl@0
|
348 |
/**
|
sl@0
|
349 |
Creates an ASN.1 Set encoder.
|
sl@0
|
350 |
@return The fully constructed object.
|
sl@0
|
351 |
*/
|
sl@0
|
352 |
IMPORT_C static CASN1EncSet* NewL();
|
sl@0
|
353 |
|
sl@0
|
354 |
/**
|
sl@0
|
355 |
Creates an ASN.1 Set encoder, and puts it onto the cleanup stack.
|
sl@0
|
356 |
@return The fully constructed object.
|
sl@0
|
357 |
*/
|
sl@0
|
358 |
IMPORT_C static CASN1EncSet* NewLC();
|
sl@0
|
359 |
|
sl@0
|
360 |
/**
|
sl@0
|
361 |
Destructor.
|
sl@0
|
362 |
*/
|
sl@0
|
363 |
IMPORT_C ~CASN1EncSet(); // virtual from base
|
sl@0
|
364 |
|
sl@0
|
365 |
protected:
|
sl@0
|
366 |
/**
|
sl@0
|
367 |
* @internalComponent
|
sl@0
|
368 |
*
|
sl@0
|
369 |
* Constructor
|
sl@0
|
370 |
*/
|
sl@0
|
371 |
CASN1EncSet();
|
sl@0
|
372 |
|
sl@0
|
373 |
private:
|
sl@0
|
374 |
// From CASN1EncContainer
|
sl@0
|
375 |
const CASN1EncBase& Child(const TUint aIndex) const;
|
sl@0
|
376 |
void AddChildIntL(const CASN1EncBase* aChild);
|
sl@0
|
377 |
TUint NumChildren() const;
|
sl@0
|
378 |
|
sl@0
|
379 |
private:
|
sl@0
|
380 |
RPointerArray<CASN1EncBase> iChildren;
|
sl@0
|
381 |
};
|
sl@0
|
382 |
|
sl@0
|
383 |
|
sl@0
|
384 |
|
sl@0
|
385 |
/**
|
sl@0
|
386 |
* All ASN1 primitive type encoding classes derive from here.
|
sl@0
|
387 |
*
|
sl@0
|
388 |
* @publishedAll
|
sl@0
|
389 |
* @released
|
sl@0
|
390 |
*/
|
sl@0
|
391 |
class CASN1EncPrimitive : public CASN1EncBase
|
sl@0
|
392 |
{
|
sl@0
|
393 |
protected:
|
sl@0
|
394 |
IMPORT_C CASN1EncPrimitive(const TTagType aType);
|
sl@0
|
395 |
|
sl@0
|
396 |
private:
|
sl@0
|
397 |
TBool IsConstructed() const; ///< Inherited from CASN1EncBase
|
sl@0
|
398 |
};
|
sl@0
|
399 |
|
sl@0
|
400 |
|
sl@0
|
401 |
/**
|
sl@0
|
402 |
* Class for encoding NULLs.
|
sl@0
|
403 |
*
|
sl@0
|
404 |
* @publishedAll
|
sl@0
|
405 |
* @released
|
sl@0
|
406 |
*/
|
sl@0
|
407 |
class CASN1EncNull : public CASN1EncPrimitive
|
sl@0
|
408 |
{
|
sl@0
|
409 |
public:
|
sl@0
|
410 |
IMPORT_C static CASN1EncNull* NewL();
|
sl@0
|
411 |
IMPORT_C static CASN1EncNull* NewLC();
|
sl@0
|
412 |
|
sl@0
|
413 |
private:
|
sl@0
|
414 |
CASN1EncNull();
|
sl@0
|
415 |
|
sl@0
|
416 |
// Methods from CASN1EncBase
|
sl@0
|
417 |
void CalculateContentsLengthDER() ;
|
sl@0
|
418 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
419 |
};
|
sl@0
|
420 |
|
sl@0
|
421 |
|
sl@0
|
422 |
/**
|
sl@0
|
423 |
* Class for encoding Boolean values.
|
sl@0
|
424 |
*
|
sl@0
|
425 |
* @publishedAll
|
sl@0
|
426 |
* @released
|
sl@0
|
427 |
*/
|
sl@0
|
428 |
class CASN1EncBoolean : public CASN1EncPrimitive
|
sl@0
|
429 |
{
|
sl@0
|
430 |
public:
|
sl@0
|
431 |
IMPORT_C static CASN1EncBoolean* NewLC(const TBool aBool);
|
sl@0
|
432 |
IMPORT_C static CASN1EncBoolean* NewL(const TBool aBool);
|
sl@0
|
433 |
|
sl@0
|
434 |
private:
|
sl@0
|
435 |
CASN1EncBoolean(const TBool aBool);
|
sl@0
|
436 |
|
sl@0
|
437 |
// Methods from CASN1EncBase
|
sl@0
|
438 |
void CalculateContentsLengthDER() ;
|
sl@0
|
439 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
440 |
|
sl@0
|
441 |
const TBool iBool;
|
sl@0
|
442 |
};
|
sl@0
|
443 |
|
sl@0
|
444 |
|
sl@0
|
445 |
/**
|
sl@0
|
446 |
* Class for encoding TInts only. Use CASN1EncBigInt for encoding
|
sl@0
|
447 |
* Big Integer objects.
|
sl@0
|
448 |
*
|
sl@0
|
449 |
* @publishedAll
|
sl@0
|
450 |
* @released
|
sl@0
|
451 |
*/
|
sl@0
|
452 |
class CASN1EncInt : public CASN1EncPrimitive
|
sl@0
|
453 |
{
|
sl@0
|
454 |
public:
|
sl@0
|
455 |
IMPORT_C static CASN1EncInt* NewLC(const TInt aInt);
|
sl@0
|
456 |
IMPORT_C static CASN1EncInt* NewL(const TInt aInt);
|
sl@0
|
457 |
|
sl@0
|
458 |
private:
|
sl@0
|
459 |
CASN1EncInt(const TInt aInt);
|
sl@0
|
460 |
|
sl@0
|
461 |
// Methods from CASN1EncBase
|
sl@0
|
462 |
void CalculateContentsLengthDER() ;
|
sl@0
|
463 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
464 |
|
sl@0
|
465 |
private:
|
sl@0
|
466 |
const TInt iInt;
|
sl@0
|
467 |
};
|
sl@0
|
468 |
|
sl@0
|
469 |
|
sl@0
|
470 |
/**
|
sl@0
|
471 |
* Class for encoding Big Integer objects only - use CASN1EncInt
|
sl@0
|
472 |
* for TInts.
|
sl@0
|
473 |
*
|
sl@0
|
474 |
* @publishedAll
|
sl@0
|
475 |
* @released
|
sl@0
|
476 |
*/
|
sl@0
|
477 |
class CASN1EncBigInt : public CASN1EncPrimitive
|
sl@0
|
478 |
{
|
sl@0
|
479 |
public:
|
sl@0
|
480 |
// Takes a deep copy
|
sl@0
|
481 |
IMPORT_C static CASN1EncBigInt* NewLC(const TInteger& aInteger);
|
sl@0
|
482 |
IMPORT_C static CASN1EncBigInt* NewL(const TInteger& aInteger);
|
sl@0
|
483 |
|
sl@0
|
484 |
IMPORT_C ~CASN1EncBigInt(); // virtual from base
|
sl@0
|
485 |
|
sl@0
|
486 |
private:
|
sl@0
|
487 |
CASN1EncBigInt();
|
sl@0
|
488 |
void ConstructL(const TInteger& aInteger);
|
sl@0
|
489 |
|
sl@0
|
490 |
// Methods from CASN1EncBase
|
sl@0
|
491 |
void CalculateContentsLengthDER();
|
sl@0
|
492 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
493 |
|
sl@0
|
494 |
private:
|
sl@0
|
495 |
HBufC8* iContents;
|
sl@0
|
496 |
TPtrC8 iWriteContents;
|
sl@0
|
497 |
};
|
sl@0
|
498 |
|
sl@0
|
499 |
|
sl@0
|
500 |
/**
|
sl@0
|
501 |
* Class for encoding octet strings.
|
sl@0
|
502 |
*
|
sl@0
|
503 |
* @publishedAll
|
sl@0
|
504 |
* @released
|
sl@0
|
505 |
*/
|
sl@0
|
506 |
class CASN1EncOctetString : public CASN1EncPrimitive
|
sl@0
|
507 |
{
|
sl@0
|
508 |
public:
|
sl@0
|
509 |
// Takes a deep copy
|
sl@0
|
510 |
IMPORT_C static CASN1EncOctetString* NewLC(const TDesC8& aStr);
|
sl@0
|
511 |
IMPORT_C static CASN1EncOctetString* NewL(const TDesC8& aStr);
|
sl@0
|
512 |
|
sl@0
|
513 |
IMPORT_C ~CASN1EncOctetString(); // virtual from base
|
sl@0
|
514 |
|
sl@0
|
515 |
private:
|
sl@0
|
516 |
CASN1EncOctetString();
|
sl@0
|
517 |
void ConstructL(const TDesC8& aStr);
|
sl@0
|
518 |
|
sl@0
|
519 |
// Methods from CASN1EncBase
|
sl@0
|
520 |
void CalculateContentsLengthDER();
|
sl@0
|
521 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
522 |
|
sl@0
|
523 |
private:
|
sl@0
|
524 |
HBufC8* iContents;
|
sl@0
|
525 |
};
|
sl@0
|
526 |
|
sl@0
|
527 |
|
sl@0
|
528 |
/**
|
sl@0
|
529 |
* Class for encoding printable strings.
|
sl@0
|
530 |
*
|
sl@0
|
531 |
* @publishedAll
|
sl@0
|
532 |
* @released
|
sl@0
|
533 |
*/
|
sl@0
|
534 |
class CASN1EncPrintableString : public CASN1EncPrimitive
|
sl@0
|
535 |
{
|
sl@0
|
536 |
public:
|
sl@0
|
537 |
/**
|
sl@0
|
538 |
Creates an ASN.1 Printable String encoder, and puts it onto the cleanup stack.
|
sl@0
|
539 |
@return The fully constructed object.
|
sl@0
|
540 |
*/
|
sl@0
|
541 |
IMPORT_C static CASN1EncPrintableString* NewLC(const TDesC8& aStr);
|
sl@0
|
542 |
|
sl@0
|
543 |
/**
|
sl@0
|
544 |
Creates an ASN.1 Printable String encoder.
|
sl@0
|
545 |
@return The fully constructed object.
|
sl@0
|
546 |
*/
|
sl@0
|
547 |
IMPORT_C static CASN1EncPrintableString* NewL(const TDesC8& aStr);
|
sl@0
|
548 |
|
sl@0
|
549 |
/**
|
sl@0
|
550 |
Destructor.
|
sl@0
|
551 |
*/
|
sl@0
|
552 |
IMPORT_C ~CASN1EncPrintableString(); // virtual from base
|
sl@0
|
553 |
|
sl@0
|
554 |
private:
|
sl@0
|
555 |
CASN1EncPrintableString();
|
sl@0
|
556 |
void ConstructL(const TDesC8& aStr);
|
sl@0
|
557 |
TInt CheckValid(const TDesC8& aStr);
|
sl@0
|
558 |
|
sl@0
|
559 |
// Methods from CASN1EncBase
|
sl@0
|
560 |
void CalculateContentsLengthDER();
|
sl@0
|
561 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
562 |
|
sl@0
|
563 |
private:
|
sl@0
|
564 |
HBufC8* iContents;
|
sl@0
|
565 |
};
|
sl@0
|
566 |
|
sl@0
|
567 |
|
sl@0
|
568 |
/**
|
sl@0
|
569 |
* Class for encoding bit strings (keys, for example).
|
sl@0
|
570 |
*
|
sl@0
|
571 |
* @publishedAll
|
sl@0
|
572 |
* @released
|
sl@0
|
573 |
*/
|
sl@0
|
574 |
class CASN1EncBitString : public CASN1EncPrimitive
|
sl@0
|
575 |
{
|
sl@0
|
576 |
public:
|
sl@0
|
577 |
/**
|
sl@0
|
578 |
* Constructs a new DER bit string encoder from a bit string that
|
sl@0
|
579 |
* does not have unused bits at the end, i.e. is octet-aligned.
|
sl@0
|
580 |
* The passed string must be in big-endian format.
|
sl@0
|
581 |
* @param aBitStr Octet-aligned bit string.
|
sl@0
|
582 |
* @return A new DER bit string encoder object,
|
sl@0
|
583 |
* which is left on the cleanup stack.
|
sl@0
|
584 |
*/
|
sl@0
|
585 |
IMPORT_C static CASN1EncBitString* NewLC(const TDesC8& aBitStr);
|
sl@0
|
586 |
|
sl@0
|
587 |
/**
|
sl@0
|
588 |
* Constructs a new DER bit string encoder from a bit string that
|
sl@0
|
589 |
* does not have unused bits at the end, i.e. is octet-aligned.
|
sl@0
|
590 |
* The passed string must be in big-endian format.
|
sl@0
|
591 |
* @param aBitStr Octet-aligned bit string.
|
sl@0
|
592 |
* @return A new DER bit string encoder object.
|
sl@0
|
593 |
*/
|
sl@0
|
594 |
IMPORT_C static CASN1EncBitString* NewL(const TDesC8& aBitStr);
|
sl@0
|
595 |
|
sl@0
|
596 |
/**
|
sl@0
|
597 |
* Constructs a new DER bit string encoder from a bit string that
|
sl@0
|
598 |
* is not octet-aligned, which means it has unused bits in its last
|
sl@0
|
599 |
* octet. The passed string must be in big-endian format.
|
sl@0
|
600 |
* @param aBitStr Bit string.
|
sl@0
|
601 |
* @param aLengthBits Length in bits of the passed bit string.
|
sl@0
|
602 |
* The function will panic if aLengthBits is greater than
|
sl@0
|
603 |
* the actual bit length of aBitString, or the difference
|
sl@0
|
604 |
* is more that 7 bits.
|
sl@0
|
605 |
* @return A new DER bit string encoder object which is left on the
|
sl@0
|
606 |
* cleanup stack.
|
sl@0
|
607 |
*/
|
sl@0
|
608 |
IMPORT_C static CASN1EncBitString* NewLC(const TDesC8& aBitStr, TUint aLengthBits);
|
sl@0
|
609 |
|
sl@0
|
610 |
/**
|
sl@0
|
611 |
* Constructs a new DER bit string encoder from a bit string that
|
sl@0
|
612 |
* is not octet-aligned, which means it has unused bits in its last
|
sl@0
|
613 |
* octet. The passed string must be in big-endian format.
|
sl@0
|
614 |
* @param aBitStr Bit string.
|
sl@0
|
615 |
* @param aLengthBits Length in bits of the passed bit string.
|
sl@0
|
616 |
* The function will panic if aLengthBits is greater than
|
sl@0
|
617 |
* the actual bit length of aBitString, or the difference
|
sl@0
|
618 |
* is more that 7 bits.
|
sl@0
|
619 |
* @return A new DER bit string encoder object.
|
sl@0
|
620 |
*/
|
sl@0
|
621 |
IMPORT_C static CASN1EncBitString* NewL(const TDesC8& aBitStr, TUint aLengthBits);
|
sl@0
|
622 |
|
sl@0
|
623 |
/**
|
sl@0
|
624 |
* Wraps the passed encoding object into a bit string.
|
sl@0
|
625 |
* @param aAsnObj Encoding object to wrap.
|
sl@0
|
626 |
* @return A new bit string containing the passed encoding object.
|
sl@0
|
627 |
*/
|
sl@0
|
628 |
IMPORT_C static CASN1EncBitString* NewL(const CASN1EncBase& aAsnObj);
|
sl@0
|
629 |
|
sl@0
|
630 |
/**
|
sl@0
|
631 |
* Wraps the passed encoding object into a bit string.
|
sl@0
|
632 |
* @param aAsnObj Encoding object to wrap.
|
sl@0
|
633 |
* @return A new bit string containing the passed encoding object
|
sl@0
|
634 |
* on the cleanup stack.
|
sl@0
|
635 |
*/
|
sl@0
|
636 |
IMPORT_C static CASN1EncBitString* NewLC(const CASN1EncBase& aAsnObj);
|
sl@0
|
637 |
|
sl@0
|
638 |
IMPORT_C ~CASN1EncBitString(); // virtual from base
|
sl@0
|
639 |
|
sl@0
|
640 |
private:
|
sl@0
|
641 |
CASN1EncBitString();
|
sl@0
|
642 |
void ConstructL(const TDesC8& aBitStr);
|
sl@0
|
643 |
void ConstructL(const TDesC8& aBitStr, TUint aLengthBits);
|
sl@0
|
644 |
void ConstructL(const CASN1EncBase& aAsnObj);
|
sl@0
|
645 |
|
sl@0
|
646 |
// Methods from CASN1EncBase
|
sl@0
|
647 |
void CalculateContentsLengthDER();
|
sl@0
|
648 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
649 |
|
sl@0
|
650 |
private:
|
sl@0
|
651 |
HBufC8* iContents;
|
sl@0
|
652 |
TUint8 iPadding;
|
sl@0
|
653 |
};
|
sl@0
|
654 |
|
sl@0
|
655 |
/**
|
sl@0
|
656 |
* Class for encoding object identifiers.
|
sl@0
|
657 |
*
|
sl@0
|
658 |
* @publishedAll
|
sl@0
|
659 |
* @released
|
sl@0
|
660 |
*/
|
sl@0
|
661 |
class CASN1EncObjectIdentifier : public CASN1EncPrimitive
|
sl@0
|
662 |
{
|
sl@0
|
663 |
public:
|
sl@0
|
664 |
/**
|
sl@0
|
665 |
* Takes ints in a string, delimited by '.' characters in
|
sl@0
|
666 |
* between (not at ends). Takes a deep copy of the info.
|
sl@0
|
667 |
* @param aStr OID string.
|
sl@0
|
668 |
* @return New ASN.1 OID object on the cleanup stack.
|
sl@0
|
669 |
*/
|
sl@0
|
670 |
IMPORT_C static CASN1EncObjectIdentifier* NewLC(const TDesC& aStr);
|
sl@0
|
671 |
|
sl@0
|
672 |
/**
|
sl@0
|
673 |
* Takes ints in a string, delimited by '.' characters in
|
sl@0
|
674 |
* between (not at ends). Takes a deep copy of the info.
|
sl@0
|
675 |
* @param aStr OID string.
|
sl@0
|
676 |
* @return New ASN.1 OID object.
|
sl@0
|
677 |
*/
|
sl@0
|
678 |
IMPORT_C static CASN1EncObjectIdentifier* NewL(const TDesC& aStr);
|
sl@0
|
679 |
|
sl@0
|
680 |
/** Destructor */
|
sl@0
|
681 |
IMPORT_C ~CASN1EncObjectIdentifier(); // virtual from base
|
sl@0
|
682 |
|
sl@0
|
683 |
private:
|
sl@0
|
684 |
CASN1EncObjectIdentifier();
|
sl@0
|
685 |
void ConstructL(const TDesC& aStr);
|
sl@0
|
686 |
|
sl@0
|
687 |
// Methods from CASN1EncBase
|
sl@0
|
688 |
void CalculateContentsLengthDER();
|
sl@0
|
689 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
690 |
|
sl@0
|
691 |
private:
|
sl@0
|
692 |
// Data to encode
|
sl@0
|
693 |
RArray<TASN1EncBase128DER> iData;
|
sl@0
|
694 |
TUint8 iFirstOctet;
|
sl@0
|
695 |
};
|
sl@0
|
696 |
|
sl@0
|
697 |
|
sl@0
|
698 |
/**
|
sl@0
|
699 |
* Class for encoding GeneralisedTime objects.
|
sl@0
|
700 |
*
|
sl@0
|
701 |
* Doesn't support fractions of seconds or regional time zone offsets.
|
sl@0
|
702 |
*
|
sl@0
|
703 |
* @publishedAll
|
sl@0
|
704 |
* @released
|
sl@0
|
705 |
*/
|
sl@0
|
706 |
class CASN1EncGeneralizedTime : public CASN1EncPrimitive
|
sl@0
|
707 |
{
|
sl@0
|
708 |
public:
|
sl@0
|
709 |
IMPORT_C static CASN1EncGeneralizedTime* NewLC(const TTime& aTime);
|
sl@0
|
710 |
IMPORT_C static CASN1EncGeneralizedTime* NewL(const TTime& aTime);
|
sl@0
|
711 |
|
sl@0
|
712 |
private:
|
sl@0
|
713 |
CASN1EncGeneralizedTime(const TTime& aTime);
|
sl@0
|
714 |
|
sl@0
|
715 |
// Methods from CASN1EncBase
|
sl@0
|
716 |
void CalculateContentsLengthDER();
|
sl@0
|
717 |
void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
718 |
|
sl@0
|
719 |
private:
|
sl@0
|
720 |
TDateTime iDateTime;
|
sl@0
|
721 |
};
|
sl@0
|
722 |
|
sl@0
|
723 |
/**
|
sl@0
|
724 |
* Class for encapsulation of already encoded data.
|
sl@0
|
725 |
*
|
sl@0
|
726 |
* Wraps it so that the data could be used in the ASN.1 hierarchy.
|
sl@0
|
727 |
* It reverse-engineers and stores the encoded data, providing whatever
|
sl@0
|
728 |
* information is needed to override pure virtual methods of the base
|
sl@0
|
729 |
* class and write out the DER encoding in its initial form.
|
sl@0
|
730 |
*
|
sl@0
|
731 |
* @publishedAll
|
sl@0
|
732 |
* @released
|
sl@0
|
733 |
*/
|
sl@0
|
734 |
class CASN1EncEncoding : public CASN1EncBase
|
sl@0
|
735 |
{
|
sl@0
|
736 |
public:
|
sl@0
|
737 |
/**
|
sl@0
|
738 |
* Creates a new object from raw DER encoding and places it on the
|
sl@0
|
739 |
* cleanup stack.
|
sl@0
|
740 |
* @param aEncoding Raw DER encoding.
|
sl@0
|
741 |
* @return New wrapper object placed on the cleanup stack.
|
sl@0
|
742 |
*/
|
sl@0
|
743 |
IMPORT_C static CASN1EncEncoding* NewLC(const TDesC8& aEncoding);
|
sl@0
|
744 |
|
sl@0
|
745 |
/**
|
sl@0
|
746 |
* Creates a new object from raw DER encoding.
|
sl@0
|
747 |
* @param aEncoding Raw DER encoding.
|
sl@0
|
748 |
* @return New wrapper object.
|
sl@0
|
749 |
*/
|
sl@0
|
750 |
IMPORT_C static CASN1EncEncoding* NewL(const TDesC8& aEncoding);
|
sl@0
|
751 |
|
sl@0
|
752 |
IMPORT_C static CASN1EncEncoding* NewLC(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass);
|
sl@0
|
753 |
|
sl@0
|
754 |
IMPORT_C ~CASN1EncEncoding();
|
sl@0
|
755 |
|
sl@0
|
756 |
protected:
|
sl@0
|
757 |
/**
|
sl@0
|
758 |
* Protected constructor.
|
sl@0
|
759 |
* <!--
|
sl@0
|
760 |
* @param aType Tag type of the new object
|
sl@0
|
761 |
* @param aClass Tag class of the new object.
|
sl@0
|
762 |
* -->
|
sl@0
|
763 |
*/
|
sl@0
|
764 |
IMPORT_C CASN1EncEncoding();
|
sl@0
|
765 |
|
sl@0
|
766 |
private:
|
sl@0
|
767 |
/**
|
sl@0
|
768 |
* Constructs the wrapper around the passed raw DER encoding.
|
sl@0
|
769 |
* Calculates element sizes. Decodes it to get type and length.
|
sl@0
|
770 |
* @param aEncoding Raw DER encoding.
|
sl@0
|
771 |
*/
|
sl@0
|
772 |
void ConstructL(const TDesC8& aEncoding);
|
sl@0
|
773 |
|
sl@0
|
774 |
void ConstructL(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass);
|
sl@0
|
775 |
|
sl@0
|
776 |
virtual TBool IsConstructed() const;
|
sl@0
|
777 |
|
sl@0
|
778 |
/**
|
sl@0
|
779 |
* Writes DER content encoding into supplied buffer, which is
|
sl@0
|
780 |
* already verified to be big enough.
|
sl@0
|
781 |
* @param aBuf Buffer to write to.
|
sl@0
|
782 |
*/
|
sl@0
|
783 |
virtual void WriteContentsDERL(TDes8& aBuf) const;
|
sl@0
|
784 |
|
sl@0
|
785 |
/**
|
sl@0
|
786 |
* Calculates number of octets in DER content encoding. Sets
|
sl@0
|
787 |
* value of the appropriate data member.
|
sl@0
|
788 |
*/
|
sl@0
|
789 |
virtual void CalculateContentsLengthDER();
|
sl@0
|
790 |
|
sl@0
|
791 |
private:
|
sl@0
|
792 |
HBufC8* iContents; ///< Copy of the supplied DER encoded data (contents only).
|
sl@0
|
793 |
TASN1Class iClass; ///< ASN.1 class of the encoded object.
|
sl@0
|
794 |
TTagType iTag; ///< ASN.1 tag of the encoding.
|
sl@0
|
795 |
};
|
sl@0
|
796 |
|
sl@0
|
797 |
#endif // __ASN1ENC_H__
|