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