1 | /** @file
|
---|
2 | * IPRT - Abstract Syntax Notation One (ASN.1).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2015 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_asn1_h
|
---|
27 | #define ___iprt_asn1_h
|
---|
28 |
|
---|
29 | #include <iprt/time.h>
|
---|
30 | #include <iprt/stdarg.h>
|
---|
31 | #include <iprt/err.h>
|
---|
32 | #include <iprt/formats/asn1.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | RT_C_DECLS_BEGIN
|
---|
36 |
|
---|
37 | /** @defgroup grp_rt_asn1 RTAsn1 - Abstract Syntax Notation One
|
---|
38 | * @ingroup grp_rt
|
---|
39 | * @{
|
---|
40 | */
|
---|
41 |
|
---|
42 |
|
---|
43 | /** Pointer to ASN.1 allocation information. */
|
---|
44 | typedef struct RTASN1ALLOCATION *PRTASN1ALLOCATION;
|
---|
45 | /** Pointer to a ASN.1 byte decoder cursor. */
|
---|
46 | typedef struct RTASN1CURSOR *PRTASN1CURSOR;
|
---|
47 |
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Sketch of a custom ASN.1 allocator virtual method table.
|
---|
51 | *
|
---|
52 | * Any information required by the allocator should be associated with this
|
---|
53 | * structure, i.e. use this as a kind of parent class. This saves storage in
|
---|
54 | * RTASN1ALLOCATORINFO and possibly reduces the number of parameters by one.
|
---|
55 | */
|
---|
56 | typedef struct RTASN1ALLOCATORVTABLE
|
---|
57 | {
|
---|
58 | /**
|
---|
59 | * Free a chunk of memory allocated by this allocator.
|
---|
60 | *
|
---|
61 | * @returns IPRT status code.
|
---|
62 | * @param pThis Pointer to the vtable structure.
|
---|
63 | * @param pAllocation Pointer to the allocation info structure.
|
---|
64 | * @param pv Pointer to the memory that shall be freed. Not NULL.
|
---|
65 | */
|
---|
66 | DECLCALLBACKMEMBER(void, pfnFree)(struct RTASN1ALLOCATORVTABLE const *pThis, PRTASN1ALLOCATION pAllocation,
|
---|
67 | void *pv);
|
---|
68 | /**
|
---|
69 | * Allocates a chunk of memory, all initialized to zero.
|
---|
70 | *
|
---|
71 | * @returns IPRT status code.
|
---|
72 | * @param pThis Pointer to the vtable structure.
|
---|
73 | * @param pAllocation Pointer to the allocation info structure.
|
---|
74 | * @param ppv Where to store the pointer on success.
|
---|
75 | * @param cb The minimum number of bytes to allocate. The actual
|
---|
76 | * number of bytes allocated shall be stored in
|
---|
77 | * pInfo->cbAllocated on success.
|
---|
78 | */
|
---|
79 | DECLCALLBACKMEMBER(int, pfnAlloc)(struct RTASN1ALLOCATORVTABLE const *pThis, PRTASN1ALLOCATION pAllocation,
|
---|
80 | void **ppv, size_t cb);
|
---|
81 | /**
|
---|
82 | * Reallocates a memory allocation.
|
---|
83 | *
|
---|
84 | * New memory does not need to be initialized, the caller takes care of that.
|
---|
85 | *
|
---|
86 | * This will not need to deal with free (@a cbNew == 0) or the initial
|
---|
87 | * allocation (@a pvOld == NULL), those calls will be directed to pfnFree and
|
---|
88 | * pfnAlloc respectively.
|
---|
89 | *
|
---|
90 | * @returns IPRT status code.
|
---|
91 | * @param pThis Pointer to the vtable structure.
|
---|
92 | * @param pAllocation Pointer to the allocation info structure.
|
---|
93 | * @param pvOld Pointer to the current allocation. Shall remain
|
---|
94 | * valid on failure, but may be invalid on success.
|
---|
95 | * @param ppvNew Where to store the pointer on success. Shall not be
|
---|
96 | * touched, except on successful returns.
|
---|
97 | * @param cbNew The new minimum allocation size. The actual number
|
---|
98 | * of bytes allocated shall be stored in
|
---|
99 | * pInfo->cbAllocated on success.
|
---|
100 | */
|
---|
101 | DECLCALLBACKMEMBER(int, pfnRealloc)(struct RTASN1ALLOCATORVTABLE const *pThis, PRTASN1ALLOCATION pAllocation,
|
---|
102 | void *pvOld, void **ppvNew, size_t cbNew);
|
---|
103 | } RTASN1ALLOCATORVTABLE;
|
---|
104 | /** Pointer to an ASN.1 allocator vtable. */
|
---|
105 | typedef RTASN1ALLOCATORVTABLE *PRTASN1ALLOCATORVTABLE;
|
---|
106 | /** Pointer to a const ASN.1 allocator vtable. */
|
---|
107 | typedef RTASN1ALLOCATORVTABLE const *PCRTASN1ALLOCATORVTABLE;
|
---|
108 |
|
---|
109 | /** The default ASN.1 allocator. */
|
---|
110 | extern RTDATADECL(RTASN1ALLOCATORVTABLE const) g_RTAsn1DefaultAllocator;
|
---|
111 |
|
---|
112 | /** The Electric Fence ASN.1 allocator. */
|
---|
113 | extern RTDATADECL(RTASN1ALLOCATORVTABLE const) g_RTAsn1EFenceAllocator;
|
---|
114 |
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Allocation information.
|
---|
118 | */
|
---|
119 | typedef struct RTASN1ALLOCATION
|
---|
120 | {
|
---|
121 | /** The number of bytes currently allocated. */
|
---|
122 | uint32_t cbAllocated;
|
---|
123 | /** Number of realloc calls. */
|
---|
124 | uint16_t cReallocs;
|
---|
125 | /** Reserved / padding. */
|
---|
126 | uint16_t uReserved0;
|
---|
127 | /** Allocator vtable, NULL for the default allocator. */
|
---|
128 | PCRTASN1ALLOCATORVTABLE pAllocator;
|
---|
129 | } RTASN1ALLOCATION;
|
---|
130 |
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Grow an array by zero initialized memory.
|
---|
134 | *
|
---|
135 | * @returns IPRT status code.
|
---|
136 | * @param pAllocation The allocation record (initialized by
|
---|
137 | * RTAsn1CursorInitAllocation or similar).
|
---|
138 | * @param ppvArray Pointer to the variable pointing to the array. This is
|
---|
139 | * both input and output. Remains valid on failure.
|
---|
140 | * @param cbEntry The size of an array entry.
|
---|
141 | * @param cCurrent The current entry count. (Relevant for zero
|
---|
142 | * initialization of the new entries.)
|
---|
143 | * @param cNew The new entry count.
|
---|
144 | */
|
---|
145 | RTDECL(int) RTAsn1MemGrowArray(PRTASN1ALLOCATION pAllocation, void **ppvArray, size_t cbEntry,
|
---|
146 | uint32_t cCurrent, uint32_t cNew);
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Allocate a block of zero initialized memory.
|
---|
150 | *
|
---|
151 | * @returns IPRT status code.
|
---|
152 | * @param pAllocation The allocation record (initialized by
|
---|
153 | * RTAsn1CursorInitAllocation or similar).
|
---|
154 | * @param ppvMem Where to return the pointer to the block.
|
---|
155 | * @param cbMem The minimum number of bytes to allocate.
|
---|
156 | */
|
---|
157 | RTDECL(int) RTAsn1MemAllocZ(PRTASN1ALLOCATION pAllocation, void **ppvMem, size_t cbMem);
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Allocates a block of memory initialized to the content of @a pvSrc.
|
---|
161 | *
|
---|
162 | * @returns IPRT status code.
|
---|
163 | * @param pAllocation The allocation record (initialized by
|
---|
164 | * RTAsn1CursorInitAllocation or similar).
|
---|
165 | * @param ppvMem Where to return the pointer to the block.
|
---|
166 | * @param pvSrc The source memory.
|
---|
167 | * @param cbMem The minimum number of bytes to allocate.
|
---|
168 | */
|
---|
169 | RTDECL(int) RTAsn1MemDup(PRTASN1ALLOCATION pAllocation, void **ppvMem, void const *pvSrc, size_t cbMem);
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Free a memory block.
|
---|
173 | *
|
---|
174 | * @param pAllocation The allocation record (initialized by
|
---|
175 | * RTAsn1CursorInitAllocation or similar).
|
---|
176 | * @param pv The memory block to free. NULL will be ignored.
|
---|
177 | */
|
---|
178 | RTDECL(void) RTAsn1MemFree(PRTASN1ALLOCATION pAllocation, void *pv);
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Initalize an allocation.
|
---|
182 | *
|
---|
183 | * @param pAllocation The allocation record (initialized by
|
---|
184 | * RTAsn1CursorInitAllocation or similar).
|
---|
185 | * @param pAllocator The allocator
|
---|
186 | */
|
---|
187 | RTDECL(PRTASN1ALLOCATION) RTAsn1MemInitAllocation(PRTASN1ALLOCATION pAllocation, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
188 |
|
---|
189 | RTDECL(int) RTAsn1ContentAllocZ(struct RTASN1CORE *pAsn1Core, size_t cb, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
190 | RTDECL(int) RTAsn1ContentDup(struct RTASN1CORE *pAsn1Core, void const *pvSrc, size_t cbSrc, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
191 | RTDECL(int) RTAsn1ContentReallocZ(struct RTASN1CORE *pAsn1Core, size_t cb, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
192 | RTDECL(void) RTAsn1ContentFree(struct RTASN1CORE *pAsn1Core);
|
---|
193 |
|
---|
194 |
|
---|
195 |
|
---|
196 | /** Pointer to a core ASN.1 encoding info structure. */
|
---|
197 | typedef struct RTASN1CORE *PRTASN1CORE;
|
---|
198 | /** Pointer to a const core ASN.1 encoding info structure. */
|
---|
199 | typedef struct RTASN1CORE const *PCRTASN1CORE;
|
---|
200 |
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * ASN.1 object enumeration callback.
|
---|
204 | *
|
---|
205 | * @returns IPRT status code. VINF_SUCCESS continues the enumberation, all
|
---|
206 | * others quit it and is returned to the caller's caller.
|
---|
207 | * @param pAsn1Core The ASN.1 object we're called back about.
|
---|
208 | * @param pszName The member name. Array member names ends with
|
---|
209 | * '[#]'.
|
---|
210 | * @param uDepth The current depth.
|
---|
211 | * @param pvUser Callback user parameter.
|
---|
212 | */
|
---|
213 | typedef DECLCALLBACK(int) FNRTASN1ENUMCALLBACK(struct RTASN1CORE *pAsn1Core, const char *pszName, uint32_t uDepth, void *pvUser);
|
---|
214 | /** Pointer to an ASN.1 object enumeration callback. */
|
---|
215 | typedef FNRTASN1ENUMCALLBACK *PFNRTASN1ENUMCALLBACK;
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * ASN.1 object encoding writer callback.
|
---|
219 | *
|
---|
220 | * @returns IPRT status code.
|
---|
221 | * @param pbBuf Pointer to the bytes to output.
|
---|
222 | * @param cbToWrite The number of bytes to write.
|
---|
223 | * @param pvUser Callback user parameter.
|
---|
224 | * @param pErrInfo Where to store extended error info. Optional.
|
---|
225 | */
|
---|
226 | typedef DECLCALLBACK(int) FNRTASN1ENCODEWRITER(const void *pvBuf, size_t cbToWrite, void *pvUser, PRTERRINFO pErrInfo);
|
---|
227 | /** Pointer to an ASN.1 encoding writer callback. */
|
---|
228 | typedef FNRTASN1ENCODEWRITER *PFNRTASN1ENCODEWRITER;
|
---|
229 |
|
---|
230 | /** @name ASN.1 Vtable Method Types
|
---|
231 | * @{ */
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Destructor.
|
---|
235 | *
|
---|
236 | * RTAsn1Destroy will first destroy all children by recursive calls to pfnEnum,
|
---|
237 | * afterwards it will call this method to release any memory or other resources
|
---|
238 | * associated with this object. The memory backing the object structure shall
|
---|
239 | * not be freed by this method.
|
---|
240 | *
|
---|
241 | * @param pThisCore Pointer to the ASN.1 core to destroy.
|
---|
242 | */
|
---|
243 | typedef DECLCALLBACK(void) FNRTASN1COREVTDTOR(PRTASN1CORE pThisCore);
|
---|
244 | /** Pointer to a FNRTASN1COREVTDTOR method. */
|
---|
245 | typedef FNRTASN1COREVTDTOR *PFNRTASN1COREVTDTOR;
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * Enumerate members (not necessary for primitive objects).
|
---|
249 | *
|
---|
250 | * @returns IPRT status code, any non VINF_SUCCESS value stems from pfnCallback.
|
---|
251 | * @param pThisCore Pointer to the ASN.1 core to enumerate members of.
|
---|
252 | * @param pfnCallback The callback.
|
---|
253 | * @param uDepth The depth of this object. Children are at +1.
|
---|
254 | * @param pvUser Callback user argument.
|
---|
255 | */
|
---|
256 | typedef DECLCALLBACK(int) FNRTASN1COREVTENUM(PRTASN1CORE pThisCore, PFNRTASN1ENUMCALLBACK pfnCallback,
|
---|
257 | uint32_t uDepth, void *pvUser);
|
---|
258 | /** Pointer to a FNRTASN1COREVTENUM method. */
|
---|
259 | typedef FNRTASN1COREVTENUM *PFNRTASN1COREVTENUM;
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * Clone method.
|
---|
263 | *
|
---|
264 | * @param pThisCore Pointer to the ASN.1 core to initialize as a clone
|
---|
265 | * of pSrcClone. (The caller is responsible for making
|
---|
266 | * sure there is sufficent space and such.)
|
---|
267 | * @param pSrcCore The object to clone.
|
---|
268 | * @param pAllocator The allocator to use.
|
---|
269 | */
|
---|
270 | typedef DECLCALLBACK(int) FNRTASN1COREVTCLONE(PRTASN1CORE pThisCore, PCRTASN1CORE pSrcCore, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
271 | /** Pointer to a FNRTASN1COREVTCLONE method. */
|
---|
272 | typedef FNRTASN1COREVTCLONE *PFNRTASN1COREVTCLONE;
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Compare method.
|
---|
276 | *
|
---|
277 | * The caller makes sure both cores are present and have the same Vtable.
|
---|
278 | *
|
---|
279 | * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
|
---|
280 | * @param pLeftCore Pointer to the ASN.1 core of the left side object.
|
---|
281 | * @param pRightCore Pointer to the ASN.1 core of the right side object.
|
---|
282 | */
|
---|
283 | typedef DECLCALLBACK(int) FNRTASN1COREVTCOMPARE(PCRTASN1CORE pLeftCore, PCRTASN1CORE pRightCore);
|
---|
284 | /** Pointer to a FNRTASN1COREVTCOMPARE method. */
|
---|
285 | typedef FNRTASN1COREVTCOMPARE *PFNRTASN1COREVTCOMPARE;
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * Check sanity method.
|
---|
289 | *
|
---|
290 | * @returns IPRT status code.
|
---|
291 | * @param pThisCore Pointer to the ASN.1 core of the object to check out.
|
---|
292 | * @param fFlags See RTASN1_CHECK_SANITY_F_XXX.
|
---|
293 | * @param pszErrInfo Where to return additional error details. Optional.
|
---|
294 | * @param pszErrorTag Tag for the additional error details.
|
---|
295 | */
|
---|
296 | typedef DECLCALLBACK(int) FNRTASN1COREVTCHECKSANITY(PCRTASN1CORE pThisCore, uint32_t fFlags,
|
---|
297 | PRTERRINFO pErrInfo, const char *pszErrorTag);
|
---|
298 | /** Pointer to a FNRTASN1COREVTCHECKSANITY method. */
|
---|
299 | typedef FNRTASN1COREVTCHECKSANITY *PFNRTASN1COREVTCHECKSANITY;
|
---|
300 |
|
---|
301 | /**
|
---|
302 | * Optional encoding preparations.
|
---|
303 | *
|
---|
304 | * On successful return, the pThisCore->cb value shall be valid and up to date.
|
---|
305 | * Will be called for any present object, including ones with default values and
|
---|
306 | * similar.
|
---|
307 | *
|
---|
308 | * @returns IPRT status code
|
---|
309 | * @param pThisCore Pointer to the ASN.1 core to enumerate members of.
|
---|
310 | * @param fFlags Encoding flags, RTASN1ENCODE_F_XXX.
|
---|
311 | * @param pErrInfo Where to return extra error information. Optional.
|
---|
312 | */
|
---|
313 | typedef DECLCALLBACK(int) FNRTASN1COREVTENCODEPREP(PRTASN1CORE pThisCore, uint32_t fFlags, PRTERRINFO pErrInfo);
|
---|
314 | /** Pointer to a FNRTASN1COREVTENCODEWRITE method. */
|
---|
315 | typedef FNRTASN1COREVTENCODEPREP *PFNRTASN1COREVTENCODEPREP;
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Optional encoder writer.
|
---|
319 | *
|
---|
320 | * This writes the header as well as all the content. Will be called for any
|
---|
321 | * present object, including ones with default values and similar.
|
---|
322 | *
|
---|
323 | * @returns IPRT status code.
|
---|
324 | * @param pThisCore Pointer to the ASN.1 core to enumerate members of.
|
---|
325 | * @param fFlags Encoding flags, RTASN1ENCODE_F_XXX.
|
---|
326 | * @param pfnWriter The output writer function.
|
---|
327 | * @param pvUser The user context for the writer function.
|
---|
328 | * @param pErrInfo Where to return extra error information. Optional.
|
---|
329 | */
|
---|
330 | typedef DECLCALLBACK(int) FNRTASN1COREVTENCODEWRITE(PRTASN1CORE pThisCore, uint32_t fFlags, PFNRTASN1ENCODEWRITER pfnWriter,
|
---|
331 | void *pvUser, PRTERRINFO pErrInfo);
|
---|
332 | /** Pointer to a FNRTASN1COREVTENCODEWRITE method. */
|
---|
333 | typedef FNRTASN1COREVTENCODEWRITE *PFNRTASN1COREVTENCODEWRITE;
|
---|
334 | /** @} */
|
---|
335 |
|
---|
336 | /** Mask of common flags. These will be propagated during sanity checking.
|
---|
337 | * Bits not in this mask are type specfic. */
|
---|
338 | #define RTASN1_CHECK_SANITY_F_COMMON_MASK UINT32_C(0xffff0000)
|
---|
339 |
|
---|
340 | /**
|
---|
341 | * ASN.1 core vtable.
|
---|
342 | */
|
---|
343 | typedef struct RTASN1COREVTABLE
|
---|
344 | {
|
---|
345 | /** The name. */
|
---|
346 | const char *pszName;
|
---|
347 | /** Size of the structure. */
|
---|
348 | uint32_t cbStruct;
|
---|
349 | /** The default tag, UINT8_MAX if not applicable. */
|
---|
350 | uint8_t uDefaultTag;
|
---|
351 | /** The default class and flags. */
|
---|
352 | uint8_t fDefaultClass;
|
---|
353 | /** Reserved for later / alignment. */
|
---|
354 | uint16_t uReserved;
|
---|
355 | /** @copydoc FNRTASN1COREVTDTOR */
|
---|
356 | PFNRTASN1COREVTDTOR pfnDtor;
|
---|
357 | /** @copydoc FNRTASN1COREVTENUM */
|
---|
358 | PFNRTASN1COREVTENUM pfnEnum;
|
---|
359 | /** @copydoc FNRTASN1COREVTCLONE */
|
---|
360 | PFNRTASN1COREVTCLONE pfnClone;
|
---|
361 | /** @copydoc FNRTASN1COREVTCOMPARE */
|
---|
362 | PFNRTASN1COREVTCOMPARE pfnCompare;
|
---|
363 | /** @copydoc FNRTASN1COREVTCHECKSANITY */
|
---|
364 | PFNRTASN1COREVTCHECKSANITY pfnCheckSanity;
|
---|
365 | /** @copydoc FNRTASN1COREVTENCODEPREP */
|
---|
366 | PFNRTASN1COREVTENCODEPREP pfnEncodePrep;
|
---|
367 | /** @copydoc FNRTASN1COREVTENUM */
|
---|
368 | PFNRTASN1COREVTENCODEWRITE pfnEncodeWrite;
|
---|
369 | } RTASN1COREVTABLE;
|
---|
370 | /** Pointer to an ASN.1 allocator vtable. */
|
---|
371 | typedef struct RTASN1COREVTABLE *PRTASN1COREVTABLE;
|
---|
372 | /** Pointer to a const ASN.1 allocator vtable. */
|
---|
373 | typedef RTASN1COREVTABLE const *PCRTASN1COREVTABLE;
|
---|
374 |
|
---|
375 |
|
---|
376 | /** @name Helper macros for prototyping standard functions for an ASN.1 type.
|
---|
377 | * @{ */
|
---|
378 | #define RTASN1TYPE_STANDARD_PROTOTYPES_NO_GET_CORE(a_TypeNm, a_DeclMacro, a_ImplExtNm) \
|
---|
379 | a_DeclMacro(int) RT_CONCAT(a_ImplExtNm,_Init)(RT_CONCAT(P,a_TypeNm) pThis, PCRTASN1ALLOCATORVTABLE pAllocator); \
|
---|
380 | a_DeclMacro(int) RT_CONCAT(a_ImplExtNm,_Clone)(RT_CONCAT(P,a_TypeNm) pThis, RT_CONCAT(PC,a_TypeNm) pSrc, \
|
---|
381 | PCRTASN1ALLOCATORVTABLE pAllocator); \
|
---|
382 | a_DeclMacro(void) RT_CONCAT(a_ImplExtNm,_Delete)(RT_CONCAT(P,a_TypeNm) pThis); \
|
---|
383 | a_DeclMacro(int) RT_CONCAT(a_ImplExtNm,_Enum)(RT_CONCAT(P,a_TypeNm) pThis, PFNRTASN1ENUMCALLBACK pfnCallback, \
|
---|
384 | uint32_t uDepth, void *pvUser); \
|
---|
385 | a_DeclMacro(int) RT_CONCAT(a_ImplExtNm,_Compare)(RT_CONCAT(PC,a_TypeNm) pLeft, RT_CONCAT(PC,a_TypeNm) pRight); \
|
---|
386 | a_DeclMacro(int) RT_CONCAT(a_ImplExtNm,_DecodeAsn1)(PRTASN1CURSOR pCursor, uint32_t fFlags, RT_CONCAT(P,a_TypeNm) pThis,\
|
---|
387 | const char *pszErrorTag); \
|
---|
388 | a_DeclMacro(int) RT_CONCAT(a_ImplExtNm,_CheckSanity)(RT_CONCAT(PC,a_TypeNm) pThis, uint32_t fFlags, \
|
---|
389 | PRTERRINFO pErrInfo, const char *pszErrorTag)
|
---|
390 |
|
---|
391 |
|
---|
392 | /** @name Helper macros for prototyping standard functions for an ASN.1 type.
|
---|
393 | * @{ */
|
---|
394 | #define RTASN1TYPE_STANDARD_PROTOTYPES(a_TypeNm, a_DeclMacro, a_ImplExtNm, a_Asn1CoreNm) \
|
---|
395 | DECL_FORCE_INLINE(PRTASN1CORE) RT_CONCAT(a_ImplExtNm,_GetAsn1Core)(RT_CONCAT(PC,a_TypeNm) pThis) \
|
---|
396 | { return (PRTASN1CORE)&pThis->a_Asn1CoreNm; } \
|
---|
397 | DECLINLINE(bool) RT_CONCAT(a_ImplExtNm,_IsPresent)(RT_CONCAT(PC,a_TypeNm) pThis) \
|
---|
398 | { return pThis && RTASN1CORE_IS_PRESENT(&pThis->a_Asn1CoreNm); } \
|
---|
399 | RTASN1TYPE_STANDARD_PROTOTYPES_NO_GET_CORE(a_TypeNm, a_DeclMacro, a_ImplExtNm)
|
---|
400 |
|
---|
401 |
|
---|
402 | /** Aliases two ASN.1 types, no method aliases. */
|
---|
403 | #define RTASN1TYPE_ALIAS_TYPE_ONLY(a_TypeNm, a_AliasType) \
|
---|
404 | typedef a_AliasType a_TypeNm; \
|
---|
405 | typedef a_TypeNm *RT_CONCAT(P,a_TypeNm); \
|
---|
406 | typedef a_TypeNm const *RT_CONCAT(PC,a_TypeNm)
|
---|
407 |
|
---|
408 | /** Aliases two ASN.1 types and methods. */
|
---|
409 | #define RTASN1TYPE_ALIAS(a_TypeNm, a_AliasType, a_ImplExtNm, a_AliasExtNm) \
|
---|
410 | typedef a_AliasType a_TypeNm; \
|
---|
411 | typedef a_TypeNm *RT_CONCAT(P,a_TypeNm); \
|
---|
412 | \
|
---|
413 | DECLINLINE(PRTASN1CORE) RT_CONCAT(a_ImplExtNm,_GetAsn1Core)(a_TypeNm const *pThis) \
|
---|
414 | { return RT_CONCAT(a_AliasExtNm,_GetAsn1Core)(pThis); } \
|
---|
415 | DECLINLINE(bool) RT_CONCAT(a_ImplExtNm,_IsPresent)(a_TypeNm const *pThis) \
|
---|
416 | { return RT_CONCAT(a_AliasExtNm,_IsPresent)(pThis); } \
|
---|
417 | \
|
---|
418 | DECLINLINE(int) RT_CONCAT(a_ImplExtNm,_Init)(RT_CONCAT(P,a_TypeNm) pThis, PCRTASN1ALLOCATORVTABLE pAllocator) \
|
---|
419 | { return RT_CONCAT(a_AliasExtNm,_Init)(pThis, pAllocator); } \
|
---|
420 | DECLINLINE(int) RT_CONCAT(a_ImplExtNm,_Clone)(RT_CONCAT(P,a_TypeNm) pThis, a_TypeNm const *pSrc, \
|
---|
421 | PCRTASN1ALLOCATORVTABLE pAllocator) \
|
---|
422 | { return RT_CONCAT(a_AliasExtNm,_Clone)(pThis, pSrc, pAllocator); } \
|
---|
423 | DECLINLINE(void) RT_CONCAT(a_ImplExtNm,_Delete)(RT_CONCAT(P,a_TypeNm) pThis) \
|
---|
424 | { RT_CONCAT(a_AliasExtNm,_Delete)(pThis); } \
|
---|
425 | DECLINLINE(int) RT_CONCAT(a_ImplExtNm,_Enum)(a_TypeNm *pThis, PFNRTASN1ENUMCALLBACK pfnCallback, \
|
---|
426 | uint32_t uDepth, void *pvUser) \
|
---|
427 | { return RT_CONCAT(a_AliasExtNm,_Enum)(pThis, pfnCallback, uDepth, pvUser); } \
|
---|
428 | DECLINLINE(int) RT_CONCAT(a_ImplExtNm,_Compare)(a_TypeNm const *pLeft, a_TypeNm const *pRight) \
|
---|
429 | { return RT_CONCAT(a_AliasExtNm,_Compare)(pLeft, pRight); } \
|
---|
430 | DECLINLINE(int) RT_CONCAT(a_ImplExtNm,_DecodeAsn1)(PRTASN1CURSOR pCursor, uint32_t fFlags, RT_CONCAT(P,a_TypeNm) pThis,\
|
---|
431 | const char *pszErrorTag) \
|
---|
432 | { return RT_CONCAT(a_AliasExtNm,_DecodeAsn1)(pCursor, fFlags, pThis, pszErrorTag); } \
|
---|
433 | DECLINLINE(int) RT_CONCAT(a_ImplExtNm,_CheckSanity)(a_TypeNm const *pThis, uint32_t fFlags, \
|
---|
434 | PRTERRINFO pErrInfo, const char *pszErrorTag) \
|
---|
435 | { return RT_CONCAT(a_AliasExtNm,_CheckSanity)(pThis, fFlags, pErrInfo, pszErrorTag); } \
|
---|
436 | \
|
---|
437 | typedef a_TypeNm const *RT_CONCAT(PC,a_TypeNm)
|
---|
438 |
|
---|
439 | /** @} */
|
---|
440 |
|
---|
441 |
|
---|
442 | /**
|
---|
443 | * Core ASN.1 structure for storing encoding details and data location.
|
---|
444 | *
|
---|
445 | * This is used as a 'parent' for all other decoded ASN.1 based structures.
|
---|
446 | */
|
---|
447 | typedef struct RTASN1CORE
|
---|
448 | {
|
---|
449 | /** The tag.
|
---|
450 | * @remarks 32-bit should be enough for everyone... We don't currently
|
---|
451 | * implement decoding tags larger than 30 anyway. :-) */
|
---|
452 | uint32_t uTag;
|
---|
453 | /** Tag class and flags (ASN1_TAGCLASS_XXX and ASN1_TAGFLAG_XXX). */
|
---|
454 | uint8_t fClass;
|
---|
455 | /** The real tag value for IMPLICT tag overrides. */
|
---|
456 | uint8_t uRealTag;
|
---|
457 | /** The real class value for IMPLICT tag overrides. */
|
---|
458 | uint8_t fRealClass;
|
---|
459 | /** The size of the tag and length ASN.1 header. */
|
---|
460 | uint8_t cbHdr;
|
---|
461 | /** Length. */
|
---|
462 | uint32_t cb;
|
---|
463 | /** IPRT flags (RTASN1CORE_F_XXX). */
|
---|
464 | uint32_t fFlags;
|
---|
465 | /** Pointer to the data.
|
---|
466 | * After decoding this generally points to the encoded data content. When
|
---|
467 | * preparting something for encoding or otherwise constructing things in memory,
|
---|
468 | * this generally points heap memory or read-only constants.
|
---|
469 | * @sa RTAsn1ContentAllocZ, RTAsn1ContentReallocZ, RTAsn1ContentDup,
|
---|
470 | * RTAsn1ContentFree. */
|
---|
471 | RTCPTRUNION uData;
|
---|
472 | /** Pointer to the virtual method table for this object. Optional. */
|
---|
473 | PCRTASN1COREVTABLE pOps;
|
---|
474 | } RTASN1CORE;
|
---|
475 | /** The Vtable for a RTASN1CORE structure when not in some way use used as a
|
---|
476 | * parent type/class. */
|
---|
477 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1Core_Vtable;
|
---|
478 |
|
---|
479 | RTASN1TYPE_STANDARD_PROTOTYPES_NO_GET_CORE(RTASN1CORE, RTDECL, RTAsn1Core);
|
---|
480 |
|
---|
481 | /** @name RTASN1CORE_F_XXX - Flags for RTASN1CORE::fFlags
|
---|
482 | * @{ */
|
---|
483 | /** Present/valid. */
|
---|
484 | #define RTASN1CORE_F_PRESENT RT_BIT_32(0)
|
---|
485 | /** Not present in stream, using default value. */
|
---|
486 | #define RTASN1CORE_F_DEFAULT RT_BIT_32(1)
|
---|
487 | /** The tag was overriden by an implict context tag or some such thing,
|
---|
488 | * RTASN1CORE::uImplicitTag hold the universal tag value if one exists. */
|
---|
489 | #define RTASN1CORE_F_TAG_IMPLICIT RT_BIT_32(2)
|
---|
490 | /** Primitive tag with the corresponding RTASN1XXX struct. */
|
---|
491 | #define RTASN1CORE_F_PRIMITE_TAG_STRUCT RT_BIT_32(3)
|
---|
492 | /** Dummy node typically used with choices, has children, not encoded, must be
|
---|
493 | * ignored. */
|
---|
494 | #define RTASN1CORE_F_DUMMY RT_BIT_32(4)
|
---|
495 | /** Allocated content (pointed to by uData).
|
---|
496 | * The content should is still be considered 104% read-only by anyone other
|
---|
497 | * than then type methods (pOps and associates). */
|
---|
498 | #define RTASN1CORE_F_ALLOCATED_CONTENT RT_BIT_32(5)
|
---|
499 | /** Decoded content (pointed to by uData).
|
---|
500 | * Mutually exclusive with RTASN1CORE_F_ALLOCATED_CONTENT. If neither is
|
---|
501 | * set, uData might be NULL or point to some shared static memory for
|
---|
502 | * frequently used values. */
|
---|
503 | #define RTASN1CORE_F_DECODED_CONTENT RT_BIT_32(6)
|
---|
504 | /** @} */
|
---|
505 |
|
---|
506 |
|
---|
507 | /** Check s whether an ASN.1 core object present in some way (default data,
|
---|
508 | * decoded data, ...). */
|
---|
509 | #define RTASN1CORE_IS_PRESENT(a_pAsn1Core) ( RT_BOOL((a_pAsn1Core)->fFlags) )
|
---|
510 |
|
---|
511 | /** Check s whether an ASN.1 core object is a dummy object (and is present). */
|
---|
512 | #define RTASN1CORE_IS_DUMMY(a_pAsn1Core) ( RT_BOOL((a_pAsn1Core)->fFlags & RTASN1CORE_F_DUMMY) )
|
---|
513 |
|
---|
514 | /**
|
---|
515 | * Calculates pointer to the raw ASN.1 record.
|
---|
516 | *
|
---|
517 | * ASSUMES that it's decoded content and that cbHdr and uData are both valid.
|
---|
518 | *
|
---|
519 | * @returns Byte pointer to the first tag byte.
|
---|
520 | * @param a_pAsn1Core The ASN.1 core.
|
---|
521 | */
|
---|
522 | #define RTASN1CORE_GET_RAW_ASN1_PTR(a_pAsn1Core) ( (a_pAsn1Core)->uData.pu8 - (a_pAsn1Core)->cbHdr )
|
---|
523 |
|
---|
524 | /**
|
---|
525 | * Calculates the length of the raw ASN.1 record to go with the
|
---|
526 | * RTASN1CORE_GET_RAW_ASN1_PTR() result.
|
---|
527 | *
|
---|
528 | * ASSUMES that it's decoded content and that cbHdr and uData are both valid.
|
---|
529 | *
|
---|
530 | * @returns Size in bytes (uint32_t).
|
---|
531 | * @param a_pAsn1Core The ASN.1 core.
|
---|
532 | */
|
---|
533 | #define RTASN1CORE_GET_RAW_ASN1_SIZE(a_pAsn1Core) ( (a_pAsn1Core)->cbHdr + (a_pAsn1Core)->cb )
|
---|
534 |
|
---|
535 | /**
|
---|
536 | * Retrievs the tag or implicit tag depending on the RTASN1CORE_F_TAG_IMPLICIT
|
---|
537 | * flag.
|
---|
538 | *
|
---|
539 | * @returns The ASN.1 tag of the object.
|
---|
540 | * @param a_pAsn1Core The ASN.1 core.
|
---|
541 | */
|
---|
542 | #define RTASN1CORE_GET_TAG(a_pAsn1Core) ( !((a_pAsn1Core)->fFlags & RTASN1CORE_F_TAG_IMPLICIT) ? (a_pAsn1Core)->uTag : (a_pAsn1Core)->uRealTag )
|
---|
543 |
|
---|
544 |
|
---|
545 | DECL_FORCE_INLINE(PRTASN1CORE) RTAsn1Core_GetAsn1Core(PCRTASN1CORE pThis)
|
---|
546 | {
|
---|
547 | return (PRTASN1CORE)pThis;
|
---|
548 | }
|
---|
549 |
|
---|
550 |
|
---|
551 | DECL_FORCE_INLINE(bool) RTAsn1Core_IsPresent(PCRTASN1CORE pThis)
|
---|
552 | {
|
---|
553 | return pThis && RTASN1CORE_IS_PRESENT(pThis);
|
---|
554 | }
|
---|
555 |
|
---|
556 |
|
---|
557 | RTDECL(int) RTAsn1Core_InitEx(PRTASN1CORE pAsn1Core, uint32_t uTag, uint8_t fClass, PCRTASN1COREVTABLE pOps, uint32_t fFlags);
|
---|
558 | /**
|
---|
559 | * Initialize the ASN.1 core object representation to a default value.
|
---|
560 | *
|
---|
561 | * @returns VINF_SUCCESS
|
---|
562 | * @param pAsn1Core The ASN.1 core.
|
---|
563 | * @param uTag The tag number.
|
---|
564 | * @param fClass The tag class and flags.
|
---|
565 | */
|
---|
566 | RTDECL(int) RTAsn1Core_InitDefault(PRTASN1CORE pAsn1Core, uint32_t uTag, uint8_t fClass);
|
---|
567 | RTDECL(int) RTAsn1Core_CloneContent(PRTASN1CORE pThis, PCRTASN1CORE pSrc, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
568 | RTDECL(int) RTAsn1Core_CloneNoContent(PRTASN1CORE pThis, PCRTASN1CORE pSrc);
|
---|
569 | RTDECL(int) RTAsn1Core_SetTagAndFlags(PRTASN1CORE pAsn1Core, uint32_t uTag, uint8_t fClass);
|
---|
570 | RTDECL(int) RTAsn1Core_ChangeTag(PRTASN1CORE pAsn1Core, uint32_t uTag);
|
---|
571 | RTDECL(void) RTAsn1Core_ResetImplict(PRTASN1CORE pThis);
|
---|
572 | RTDECL(int) RTAsn1Core_CompareEx(PCRTASN1CORE pLeft, PCRTASN1CORE pRight, bool fIgnoreTagAndClass);
|
---|
573 |
|
---|
574 |
|
---|
575 | /**
|
---|
576 | * Dummy ASN.1 object for use in choices and similar non-sequence structures.
|
---|
577 | *
|
---|
578 | * This allows hooking up destructors, enumerators and such, as well as not
|
---|
579 | * needing custom code for sequence-of / set-of collections.
|
---|
580 | */
|
---|
581 | typedef struct RTASN1DUMMY
|
---|
582 | {
|
---|
583 | /** Core ASN.1. */
|
---|
584 | RTASN1CORE Asn1Core;
|
---|
585 | } RTASN1DUMMY;
|
---|
586 | /** Pointer to a dummy record. */
|
---|
587 | typedef RTASN1DUMMY *PRTASN1DUMMY;
|
---|
588 |
|
---|
589 |
|
---|
590 | /**
|
---|
591 | * Initalizes a dummy ASN.1 object.
|
---|
592 | *
|
---|
593 | * @returns VINF_SUCCESS.
|
---|
594 | * @param pThis The dummy object.
|
---|
595 | */
|
---|
596 | RTDECL(int) RTAsn1Dummy_InitEx(PRTASN1DUMMY pThis);
|
---|
597 |
|
---|
598 | /**
|
---|
599 | * Standard compliant initalizer.
|
---|
600 | *
|
---|
601 | * @returns VINF_SUCCESS.
|
---|
602 | * @param pThis The dummy object.
|
---|
603 | * @param pAllocator Ignored.
|
---|
604 | */
|
---|
605 | DECLINLINE(int) RTAsn1Dummy_Init(PRTASN1DUMMY pThis, PCRTASN1ALLOCATORVTABLE pAllocator)
|
---|
606 | {
|
---|
607 | return RTAsn1Dummy_InitEx(pThis);
|
---|
608 | }
|
---|
609 |
|
---|
610 |
|
---|
611 | /**
|
---|
612 | * ASN.1 sequence core (IPRT representation).
|
---|
613 | */
|
---|
614 | typedef struct RTASN1SEQUENCECORE
|
---|
615 | {
|
---|
616 | /** Core ASN.1 encoding details. */
|
---|
617 | RTASN1CORE Asn1Core;
|
---|
618 | } RTASN1SEQUENCECORE;
|
---|
619 | /** Pointer to an ASN.1 sequence core (IPRT representation). */
|
---|
620 | typedef RTASN1SEQUENCECORE *PRTASN1SEQUENCECORE;
|
---|
621 | /** Pointer to a const ASN.1 sequence core (IPRT representation). */
|
---|
622 | typedef RTASN1SEQUENCECORE const *PCRTASN1SEQUENCECORE;
|
---|
623 |
|
---|
624 | RTDECL(int) RTAsn1SequenceCore_Init(PRTASN1SEQUENCECORE pSeqCore, PCRTASN1COREVTABLE pVtable);
|
---|
625 | RTDECL(int) RTAsn1SequenceCore_Clone(PRTASN1SEQUENCECORE pSeqCore, PCRTASN1COREVTABLE pVtable, PCRTASN1SEQUENCECORE pSrc);
|
---|
626 |
|
---|
627 | /**
|
---|
628 | * ASN.1 sequence-of core (IPRT representation).
|
---|
629 | */
|
---|
630 | #if 0
|
---|
631 | typedef struct RTASN1SEQOFCORE
|
---|
632 | {
|
---|
633 | /** Core ASN.1 encoding details. */
|
---|
634 | RTASN1CORE Asn1Core;
|
---|
635 | } RTASN1SEQUENCECORE;
|
---|
636 | /** Pointer to an ASN.1 sequence-of core (IPRT representation). */
|
---|
637 | typedef RTASN1SEQUENCECORE *PRTASN1SEQUENCECORE;
|
---|
638 | /** Pointer to a const ASN.1 sequence-of core (IPRT representation). */
|
---|
639 | typedef RTASN1SEQUENCECORE const *PCRTASN1SEQUENCECORE;
|
---|
640 | #else
|
---|
641 | # define RTASN1SEQOFCORE RTASN1SEQUENCECORE
|
---|
642 | # define PRTASN1SEQOFCORE PRTASN1SEQUENCECORE
|
---|
643 | # define PCRTASN1SEQOFCORE PCRTASN1SEQUENCECORE
|
---|
644 | #endif
|
---|
645 | RTDECL(int) RTAsn1SeqOfCore_Init(PRTASN1SEQOFCORE pThis, PCRTASN1COREVTABLE pVtable);
|
---|
646 | RTDECL(int) RTAsn1SeqOfCore_Clone(PRTASN1SEQOFCORE pThis, PCRTASN1COREVTABLE pVtable, PCRTASN1SEQOFCORE pSrc);
|
---|
647 |
|
---|
648 |
|
---|
649 | /** Defines the typedefs and prototypes for a generic sequence-of type. */
|
---|
650 | #define RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(a_SeqOfType, a_ItemType, a_DeclMacro, a_ImplExtNm) \
|
---|
651 | typedef struct a_SeqOfType \
|
---|
652 | { \
|
---|
653 | /** Sequence core. */ \
|
---|
654 | RTASN1SEQUENCECORE SeqCore; \
|
---|
655 | /** The array allocation tracker. */ \
|
---|
656 | RTASN1ALLOCATION Allocation; \
|
---|
657 | /** Items in the array. */ \
|
---|
658 | uint32_t cItems; \
|
---|
659 | /** Array. */ \
|
---|
660 | RT_CONCAT(P,a_ItemType) paItems; \
|
---|
661 | } a_SeqOfType; \
|
---|
662 | typedef a_SeqOfType *RT_CONCAT(P,a_SeqOfType); \
|
---|
663 | typedef a_SeqOfType const *RT_CONCAT(PC,a_SeqOfType); \
|
---|
664 | RTASN1TYPE_STANDARD_PROTOTYPES(a_SeqOfType, a_DeclMacro, a_ImplExtNm, SeqCore.Asn1Core)
|
---|
665 |
|
---|
666 |
|
---|
667 | /**
|
---|
668 | * ASN.1 set core (IPRT representation).
|
---|
669 | */
|
---|
670 | typedef struct RTASN1SETCORE
|
---|
671 | {
|
---|
672 | /** Core ASN.1 encoding details. */
|
---|
673 | RTASN1CORE Asn1Core;
|
---|
674 | } RTASN1SETCORE;
|
---|
675 | /** Pointer to an ASN.1 set core (IPRT representation). */
|
---|
676 | typedef RTASN1SETCORE *PRTASN1SETCORE;
|
---|
677 | /** Pointer to a const ASN.1 set core (IPRT representation). */
|
---|
678 | typedef RTASN1SETCORE const *PCRTASN1SETCORE;
|
---|
679 |
|
---|
680 | RTDECL(int) RTAsn1SetCore_Init(PRTASN1SETCORE pThis, PCRTASN1COREVTABLE pVtable);
|
---|
681 | RTDECL(int) RTAsn1SetCore_Clone(PRTASN1SETCORE pThis, PCRTASN1COREVTABLE pVtable, PCRTASN1SETCORE pSrc);
|
---|
682 |
|
---|
683 | /**
|
---|
684 | * ASN.1 set-of core (IPRT representation).
|
---|
685 | */
|
---|
686 | #if 0
|
---|
687 | typedef struct RTASN1SETOFCORE
|
---|
688 | {
|
---|
689 | /** Core ASN.1 encoding details. */
|
---|
690 | RTASN1CORE Asn1Core;
|
---|
691 | } RTASN1SETUENCECORE;
|
---|
692 | /** Pointer to an ASN.1 set-of core (IPRT representation). */
|
---|
693 | typedef RTASN1SETUENCECORE *PRTASN1SETUENCECORE;
|
---|
694 | /** Pointer to a const ASN.1 set-of core (IPRT representation). */
|
---|
695 | typedef RTASN1SETUENCECORE const *PCRTASN1SETUENCECORE;
|
---|
696 | #else
|
---|
697 | # define RTASN1SETOFCORE RTASN1SETCORE
|
---|
698 | # define PRTASN1SETOFCORE PRTASN1SETCORE
|
---|
699 | # define PCRTASN1SETOFCORE PCRTASN1SETCORE
|
---|
700 | #endif
|
---|
701 | RTDECL(int) RTAsn1SetOfCore_Init(PRTASN1SETOFCORE pThis, PCRTASN1COREVTABLE pVtable);
|
---|
702 | RTDECL(int) RTAsn1SetOfCore_Clone(PRTASN1SETOFCORE pThis, PCRTASN1COREVTABLE pVtable, PCRTASN1SETOFCORE pSrc);
|
---|
703 |
|
---|
704 |
|
---|
705 | /** Defines the typedefs and prototypes for a generic set-of type. */
|
---|
706 | #define RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(a_SetOfType, a_ItemType, a_DeclMacro, a_ImplExtNm) \
|
---|
707 | typedef struct a_SetOfType \
|
---|
708 | { \
|
---|
709 | /** Set core. */ \
|
---|
710 | RTASN1SETCORE SetCore; \
|
---|
711 | /** The array allocation tracker. */ \
|
---|
712 | RTASN1ALLOCATION Allocation; \
|
---|
713 | /** Items in the array. */ \
|
---|
714 | uint32_t cItems; \
|
---|
715 | /** Array. */ \
|
---|
716 | RT_CONCAT(P,a_ItemType) paItems; \
|
---|
717 | } a_SetOfType; \
|
---|
718 | typedef a_SetOfType *RT_CONCAT(P,a_SetOfType); \
|
---|
719 | typedef a_SetOfType const *RT_CONCAT(PC,a_SetOfType); \
|
---|
720 | RTASN1TYPE_STANDARD_PROTOTYPES(a_SetOfType, a_DeclMacro, a_ImplExtNm, SetCore.Asn1Core)
|
---|
721 |
|
---|
722 |
|
---|
723 | /*
|
---|
724 | * Declare sets and sequences of the core structure.
|
---|
725 | */
|
---|
726 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTASN1SEQOFCORES, RTASN1CORE, RTDECL, RTAsn1SeqOfCores);
|
---|
727 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTASN1SETOFCORES, RTASN1CORE, RTDECL, RTAsn1SetOfCores);
|
---|
728 |
|
---|
729 |
|
---|
730 | /**
|
---|
731 | * ASN.1 null (IPRT representation).
|
---|
732 | */
|
---|
733 | typedef struct RTASN1NULL
|
---|
734 | {
|
---|
735 | /** Core ASN.1 encoding details. */
|
---|
736 | RTASN1CORE Asn1Core;
|
---|
737 | } RTASN1NULL;
|
---|
738 | /** Pointer to an ASN.1 null (IPRT representation). */
|
---|
739 | typedef RTASN1NULL *PRTASN1NULL;
|
---|
740 | /** Pointer to a const ASN.1 null (IPRT representation). */
|
---|
741 | typedef RTASN1NULL const *PCRTASN1NULL;
|
---|
742 | /** The Vtable for a RTASN1NULL structure. */
|
---|
743 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1Null_Vtable;
|
---|
744 |
|
---|
745 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1NULL, RTDECL, RTAsn1Null, Asn1Core);
|
---|
746 |
|
---|
747 |
|
---|
748 | /**
|
---|
749 | * ASN.1 integer (IPRT representation).
|
---|
750 | */
|
---|
751 | typedef struct RTASN1INTEGER
|
---|
752 | {
|
---|
753 | /** Core ASN.1 encoding details. */
|
---|
754 | RTASN1CORE Asn1Core;
|
---|
755 | /** The unsigned C representation of the 64 least significant bits.
|
---|
756 | * @note A ASN.1 integer doesn't define signed/unsigned and can have any
|
---|
757 | * length you like. Thus, the user needs to check the size and
|
---|
758 | * preferably use the access APIs for signed numbers. */
|
---|
759 | RTUINT64U uValue;
|
---|
760 | } RTASN1INTEGER;
|
---|
761 | /** Pointer to an ASN.1 integer (IPRT representation). */
|
---|
762 | typedef RTASN1INTEGER *PRTASN1INTEGER;
|
---|
763 | /** Pointer to a const ASN.1 integer (IPRT representation). */
|
---|
764 | typedef RTASN1INTEGER const *PCRTASN1INTEGER;
|
---|
765 | /** The Vtable for a RTASN1INTEGER structure. */
|
---|
766 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1Integer_Vtable;
|
---|
767 |
|
---|
768 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1INTEGER, RTDECL, RTAsn1Integer, Asn1Core);
|
---|
769 |
|
---|
770 | /**
|
---|
771 | * Initializes an interger object to a default value.
|
---|
772 | * @returns VINF_SUCCESS.
|
---|
773 | * @param pBoolean The integer object representation.
|
---|
774 | * @param uValue The default value (unsigned 64-bit).
|
---|
775 | * @param pAllocator The allocator (pro forma).
|
---|
776 | */
|
---|
777 | RTDECL(int) RTAsn1Integer_InitDefault(PRTASN1INTEGER pInteger, uint64_t uValue, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
778 |
|
---|
779 | RTDECL(int) RTAsn1Integer_InitU64(PRTASN1INTEGER pThis, uint64_t uValue, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
780 |
|
---|
781 | /**
|
---|
782 | * Get the most significat bit that's set (1).
|
---|
783 | *
|
---|
784 | * @returns 0-base bit number, -1 if all clear.
|
---|
785 | * @param pInteger The integer to check.
|
---|
786 | */
|
---|
787 | RTDECL(int32_t) RTAsn1Integer_UnsignedLastBit(PCRTASN1INTEGER pInteger);
|
---|
788 |
|
---|
789 | /**
|
---|
790 | * Compares two ASN.1 unsigned integers.
|
---|
791 | *
|
---|
792 | * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
|
---|
793 | * @param pLeft The first ASN.1 integer.
|
---|
794 | * @param pRight The second ASN.1 integer.
|
---|
795 | */
|
---|
796 | RTDECL(int) RTAsn1Integer_UnsignedCompare(PCRTASN1INTEGER pLeft, PCRTASN1INTEGER pRight);
|
---|
797 |
|
---|
798 | /**
|
---|
799 | * Compares an ASN.1 unsigned integer with a uint64_t.
|
---|
800 | *
|
---|
801 | * @returns 0 if equal, -1 if @a pInteger is smaller, 1 if @a pInteger is
|
---|
802 | * larger.
|
---|
803 | * @param pInteger The ASN.1 integer to treat as unsigned.
|
---|
804 | * @param u64Const The uint64_t constant to compare with.
|
---|
805 | */
|
---|
806 | RTDECL(int) RTAsn1Integer_UnsignedCompareWithU64(PCRTASN1INTEGER pInteger, uint64_t u64Const);
|
---|
807 |
|
---|
808 | /**
|
---|
809 | * Compares an ASN.1 unsigned integer with a uint32_t.
|
---|
810 | *
|
---|
811 | * @returns 0 if equal, -1 if @a pInteger is smaller, 1 if @a pInteger is
|
---|
812 | * larger.
|
---|
813 | * @param pInteger The ASN.1 integer to treat as unsigned.
|
---|
814 | * @param u32Const The uint32_t constant to compare with.
|
---|
815 | * @remarks We don't bother with U16 and U8 variants, just use this instead.
|
---|
816 | */
|
---|
817 | RTDECL(int) RTAsn1Integer_UnsignedCompareWithU32(PCRTASN1INTEGER pInteger, uint32_t u32Const);
|
---|
818 |
|
---|
819 |
|
---|
820 | /**
|
---|
821 | * Initializes a big integer number from an ASN.1 integer.
|
---|
822 | *
|
---|
823 | * @returns IPRT status code.
|
---|
824 | * @param pInteger The ASN.1 integer.
|
---|
825 | * @param pBigNum The big integer number structure to initialize.
|
---|
826 | * @param fBigNumInit Subset of RTBIGNUMINIT_F_XXX that concerns
|
---|
827 | * senitivity, signedness and endianness.
|
---|
828 | */
|
---|
829 | RTDECL(int) RTAsn1Integer_ToBigNum(PCRTASN1INTEGER pInteger, PRTBIGNUM pBigNum, uint32_t fBigNumInit);
|
---|
830 | RTDECL(int) RTAsn1Integer_FromBigNum(PRTASN1INTEGER pThis, PCRTBIGNUM pBigNum, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
831 |
|
---|
832 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTASN1SEQOFINTEGERS, RTASN1INTEGER, RTDECL, RTAsn1SeqOfIntegers);
|
---|
833 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTASN1SETOFINTEGERS, RTASN1INTEGER, RTDECL, RTAsn1SetOfIntegers);
|
---|
834 |
|
---|
835 |
|
---|
836 |
|
---|
837 | /**
|
---|
838 | * ASN.1 boolean (IPRT representation).
|
---|
839 | */
|
---|
840 | typedef struct RTASN1BOOLEAN
|
---|
841 | {
|
---|
842 | /** Core ASN.1 encoding details. */
|
---|
843 | RTASN1CORE Asn1Core;
|
---|
844 | /** The boolean value. */
|
---|
845 | bool fValue;
|
---|
846 | } RTASN1BOOLEAN;
|
---|
847 | /** Pointer to the IPRT representation of an ASN.1 boolean. */
|
---|
848 | typedef RTASN1BOOLEAN *PRTASN1BOOLEAN;
|
---|
849 | /** Pointer to the const IPRT representation of an ASN.1 boolean. */
|
---|
850 | typedef RTASN1BOOLEAN const *PCRTASN1BOOLEAN;
|
---|
851 | /** The Vtable for a RTASN1BOOLEAN structure. */
|
---|
852 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1Boolean_Vtable;
|
---|
853 |
|
---|
854 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1BOOLEAN, RTDECL, RTAsn1Boolean, Asn1Core);
|
---|
855 |
|
---|
856 | /**
|
---|
857 | * Initializes a boolean object to a default value.
|
---|
858 | * @returns VINF_SUCCESS
|
---|
859 | * @param pBoolean The boolean object representation.
|
---|
860 | * @param fValue The default value.
|
---|
861 | * @param pAllocator The allocator (pro forma).
|
---|
862 | */
|
---|
863 | RTDECL(int) RTAsn1Boolean_InitDefault(PRTASN1BOOLEAN pBoolean, bool fValue, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
864 | RTDECL(int) RTAsn1Boolean_Set(PRTASN1BOOLEAN pThis, bool fValue);
|
---|
865 |
|
---|
866 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTASN1SEQOFBOOLEANS, RTASN1BOOLEAN, RTDECL, RTAsn1SeqOfBooleans);
|
---|
867 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTASN1SETOFBOOLEANS, RTASN1BOOLEAN, RTDECL, RTAsn1SetOfBooleans);
|
---|
868 |
|
---|
869 |
|
---|
870 |
|
---|
871 | /**
|
---|
872 | * ASN.1 UTC and Generalized Time (IPRT representation).
|
---|
873 | *
|
---|
874 | * The two time types only differs in the precision the render (UTC time being
|
---|
875 | * the one for which you go "WTF were they thinking?!!" for in 2014).
|
---|
876 | */
|
---|
877 | typedef struct RTASN1TIME
|
---|
878 | {
|
---|
879 | /** The core structure, either ASN1_TAG_UTC_TIME or
|
---|
880 | * ASN1_TAG_GENERALIZED_TIME. */
|
---|
881 | RTASN1CORE Asn1Core;
|
---|
882 | /** The exploded time. */
|
---|
883 | RTTIME Time;
|
---|
884 | } RTASN1TIME;
|
---|
885 | /** Pointer to an IPRT representation of ASN.1 UTC/Generalized time. */
|
---|
886 | typedef RTASN1TIME *PRTASN1TIME;
|
---|
887 | /** Pointer to a const IPRT representation of ASN.1 UTC/Generalized time. */
|
---|
888 | typedef RTASN1TIME const *PCRTASN1TIME;
|
---|
889 | /** The Vtable for a RTASN1TIME structure. */
|
---|
890 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1Time_Vtable;
|
---|
891 |
|
---|
892 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1TIME, RTDECL, RTAsn1Time, Asn1Core);
|
---|
893 |
|
---|
894 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1TIME, RTDECL, RTAsn1UtcTime, Asn1Core);
|
---|
895 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1TIME, RTDECL, RTAsn1GeneralizedTime, Asn1Core);
|
---|
896 |
|
---|
897 | /**
|
---|
898 | * Compares two ASN.1 time values.
|
---|
899 | *
|
---|
900 | * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
|
---|
901 | * @param pLeft The first ASN.1 time object.
|
---|
902 | * @param pTsRight The second time to compare.
|
---|
903 | */
|
---|
904 | RTDECL(int) RTAsn1Time_CompareWithTimeSpec(PCRTASN1TIME pLeft, PCRTTIMESPEC pTsRight);
|
---|
905 |
|
---|
906 | /** @name Predicate macros for determing the exact type of RTASN1TIME.
|
---|
907 | * @{ */
|
---|
908 | /** True if UTC time. */
|
---|
909 | #define RTASN1TIME_IS_UTC_TIME(a_pAsn1Time) ((a_pAsn1Time)->Asn1Core.uTag == ASN1_TAG_UTC_TIME)
|
---|
910 | /** True if generalized time. */
|
---|
911 | #define RTASN1TIME_IS_GENERALIZED_TIME(a_pAsn1Time) ((a_pAsn1Time)->Asn1Core.uTag == ASN1_TAG_GENERALIZED_TIME)
|
---|
912 | /** @} */
|
---|
913 |
|
---|
914 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTASN1SEQOFTIMES, RTASN1TIME, RTDECL, RTAsn1SeqOfTimes);
|
---|
915 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTASN1SETOFTIMES, RTASN1TIME, RTDECL, RTAsn1SetOfTimes);
|
---|
916 |
|
---|
917 |
|
---|
918 |
|
---|
919 | /**
|
---|
920 | * ASN.1 object identifier (IPRT representation).
|
---|
921 | */
|
---|
922 | typedef struct RTASN1OBJID
|
---|
923 | {
|
---|
924 | /** Core ASN.1 encoding details. */
|
---|
925 | RTASN1CORE Asn1Core;
|
---|
926 | /** Coverning the paComponents memory allocation if there isn't enough room in
|
---|
927 | * szObjId for both the dottet string and the component values. */
|
---|
928 | RTASN1ALLOCATION Allocation;
|
---|
929 | /** Pointer to an array with the component values.
|
---|
930 | * This may point within szObjId if there is enough space for both there. */
|
---|
931 | uint32_t const *pauComponents;
|
---|
932 | /** The number of components in the object identifier.
|
---|
933 | * This ASSUMES that nobody will be ever needing more than 255 components. */
|
---|
934 | uint8_t cComponents;
|
---|
935 | /** The dotted string representation of the object identifier.
|
---|
936 | * If there is sufficient space after the string, we will place the array that
|
---|
937 | * paComponents points to here and/or the raw content bytes (Asn1Core.uData).
|
---|
938 | *
|
---|
939 | * An analysis of dumpasn1.cfg, hl7.org and our own _OID defines indicates
|
---|
940 | * that we need space for at least 10 components and 30-something chars. We've
|
---|
941 | * allocated 87 bytes, which we ASSUME should be enough for everyone. */
|
---|
942 | char szObjId[87];
|
---|
943 | } RTASN1OBJID;
|
---|
944 | /** Pointer to an ASN.1 object identifier representation. */
|
---|
945 | typedef RTASN1OBJID *PRTASN1OBJID;
|
---|
946 | /** Pointer to a const ASN.1 object identifier representation. */
|
---|
947 | typedef RTASN1OBJID const *PCRTASN1OBJID;
|
---|
948 | /** The Vtable for a RTASN1OBJID structure. */
|
---|
949 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1ObjId_Vtable;
|
---|
950 |
|
---|
951 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1OBJID, RTDECL, RTAsn1ObjId, Asn1Core);
|
---|
952 |
|
---|
953 | RTDECL(int) RTAsn1ObjId_InitFromString(PRTASN1OBJID pThis, const char *pszObjId, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
954 |
|
---|
955 | /**
|
---|
956 | * Compares an ASN.1 object identifier with a dotted object identifier string.
|
---|
957 | *
|
---|
958 | * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
|
---|
959 | * @param pThis The ASN.1 object identifier.
|
---|
960 | * @param pszRight The dotted object identifier string.
|
---|
961 | */
|
---|
962 | RTDECL(int) RTAsn1ObjId_CompareWithString(PCRTASN1OBJID pThis, const char *pszRight);
|
---|
963 |
|
---|
964 | /**
|
---|
965 | * Checks if an ASN.1 object identifier starts with the given dotted object
|
---|
966 | * identifier string.
|
---|
967 | *
|
---|
968 | * The matching is only successful if the given string matches matches the last
|
---|
969 | * component completely.
|
---|
970 | *
|
---|
971 | * @returns true / false.
|
---|
972 | * @param pThis The ASN.1 object identifier.
|
---|
973 | * @param pszStartsWith The dotted object identifier string.
|
---|
974 | */
|
---|
975 | RTDECL(bool) RTAsn1ObjId_StartsWith(PCRTASN1OBJID pThis, const char *pszStartsWith);
|
---|
976 |
|
---|
977 | RTDECL(uint8_t) RTAsn1ObjIdCountComponents(PCRTASN1OBJID pThis);
|
---|
978 | RTDECL(uint32_t) RTAsn1ObjIdGetComponentsAsUInt32(PCRTASN1OBJID pThis, uint8_t iComponent);
|
---|
979 | RTDECL(uint32_t) RTAsn1ObjIdGetLastComponentsAsUInt32(PCRTASN1OBJID pThis);
|
---|
980 |
|
---|
981 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTASN1SEQOFOBJIDS, RTASN1OBJID, RTDECL, RTAsn1SeqOfObjIds);
|
---|
982 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTASN1SETOFOBJIDS, RTASN1OBJID, RTDECL, RTAsn1SetOfObjIds);
|
---|
983 |
|
---|
984 |
|
---|
985 | /**
|
---|
986 | * ASN.1 bit string (IPRT representation).
|
---|
987 | */
|
---|
988 | typedef struct RTASN1BITSTRING
|
---|
989 | {
|
---|
990 | /** Core ASN.1 encoding details. */
|
---|
991 | RTASN1CORE Asn1Core;
|
---|
992 | /** The number of bits. */
|
---|
993 | uint32_t cBits;
|
---|
994 | /** The max number of bits (given at decoding / construction). */
|
---|
995 | uint32_t cMaxBits;
|
---|
996 | /** Pointer to the bits. */
|
---|
997 | RTCPTRUNION uBits;
|
---|
998 | /** Pointer to user structure encapsulated in this string, if dynamically
|
---|
999 | * allocated the EncapsulatedAllocation member can be used to track it and
|
---|
1000 | * trigger automatic cleanup on object destruction. If EncapsulatedAllocation
|
---|
1001 | * is zero, any object pointed to will only be deleted. */
|
---|
1002 | PRTASN1CORE pEncapsulated;
|
---|
1003 | /** Allocation tracking structure for pEncapsulated. */
|
---|
1004 | RTASN1ALLOCATION EncapsulatedAllocation;
|
---|
1005 | } RTASN1BITSTRING;
|
---|
1006 | /** Pointer to the IPRT representation of an ASN.1 bit string. */
|
---|
1007 | typedef RTASN1BITSTRING *PRTASN1BITSTRING;
|
---|
1008 | /** Pointer to the const IPRT representation of an ASN.1 bit string. */
|
---|
1009 | typedef RTASN1BITSTRING const *PCRTASN1BITSTRING;
|
---|
1010 | /** The Vtable for a RTASN1BITSTRING structure. */
|
---|
1011 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1BitString_Vtable;
|
---|
1012 |
|
---|
1013 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1BITSTRING, RTDECL, RTAsn1BitString, Asn1Core);
|
---|
1014 |
|
---|
1015 | /**
|
---|
1016 | * Calculates pointer to the first bit.
|
---|
1017 | *
|
---|
1018 | * @returns Byte pointer to the first bit.
|
---|
1019 | * @param a_pBitString The ASN.1 bit string.
|
---|
1020 | */
|
---|
1021 | #define RTASN1BITSTRING_GET_BIT0_PTR(a_pBitString) ( &(a_pBitString)->Asn1Core.uData.pu8[1] )
|
---|
1022 |
|
---|
1023 | /**
|
---|
1024 | * Calculates the size in bytes.
|
---|
1025 | *
|
---|
1026 | * @returns Rounded up size in bytes.
|
---|
1027 | * @param a_pBitString The ASN.1 bit string.
|
---|
1028 | */
|
---|
1029 | #define RTASN1BITSTRING_GET_BYTE_SIZE(a_pBitString) ( ((a_pBitString)->cBits + 7U) >> 3 )
|
---|
1030 |
|
---|
1031 | RTDECL(int) RTAsn1BitString_DecodeAsn1Ex(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t cMaxBits, PRTASN1BITSTRING pThis,
|
---|
1032 | const char *pszErrorTag);
|
---|
1033 | RTDECL(uint64_t) RTAsn1BitString_GetAsUInt64(PCRTASN1BITSTRING pThis);
|
---|
1034 |
|
---|
1035 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTASN1SEQOFBITSTRINGS, RTASN1BITSTRING, RTDECL, RTAsn1SeqOfBitStrings);
|
---|
1036 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTASN1SETOFBITSTRINGS, RTASN1BITSTRING, RTDECL, RTAsn1SetOfBitStrings);
|
---|
1037 |
|
---|
1038 |
|
---|
1039 | /**
|
---|
1040 | * ASN.1 octet string (IPRT representation).
|
---|
1041 | */
|
---|
1042 | typedef struct RTASN1OCTETSTRING
|
---|
1043 | {
|
---|
1044 | /** Core ASN.1 encoding details. */
|
---|
1045 | RTASN1CORE Asn1Core;
|
---|
1046 | /** Pointer to user structure encapsulated in this string, if dynamically
|
---|
1047 | * allocated the EncapsulatedAllocation member can be used to track it and
|
---|
1048 | * trigger automatic cleanup on object destruction. If EncapsulatedAllocation
|
---|
1049 | * is zero, any object pointed to will only be deleted. */
|
---|
1050 | PRTASN1CORE pEncapsulated;
|
---|
1051 | /** Allocation tracking structure for pEncapsulated. */
|
---|
1052 | RTASN1ALLOCATION EncapsulatedAllocation;
|
---|
1053 | } RTASN1OCTETSTRING;
|
---|
1054 | /** Pointer to the IPRT representation of an ASN.1 octet string. */
|
---|
1055 | typedef RTASN1OCTETSTRING *PRTASN1OCTETSTRING;
|
---|
1056 | /** Pointer to the const IPRT representation of an ASN.1 octet string. */
|
---|
1057 | typedef RTASN1OCTETSTRING const *PCRTASN1OCTETSTRING;
|
---|
1058 | /** The Vtable for a RTASN1OCTETSTRING structure. */
|
---|
1059 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1OctetString_Vtable;
|
---|
1060 |
|
---|
1061 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1OCTETSTRING, RTDECL, RTAsn1OctetString, Asn1Core);
|
---|
1062 |
|
---|
1063 | RTDECL(int) RTAsn1OctetStringCompare(PCRTASN1OCTETSTRING pLeft, PCRTASN1OCTETSTRING pRight);
|
---|
1064 |
|
---|
1065 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTASN1SEQOFOCTETSTRINGS, RTASN1OCTETSTRING, RTDECL, RTAsn1SeqOfOctetStrings);
|
---|
1066 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTASN1SETOFOCTETSTRINGS, RTASN1OCTETSTRING, RTDECL, RTAsn1SetOfOctetStrings);
|
---|
1067 |
|
---|
1068 |
|
---|
1069 | /**
|
---|
1070 | * ASN.1 string (IPRT representation).
|
---|
1071 | * All char string types except 'character string (29)'.
|
---|
1072 | */
|
---|
1073 | typedef struct RTASN1STRING
|
---|
1074 | {
|
---|
1075 | /** Core ASN.1 encoding details. */
|
---|
1076 | RTASN1CORE Asn1Core;
|
---|
1077 | /** Allocation tracking for pszUtf8. */
|
---|
1078 | RTASN1ALLOCATION Allocation;
|
---|
1079 | /** If conversion to UTF-8 was requested, we cache that here. */
|
---|
1080 | char const *pszUtf8;
|
---|
1081 | /** The length (chars, not code points) of the above UTF-8 string if
|
---|
1082 | * present. */
|
---|
1083 | uint32_t cchUtf8;
|
---|
1084 | } RTASN1STRING;
|
---|
1085 | /** Pointer to the IPRT representation of an ASN.1 string. */
|
---|
1086 | typedef RTASN1STRING *PRTASN1STRING;
|
---|
1087 | /** Pointer to the const IPRT representation of an ASN.1 string. */
|
---|
1088 | typedef RTASN1STRING const *PCRTASN1STRING;
|
---|
1089 | /** The Vtable for a RTASN1STRING structure. */
|
---|
1090 | extern RTDATADECL(RTASN1COREVTABLE const) g_RTAsn1String_Vtable;
|
---|
1091 |
|
---|
1092 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1String, Asn1Core);
|
---|
1093 |
|
---|
1094 | /** @name String type predicate macros.
|
---|
1095 | * @{ */
|
---|
1096 | #define RTASN1STRING_IS_NUMERIC(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_NUMERIC_STRING )
|
---|
1097 | #define RTASN1STRING_IS_PRINTABLE(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_PRINTABLE_STRING )
|
---|
1098 | #define RTASN1STRING_IS_T61(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_T61_STRING )
|
---|
1099 | #define RTASN1STRING_IS_VIDEOTEX(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_VIDEOTEX_STRING )
|
---|
1100 | #define RTASN1STRING_IS_VISIBLE(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_VISIBLE_STRING )
|
---|
1101 | #define RTASN1STRING_IS_IA5(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_IA5_STRING )
|
---|
1102 | #define RTASN1STRING_IS_GRAPHIC(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_GRAPHIC_STRING )
|
---|
1103 | #define RTASN1STRING_IS_GENERAL(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_GENERAL_STRING )
|
---|
1104 | /** UTF-8. */
|
---|
1105 | #define RTASN1STRING_IS_UTF8(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_UTF8_STRING )
|
---|
1106 | /** UCS-2. */
|
---|
1107 | #define RTASN1STRING_IS_BMP(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_BMP_STRING )
|
---|
1108 | /** UCS-4. */
|
---|
1109 | #define RTASN1STRING_IS_UNIVERSAL(a_pAsn1String) ( RTASN1CORE_GET_TAG(&(a_pAsn1String)->Asn1Core) == ASN1_TAG_UNIVERSAL_STRING )
|
---|
1110 | /** @} */
|
---|
1111 |
|
---|
1112 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1NumericString, Asn1Core);
|
---|
1113 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1PrintableString, Asn1Core);
|
---|
1114 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1T61String, Asn1Core);
|
---|
1115 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1VideoTexString, Asn1Core);
|
---|
1116 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1VisibleString, Asn1Core);
|
---|
1117 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1Ia5String, Asn1Core);
|
---|
1118 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1GraphicString, Asn1Core);
|
---|
1119 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1GeneralString, Asn1Core);
|
---|
1120 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1Utf8String, Asn1Core);
|
---|
1121 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1BmpString, Asn1Core);
|
---|
1122 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1STRING, RTDECL, RTAsn1UniversalString, Asn1Core);
|
---|
1123 |
|
---|
1124 | RTDECL(int) RTAsn1String_InitWithValue(PRTASN1STRING pThis, const char *pszUtf8Value, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
1125 | RTDECL(int) RTAsn1String_InitEx(PRTASN1STRING pThis, uint32_t uTag, void const *pvValue, size_t cbValue,
|
---|
1126 | PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
1127 |
|
---|
1128 | /**
|
---|
1129 | * Compares two strings values, extended version.
|
---|
1130 | *
|
---|
1131 | * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
|
---|
1132 | * @param pLeft The first string.
|
---|
1133 | * @param pRight The second string.
|
---|
1134 | * @param fTypeToo Set if the string types must match, false if
|
---|
1135 | * not.
|
---|
1136 | */
|
---|
1137 | RTDECL(int) RTAsn1String_CompareEx(PCRTASN1STRING pLeft, PCRTASN1STRING pRight, bool fTypeToo);
|
---|
1138 |
|
---|
1139 | /**
|
---|
1140 | * Compares a ASN.1 string object with an UTF-8 string.
|
---|
1141 | *
|
---|
1142 | * @returns 0 if equal, -1 if @a pThis is smaller, 1 if @a pThis is larger.
|
---|
1143 | * @param pThis The ASN.1 string object.
|
---|
1144 | * @param pszString The UTF-8 string.
|
---|
1145 | * @param cchString The length of @a pszString, or RTSTR_MAX.
|
---|
1146 | */
|
---|
1147 | RTDECL(int) RTAsn1String_CompareWithString(PCRTASN1STRING pThis, const char *pszString, size_t cchString);
|
---|
1148 |
|
---|
1149 | /**
|
---|
1150 | * Queries the UTF-8 length of an ASN.1 string object.
|
---|
1151 | *
|
---|
1152 | * This differs from RTAsn1String_QueryUtf8 in that it won't need to allocate
|
---|
1153 | * memory for the converted string, but just calculates the length.
|
---|
1154 | *
|
---|
1155 | * @returns IPRT status code.
|
---|
1156 | * @param pThis The ASN.1 string object.
|
---|
1157 | * @param pcch Where to return the string length.
|
---|
1158 | */
|
---|
1159 | RTDECL(int) RTAsn1String_QueryUtf8Len(PCRTASN1STRING pThis, size_t *pcch);
|
---|
1160 |
|
---|
1161 | /**
|
---|
1162 | * Queries the UTF-8 string for an ASN.1 string object.
|
---|
1163 | *
|
---|
1164 | * This may fail as it may require memory to be allocated for storing the
|
---|
1165 | * string.
|
---|
1166 | *
|
---|
1167 | * @returns IPRT status code.
|
---|
1168 | * @param pString The ASN.1 string object. This is a const
|
---|
1169 | * parameter for making life easier on the caller,
|
---|
1170 | * however be aware that the object may be modified
|
---|
1171 | * by this call!
|
---|
1172 | * @param ppsz Where to return the pointer to the UTF-8 string.
|
---|
1173 | * Optional.
|
---|
1174 | * @param pcch Where to return the length (in 8-bit chars) to
|
---|
1175 | * of the UTF-8 string. Optional.
|
---|
1176 | */
|
---|
1177 | RTDECL(int) RTAsn1String_QueryUtf8(PCRTASN1STRING pString, const char **ppsz, size_t *pcch);
|
---|
1178 | RTDECL(int) RTAsn1String_RecodeAsUtf8(PRTASN1STRING pThis, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
1179 |
|
---|
1180 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTASN1SEQOFSTRINGS, RTASN1STRING, RTDECL, RTAsn1SeqOfStrings);
|
---|
1181 | RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTASN1SETOFSTRINGS, RTASN1STRING, RTDECL, RTAsn1SetOfStrings);
|
---|
1182 |
|
---|
1183 |
|
---|
1184 |
|
---|
1185 | /**
|
---|
1186 | * ASN.1 generic context specific tag (IPRT representation).
|
---|
1187 | *
|
---|
1188 | * Normally used to tag something that's optional, version specific or such.
|
---|
1189 | *
|
---|
1190 | * For the purpose of documenting the format with typedefs as well as possibly
|
---|
1191 | * making it a little more type safe, there's a set of typedefs for the most
|
---|
1192 | * commonly used tag values defined. These typedefs have are identical to
|
---|
1193 | * RTASN1CONTEXTTAG, except from the C++ type system of view.
|
---|
1194 | * tag values. These
|
---|
1195 | */
|
---|
1196 | typedef struct RTASN1CONTEXTTAG
|
---|
1197 | {
|
---|
1198 | /** Core ASN.1 encoding details. */
|
---|
1199 | RTASN1CORE Asn1Core;
|
---|
1200 | } RTASN1CONTEXTTAG;
|
---|
1201 | /** Pointer to an ASN.1 context tag (IPRT thing). */
|
---|
1202 | typedef RTASN1CONTEXTTAG *PRTASN1CONTEXTTAG;
|
---|
1203 | /** Pointer to a const ASN.1 context tag (IPRT thing). */
|
---|
1204 | typedef RTASN1CONTEXTTAG const *PCRTASN1CONTEXTTAG;
|
---|
1205 |
|
---|
1206 | RTDECL(int) RTAsn1ContextTagN_Init(PRTASN1CONTEXTTAG pThis, uint32_t uTag);
|
---|
1207 | RTDECL(int) RTAsn1ContextTagN_Clone(PRTASN1CONTEXTTAG pThis, PCRTASN1CONTEXTTAG pSrc, uint32_t uTag);
|
---|
1208 |
|
---|
1209 |
|
---|
1210 | /** @internal */
|
---|
1211 | #define RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(a_uTag) \
|
---|
1212 | typedef struct RT_CONCAT(RTASN1CONTEXTTAG,a_uTag) { RTASN1CORE Asn1Core; } RT_CONCAT(RTASN1CONTEXTTAG,a_uTag); \
|
---|
1213 | typedef RT_CONCAT(RTASN1CONTEXTTAG,a_uTag) *RT_CONCAT(PRTASN1CONTEXTTAG,a_uTag); \
|
---|
1214 | DECLINLINE(int) RT_CONCAT3(RTAsn1ContextTag,a_uTag,_Init)(RT_CONCAT(PRTASN1CONTEXTTAG,a_uTag) pThis, \
|
---|
1215 | PCRTASN1ALLOCATORVTABLE pAllocator) \
|
---|
1216 | { return RTAsn1ContextTagN_Init((PRTASN1CONTEXTTAG)pThis, a_uTag); } \
|
---|
1217 | DECLINLINE(int) RT_CONCAT3(RTAsn1ContextTag,a_uTag,_Clone)(RT_CONCAT(PRTASN1CONTEXTTAG,a_uTag) pThis, \
|
---|
1218 | RT_CONCAT(RTASN1CONTEXTTAG,a_uTag) const *pSrc) \
|
---|
1219 | { return RTAsn1ContextTagN_Clone((PRTASN1CONTEXTTAG)pThis, (PCRTASN1CONTEXTTAG)pSrc, a_uTag); } \
|
---|
1220 | typedef RT_CONCAT(RTASN1CONTEXTTAG,a_uTag) const *RT_CONCAT(PCRTASN1CONTEXTTAG,a_uTag)
|
---|
1221 | RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(0);
|
---|
1222 | RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(1);
|
---|
1223 | RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(2);
|
---|
1224 | RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(3);
|
---|
1225 | RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(4);
|
---|
1226 | RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(5);
|
---|
1227 | RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(6);
|
---|
1228 | RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE(7);
|
---|
1229 | #undef RTASN1CONTEXTTAG_DO_TYPEDEF_AND_INLINE
|
---|
1230 |
|
---|
1231 | /** Helper for comparing optional context tags.
|
---|
1232 | * This will return if both are not present or if their precense differs.
|
---|
1233 | * @internal */
|
---|
1234 | #define RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, a_uTag) \
|
---|
1235 | do { \
|
---|
1236 | /* type checks */ \
|
---|
1237 | RT_CONCAT(PCRTASN1CONTEXTTAG,a_uTag) const pMyLeftInternal = (a_pLeft); \
|
---|
1238 | RT_CONCAT(PCRTASN1CONTEXTTAG,a_uTag) const pMyRightInternal = (a_pRight); \
|
---|
1239 | (a_iDiff) = (int)RTASN1CORE_IS_PRESENT(&pMyLeftInternal->Asn1Core) \
|
---|
1240 | - (int)RTASN1CORE_IS_PRESENT(&pMyRightInternal->Asn1Core); \
|
---|
1241 | if ((a_iDiff) || !RTASN1CORE_IS_PRESENT(&pMyLeftInternal->Asn1Core)) return iDiff; \
|
---|
1242 | } while (0)
|
---|
1243 |
|
---|
1244 | /** Helpers for comparing optional context tags.
|
---|
1245 | * This will return if both are not present or if their precense differs.
|
---|
1246 | * @{ */
|
---|
1247 | #define RTASN1CONTEXTTAG0_COMPARE_PRESENT_RETURN(a_iDiff, a_pLeft, a_pRight) RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, 0)
|
---|
1248 | #define RTASN1CONTEXTTAG1_COMPARE_PRESENT_RETURN(a_iDiff, a_pLeft, a_pRight) RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, 1)
|
---|
1249 | #define RTASN1CONTEXTTAG2_COMPARE_PRESENT_RETURN(a_iDiff, a_pLeft, a_pRight) RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, 2)
|
---|
1250 | #define RTASN1CONTEXTTAG3_COMPARE_PRESENT_RETURN(a_iDiff, a_pLeft, a_pRight) RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, 3)
|
---|
1251 | #define RTASN1CONTEXTTAG4_COMPARE_PRESENT_RETURN(a_iDiff, a_pLeft, a_pRight) RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, 4)
|
---|
1252 | #define RTASN1CONTEXTTAG5_COMPARE_PRESENT_RETURN(a_iDiff, a_pLeft, a_pRight) RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, 5)
|
---|
1253 | #define RTASN1CONTEXTTAG6_COMPARE_PRESENT_RETURN(a_iDiff, a_pLeft, a_pRight) RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, 6)
|
---|
1254 | #define RTASN1CONTEXTTAG7_COMPARE_PRESENT_RETURN(a_iDiff, a_pLeft, a_pRight) RTASN1CONTEXTTAG_COMPARE_PRESENT_RETURN_INTERNAL(a_iDiff, a_pLeft, a_pRight, 7)
|
---|
1255 | /** @} */
|
---|
1256 |
|
---|
1257 |
|
---|
1258 | /**
|
---|
1259 | * Type information for dynamically bits (see RTASN1DYNTYPE).
|
---|
1260 | */
|
---|
1261 | typedef enum RTASN1TYPE
|
---|
1262 | {
|
---|
1263 | /** Not present. */
|
---|
1264 | RTASN1TYPE_NOT_PRESENT = 0,
|
---|
1265 | /** Generic ASN.1 for unknown tag/class. */
|
---|
1266 | RTASN1TYPE_CORE,
|
---|
1267 | /** ASN.1 NULL. */
|
---|
1268 | RTASN1TYPE_NULL,
|
---|
1269 | /** ASN.1 integer. */
|
---|
1270 | RTASN1TYPE_INTEGER,
|
---|
1271 | /** ASN.1 boolean. */
|
---|
1272 | RTASN1TYPE_BOOLEAN,
|
---|
1273 | /** ASN.1 character string. */
|
---|
1274 | RTASN1TYPE_STRING,
|
---|
1275 | /** ASN.1 octet string. */
|
---|
1276 | RTASN1TYPE_OCTET_STRING,
|
---|
1277 | /** ASN.1 bite string. */
|
---|
1278 | RTASN1TYPE_BIT_STRING,
|
---|
1279 | /** ASN.1 UTC or Generalize time. */
|
---|
1280 | RTASN1TYPE_TIME,
|
---|
1281 | #if 0
|
---|
1282 | /** ASN.1 sequence core. */
|
---|
1283 | RTASN1TYPE_SEQUENCE_CORE,
|
---|
1284 | /** ASN.1 set core. */
|
---|
1285 | RTASN1TYPE_SET_CORE,
|
---|
1286 | #endif
|
---|
1287 | /** ASN.1 object identifier. */
|
---|
1288 | RTASN1TYPE_OBJID,
|
---|
1289 | /** End of valid types. */
|
---|
1290 | RTASN1TYPE_END,
|
---|
1291 | /** Type size hack. */
|
---|
1292 | RTASN1TYPE_32BIT_HACK = 0x7fffffff
|
---|
1293 | } RTASN1TYPE;
|
---|
1294 |
|
---|
1295 |
|
---|
1296 | /**
|
---|
1297 | * ASN.1 dynamic type record.
|
---|
1298 | */
|
---|
1299 | typedef struct RTASN1DYNTYPE
|
---|
1300 | {
|
---|
1301 | /** Alternative interpretation provided by a user.
|
---|
1302 | * Before destroying this object, the user must explicitly free this and set
|
---|
1303 | * it to NULL, otherwise there will be memory leaks. */
|
---|
1304 | PRTASN1CORE pUser;
|
---|
1305 | /** The type of data we've got here. */
|
---|
1306 | RTASN1TYPE enmType;
|
---|
1307 | /** Union with data of the type dictated by enmType. */
|
---|
1308 | union
|
---|
1309 | {
|
---|
1310 | /** RTASN1TYPE_CORE. */
|
---|
1311 | RTASN1CORE Core;
|
---|
1312 | /** RTASN1TYPE_NULL. */
|
---|
1313 | RTASN1NULL Asn1Null;
|
---|
1314 | /** RTASN1TYPE_INTEGER. */
|
---|
1315 | RTASN1INTEGER Integer;
|
---|
1316 | /** RTASN1TYPE_BOOLEAN. */
|
---|
1317 | RTASN1BOOLEAN Boolean;
|
---|
1318 | /** RTASN1TYPE_STRING. */
|
---|
1319 | RTASN1STRING String;
|
---|
1320 | /** RTASN1TYPE_OCTET_STRING. */
|
---|
1321 | RTASN1OCTETSTRING OctetString;
|
---|
1322 | /** RTASN1TYPE_BIT_STRING. */
|
---|
1323 | RTASN1BITSTRING BitString;
|
---|
1324 | /** RTASN1TYPE_TIME. */
|
---|
1325 | RTASN1TIME Time;
|
---|
1326 | #if 0
|
---|
1327 | /** RTASN1TYPE_SEQUENCE_CORE. */
|
---|
1328 | RTASN1SEQUENCECORE SeqCore;
|
---|
1329 | /** RTASN1TYPE_SET_CORE. */
|
---|
1330 | RTASN1SETCORE SetCore;
|
---|
1331 | #endif
|
---|
1332 | /** RTASN1TYPE_OBJID. */
|
---|
1333 | RTASN1OBJID ObjId;
|
---|
1334 | } u;
|
---|
1335 | } RTASN1DYNTYPE;
|
---|
1336 | /** Pointer to an ASN.1 dynamic type record. */
|
---|
1337 | typedef RTASN1DYNTYPE *PRTASN1DYNTYPE;
|
---|
1338 | /** Pointer to a const ASN.1 dynamic type record. */
|
---|
1339 | typedef RTASN1DYNTYPE const *PCRTASN1DYNTYPE;
|
---|
1340 | RTASN1TYPE_STANDARD_PROTOTYPES(RTASN1DYNTYPE, RTDECL, RTAsn1DynType, u.Core);
|
---|
1341 |
|
---|
1342 |
|
---|
1343 | /** @name Virtual Method Table Based API
|
---|
1344 | * @{ */
|
---|
1345 | /**
|
---|
1346 | * Calls the destructor of the ASN.1 object.
|
---|
1347 | *
|
---|
1348 | * @param pAsn1Core The IPRT representation of an ASN.1 object.
|
---|
1349 | */
|
---|
1350 | RTDECL(void) RTAsn1VtDelete(PRTASN1CORE pThisCore);
|
---|
1351 |
|
---|
1352 | /**
|
---|
1353 | * Deep enumeration of all descendants.
|
---|
1354 | *
|
---|
1355 | * @returns IPRT status code, any non VINF_SUCCESS value stems from pfnCallback.
|
---|
1356 | * @param pThisCore Pointer to the ASN.1 core to enumerate members of.
|
---|
1357 | * @param pfnCallback The callback.
|
---|
1358 | * @param uDepth The depth of this object. Children are at +1.
|
---|
1359 | * @param pvUser Callback user argument.
|
---|
1360 | * @param fDepthFirst When set, recurse into child objects before calling
|
---|
1361 | * pfnCallback on then. When clear, the child object
|
---|
1362 | * is first
|
---|
1363 | */
|
---|
1364 | RTDECL(int) RTAsn1VtDeepEnum(PRTASN1CORE pThisCore, bool fDepthFirst, uint32_t uDepth,
|
---|
1365 | PFNRTASN1ENUMCALLBACK pfnCallback, void *pvUser);
|
---|
1366 |
|
---|
1367 | /**
|
---|
1368 | * Clones @a pSrcCore onto @a pThisCore.
|
---|
1369 | *
|
---|
1370 | * The caller must be sure that @a pSrcCore and @a pThisCore are of the same
|
---|
1371 | * types.
|
---|
1372 | *
|
---|
1373 | * @returns IPRT status code.
|
---|
1374 | * @param pThisCore Pointer to the ASN.1 core to clone onto. This shall
|
---|
1375 | * be uninitialized.
|
---|
1376 | * @param pSrcCore Pointer to the ASN.1 core to clone.
|
---|
1377 | * @param pAllocator The allocator to use.
|
---|
1378 | */
|
---|
1379 | RTDECL(int) RTAsn1VtClone(PRTASN1CORE pThisCore, PRTASN1CORE pSrcCore, PCRTASN1ALLOCATORVTABLE pAllocator);
|
---|
1380 |
|
---|
1381 | /**
|
---|
1382 | * Compares two objects.
|
---|
1383 | *
|
---|
1384 | * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
|
---|
1385 | * @param pLeftCore Pointer to the ASN.1 core of the left side object.
|
---|
1386 | * @param pRightCore Pointer to the ASN.1 core of the right side object.
|
---|
1387 | */
|
---|
1388 | RTDECL(int) RTAsn1VtCompare(PCRTASN1CORE pLeftCore, PCRTASN1CORE pRightCore);
|
---|
1389 |
|
---|
1390 | /**
|
---|
1391 | * Check sanity.
|
---|
1392 | *
|
---|
1393 | * A primary criteria is that the object is present and initialized.
|
---|
1394 | *
|
---|
1395 | * @returns IPRT status code.
|
---|
1396 | * @param pThisCore Pointer to the ASN.1 core of the object to check out.
|
---|
1397 | * @param fFlags See RTASN1_CHECK_SANITY_F_XXX.
|
---|
1398 | * @param pszErrInfo Where to return additional error details. Optional.
|
---|
1399 | * @param pszErrorTag Tag for the additional error details.
|
---|
1400 | */
|
---|
1401 | RTDECL(int) RTAsn1VtCheckSanity(PCRTASN1CORE pThisCore, uint32_t fFlags,
|
---|
1402 | PRTERRINFO pErrInfo, const char *pszErrorTag);
|
---|
1403 | /** @} */
|
---|
1404 |
|
---|
1405 |
|
---|
1406 | /** @defgroup rp_asn1_encode RTAsn1Encode - ASN.1 Encoding
|
---|
1407 | * @{ */
|
---|
1408 |
|
---|
1409 | /** @name RTASN1ENCODE_F_XXX
|
---|
1410 | * @{ */
|
---|
1411 | /** Use distinguished encoding rules (DER) to encode the object. */
|
---|
1412 | #define RTASN1ENCODE_F_DER UINT32_C(0x00000001)
|
---|
1413 | /** Use base encoding rules (BER) to encode the object.
|
---|
1414 | * This is currently the same as DER for practical reasons. */
|
---|
1415 | #define RTASN1ENCODE_F_BER RTASN1ENCODE_F_DER
|
---|
1416 | /** Mask of valid encoding rules. */
|
---|
1417 | #define RTASN1ENCODE_F_RULE_MASK UINT32_C(0x00000007)
|
---|
1418 | /** @} */
|
---|
1419 |
|
---|
1420 |
|
---|
1421 | /**
|
---|
1422 | * Recalculates cbHdr of and ASN.1 object.
|
---|
1423 | *
|
---|
1424 | * @returns IPRT status code.
|
---|
1425 | * @retval VINF_ASN1_NOT_ENCODED if the header size is zero (default value,
|
---|
1426 | * whatever).
|
---|
1427 | * @param pAsn1Core The object in question.
|
---|
1428 | * @param fFlags Valid combination of the RTASN1ENCODE_F_XXX
|
---|
1429 | * flags. Must include the encoding type.
|
---|
1430 | * @param pErrInfo Extended error info. Optional.
|
---|
1431 | */
|
---|
1432 | RTDECL(int) RTAsn1EncodeRecalcHdrSize(PRTASN1CORE pAsn1Core, uint32_t fFlags, PRTERRINFO pErrInfo);
|
---|
1433 |
|
---|
1434 | /**
|
---|
1435 | * Prepares the ASN.1 structure for encoding.
|
---|
1436 | *
|
---|
1437 | * The preparations is mainly calculating accurate object size, but may also
|
---|
1438 | * involve operations like recoding internal UTF-8 strings to the actual ASN.1
|
---|
1439 | * format and other things that may require memory to allocated/reallocated.
|
---|
1440 | *
|
---|
1441 | * @returns IPRT status code
|
---|
1442 | * @param pRoot The root of the ASN.1 object tree to encode.
|
---|
1443 | * @param fFlags Valid combination of the RTASN1ENCODE_F_XXX
|
---|
1444 | * flags. Must include the encoding type.
|
---|
1445 | * @param pcbEncoded Where to return the encoded size. Optional.
|
---|
1446 | * @param pErrInfo Where to store extended error information.
|
---|
1447 | * Optional.
|
---|
1448 | */
|
---|
1449 | RTDECL(int) RTAsn1EncodePrepare(PRTASN1CORE pRoot, uint32_t fFlags, uint32_t *pcbEncoded, PRTERRINFO pErrInfo);
|
---|
1450 |
|
---|
1451 | /**
|
---|
1452 | * Encodes and writes the header of an ASN.1 object.
|
---|
1453 | *
|
---|
1454 | * @returns IPRT status code.
|
---|
1455 | * @retval VINF_ASN1_NOT_ENCODED if nothing was written (default value,
|
---|
1456 | * whatever).
|
---|
1457 | * @param pAsn1Core The object in question.
|
---|
1458 | * @param fFlags Valid combination of the RTASN1ENCODE_F_XXX
|
---|
1459 | * flags. Must include the encoding type.
|
---|
1460 | * @param pfnWriter The output writer callback.
|
---|
1461 | * @param pvUser The user argument to pass to @a pfnWriter.
|
---|
1462 | * @param pErrInfo Where to store extended error information.
|
---|
1463 | * Optional.
|
---|
1464 | */
|
---|
1465 | RTDECL(int) RTAsnEncodeWriteHeader(PCRTASN1CORE pAsn1Core, uint32_t fFlags, FNRTASN1ENCODEWRITER pfnWriter, void *pvUser,
|
---|
1466 | PRTERRINFO pErrInfo);
|
---|
1467 |
|
---|
1468 | /**
|
---|
1469 | * Prepares the ASN.1 structure for encoding.
|
---|
1470 | *
|
---|
1471 | * The preparations is mainly calculating accurate object size, but may also
|
---|
1472 | * involve operations like recoding internal UTF-8 strings to the actual ASN.1
|
---|
1473 | * format and other things that may require memory to allocated/reallocated.
|
---|
1474 | *
|
---|
1475 | * @returns IPRT status code
|
---|
1476 | * @param pRoot The root of the ASN.1 object tree to encode.
|
---|
1477 | * @param fFlags Valid combination of the RTASN1ENCODE_F_XXX
|
---|
1478 | * flags. Must include the encoding type.
|
---|
1479 | * @param pfnWriter The output writer callback.
|
---|
1480 | * @param pvUser The user argument to pass to @a pfnWriter.
|
---|
1481 | * @param pErrInfo Where to store extended error information.
|
---|
1482 | * Optional.
|
---|
1483 | */
|
---|
1484 | RTDECL(int) RTAsn1EncodeWrite(PCRTASN1CORE pRoot, uint32_t fFlags, FNRTASN1ENCODEWRITER pfnWriter, void *pvUser,
|
---|
1485 | PRTERRINFO pErrInfo);
|
---|
1486 |
|
---|
1487 | /** @} */
|
---|
1488 |
|
---|
1489 |
|
---|
1490 |
|
---|
1491 | /** @defgroup rp_asn1_cursor RTAsn1Cursor - BER, DER, and CER cursor
|
---|
1492 | * @{ */
|
---|
1493 |
|
---|
1494 | /**
|
---|
1495 | * ASN.1 decoder byte cursor.
|
---|
1496 | */
|
---|
1497 | typedef struct RTASN1CURSOR
|
---|
1498 | {
|
---|
1499 | /** Pointer to the current (next) byte. */
|
---|
1500 | uint8_t const *pbCur;
|
---|
1501 | /** Number of bytes left to decode. */
|
---|
1502 | uint32_t cbLeft;
|
---|
1503 | /** RTASN1CURSOR_FLAGS_XXX. */
|
---|
1504 | uint8_t fFlags;
|
---|
1505 | /** The cursor depth. */
|
---|
1506 | uint8_t cDepth;
|
---|
1507 | /** Two bytes reserved for future tricks. */
|
---|
1508 | uint8_t abReserved[2];
|
---|
1509 | /** Pointer to the primary cursor. */
|
---|
1510 | struct RTASN1CURSORPRIMARY *pPrimary;
|
---|
1511 | /** Pointer to the parent cursor. */
|
---|
1512 | struct RTASN1CURSOR *pUp;
|
---|
1513 | /** The error tag for this cursor level. */
|
---|
1514 | const char *pszErrorTag;
|
---|
1515 | } RTASN1CURSOR;
|
---|
1516 |
|
---|
1517 | /** @name RTASN1CURSOR_FLAGS_XXX - Cursor flags.
|
---|
1518 | * @{ */
|
---|
1519 | /** Enforce DER rules. */
|
---|
1520 | #define RTASN1CURSOR_FLAGS_DER RT_BIT(1)
|
---|
1521 | /** Enforce CER rules. */
|
---|
1522 | #define RTASN1CURSOR_FLAGS_CER RT_BIT(2)
|
---|
1523 | /** @} */
|
---|
1524 |
|
---|
1525 |
|
---|
1526 | typedef struct RTASN1CURSORPRIMARY
|
---|
1527 | {
|
---|
1528 | /** The normal cursor bits. */
|
---|
1529 | RTASN1CURSOR Cursor;
|
---|
1530 | /** For error reporting. */
|
---|
1531 | PRTERRINFO pErrInfo;
|
---|
1532 | /** The allocator virtual method table. */
|
---|
1533 | PCRTASN1ALLOCATORVTABLE pAllocator;
|
---|
1534 | } RTASN1CURSORPRIMARY;
|
---|
1535 | typedef RTASN1CURSORPRIMARY *PRTASN1CURSORPRIMARY;
|
---|
1536 |
|
---|
1537 |
|
---|
1538 | /**
|
---|
1539 | * Initializes a primary cursor.
|
---|
1540 | *
|
---|
1541 | * The primary cursor is special in that it stores information shared with the
|
---|
1542 | * sub-cursors created by methods like RTAsn1CursorGetContextTagNCursor and
|
---|
1543 | * RTAsn1CursorGetSequenceCursor. Even if just sharing a few items at present,
|
---|
1544 | * it still important to save every possible byte since stack space is scarce in
|
---|
1545 | * some of the execution environments.
|
---|
1546 | *
|
---|
1547 | * @returns Pointer to pCursor->Cursor.
|
---|
1548 | * @param pPrimaryCursor The primary cursor structure to initialize.
|
---|
1549 | * @param pvFirst The first byte to decode.
|
---|
1550 | * @param cb The number of bytes to decode.
|
---|
1551 | * @param pErrInfo Where to store error information.
|
---|
1552 | * @param pAllocator The allocator to use.
|
---|
1553 | * @param fFlags RTASN1CURSOR_FLAGS_XXX.
|
---|
1554 | * @param pszErrorTag The primary error tag.
|
---|
1555 | */
|
---|
1556 | RTDECL(PRTASN1CURSOR) RTAsn1CursorInitPrimary(PRTASN1CURSORPRIMARY pPrimaryCursor, void const *pvFirst, uint32_t cb,
|
---|
1557 | PRTERRINFO pErrInfo, PCRTASN1ALLOCATORVTABLE pAllocator, uint32_t fFlags,
|
---|
1558 | const char *pszErrorTag);
|
---|
1559 |
|
---|
1560 |
|
---|
1561 | /**
|
---|
1562 | * Initialize a sub-cursor for traversing the content of an ASN.1 object.
|
---|
1563 | *
|
---|
1564 | * @returns IPRT status code.
|
---|
1565 | * @param pParent The parent cursor.
|
---|
1566 | * @param pAsn1Core The ASN.1 object which content we should
|
---|
1567 | * traverse with the sub-cursor.
|
---|
1568 | * @param pChild The sub-cursor to initialize.
|
---|
1569 | * @param pszErrorTag The error tag of the sub-cursor.
|
---|
1570 | */
|
---|
1571 | RTDECL(int) RTAsn1CursorInitSubFromCore(PRTASN1CURSOR pParent, PRTASN1CORE pAsn1Core,
|
---|
1572 | PRTASN1CURSOR pChild, const char *pszErrorTag);
|
---|
1573 |
|
---|
1574 | /**
|
---|
1575 | * Initalizes the an allocation structure prior to making an allocation.
|
---|
1576 | *
|
---|
1577 | * To try unify and optimize memory managment for decoding and in-memory
|
---|
1578 | * construction of ASN.1 objects, each allocation has an allocation structure
|
---|
1579 | * associated with it. This stores the allocator and keep statistics for
|
---|
1580 | * optimizing array allocations.
|
---|
1581 | *
|
---|
1582 | * @returns Pointer to the allocator info (for call in alloc parameter).
|
---|
1583 | * @param pCursor The cursor.
|
---|
1584 | * @param pAllocator The allocation structure to initialize.
|
---|
1585 | */
|
---|
1586 | RTDECL(PRTASN1ALLOCATION) RTAsn1CursorInitAllocation(PRTASN1CURSOR pCursor, PRTASN1ALLOCATION pAllocation);
|
---|
1587 |
|
---|
1588 |
|
---|
1589 | /**
|
---|
1590 | * Wrapper around RTErrInfoSetV.
|
---|
1591 | *
|
---|
1592 | * @returns @a rc
|
---|
1593 | * @param pCursor The cursor.
|
---|
1594 | * @param rc The return code to return.
|
---|
1595 | * @param pszMsg Message format string.
|
---|
1596 | * @param ... Format arguments.
|
---|
1597 | */
|
---|
1598 | RTDECL(int) RTAsn1CursorSetInfo(PRTASN1CURSOR pCursor, int rc, const char *pszMsg, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
1599 |
|
---|
1600 | /**
|
---|
1601 | * Wrapper around RTErrInfoSetV.
|
---|
1602 | *
|
---|
1603 | * @returns @a rc
|
---|
1604 | * @param pCursor The cursor.
|
---|
1605 | * @param rc The return code to return.
|
---|
1606 | * @param pszMsg Message format string.
|
---|
1607 | * @param va Format arguments.
|
---|
1608 | */
|
---|
1609 | RTDECL(int) RTAsn1CursorSetInfoV(PRTASN1CURSOR pCursor, int rc, const char *pszMsg, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
|
---|
1610 |
|
---|
1611 | /**
|
---|
1612 | * Checks that we've reached the end of the data for the cursor.
|
---|
1613 | *
|
---|
1614 | * @returns IPRT status code.
|
---|
1615 | * @param pCursor The cursor we're decoding from.
|
---|
1616 | */
|
---|
1617 | RTDECL(int) RTAsn1CursorCheckEnd(PRTASN1CURSOR pCursor);
|
---|
1618 |
|
---|
1619 |
|
---|
1620 | /**
|
---|
1621 | * Skips a given number of bytes.
|
---|
1622 | *
|
---|
1623 | * @returns @a pCursor
|
---|
1624 | * @param pCursor The cursor.
|
---|
1625 | * @param cb The number of bytes to skip.
|
---|
1626 | * @internal
|
---|
1627 | */
|
---|
1628 | DECLINLINE(PRTASN1CURSOR) RTAsn1CursorSkip(PRTASN1CURSOR pCursor, uint32_t cb)
|
---|
1629 | {
|
---|
1630 | if (cb <= pCursor->cbLeft)
|
---|
1631 | {
|
---|
1632 | pCursor->cbLeft -= cb;
|
---|
1633 | pCursor->pbCur += cb;
|
---|
1634 | }
|
---|
1635 | else
|
---|
1636 | {
|
---|
1637 | pCursor->pbCur += pCursor->cbLeft;
|
---|
1638 | pCursor->cbLeft = 0;
|
---|
1639 | }
|
---|
1640 |
|
---|
1641 | return pCursor;
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 | /**
|
---|
1645 | * Low-level function for reading an ASN.1 header.
|
---|
1646 | *
|
---|
1647 | * @returns IPRT status code.
|
---|
1648 | * @param pCursor The cursor we're decoding from.
|
---|
1649 | * @param pAsn1Core The output object core.
|
---|
1650 | * @param pszErrorTag Error tag.
|
---|
1651 | * @internal
|
---|
1652 | */
|
---|
1653 | RTDECL(int) RTAsn1CursorReadHdr(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core, const char *pszErrorTag);
|
---|
1654 |
|
---|
1655 | /**
|
---|
1656 | * Common helper for simple tag matching.
|
---|
1657 | *
|
---|
1658 | * @returns IPRT status code.
|
---|
1659 | * @param pCursor The cursor (for error reporting).
|
---|
1660 | * @param pAsn1Core The ASN.1 core structure.
|
---|
1661 | * @param uTag The expected tag.
|
---|
1662 | * @param fClass The expected class.
|
---|
1663 | * @param fString Set if it's a string type that shall follow
|
---|
1664 | * special CER and DER rules wrt to constructed and
|
---|
1665 | * primitive encoding.
|
---|
1666 | * @param fFlags The RTASN1CURSOR_GET_F_XXX flags.
|
---|
1667 | * @param pszErrorTag The error tag.
|
---|
1668 | * @param pszWhat The type/whatever name.
|
---|
1669 | */
|
---|
1670 | RTDECL(int) RTAsn1CursorMatchTagClassFlagsEx(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core, uint32_t uTag, uint32_t fClass,
|
---|
1671 | bool fString, uint32_t fFlags, const char *pszErrorTag, const char *pszWhat);
|
---|
1672 |
|
---|
1673 | /**
|
---|
1674 | * Common helper for simple tag matching.
|
---|
1675 | *
|
---|
1676 | * @returns IPRT status code.
|
---|
1677 | * @param pCursor The cursor (for error reporting).
|
---|
1678 | * @param pAsn1Core The ASN.1 core structure.
|
---|
1679 | * @param uTag The expected tag.
|
---|
1680 | * @param fClass The expected class.
|
---|
1681 | * @param fFlags The RTASN1CURSOR_GET_F_XXX flags.
|
---|
1682 | * @param pszErrorTag The error tag.
|
---|
1683 | * @param pszWhat The type/whatever name.
|
---|
1684 | * @internal
|
---|
1685 | */
|
---|
1686 | DECLINLINE(int) RTAsn1CursorMatchTagClassFlags(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core, uint32_t uTag, uint32_t fClass,
|
---|
1687 | uint32_t fFlags, const char *pszErrorTag, const char *pszWhat)
|
---|
1688 | {
|
---|
1689 | if (pAsn1Core->uTag == uTag && pAsn1Core->fClass == fClass)
|
---|
1690 | return VINF_SUCCESS;
|
---|
1691 | return RTAsn1CursorMatchTagClassFlagsEx(pCursor, pAsn1Core, uTag, fClass, false /*fString*/, fFlags, pszErrorTag, pszWhat);
|
---|
1692 | }
|
---|
1693 |
|
---|
1694 |
|
---|
1695 | /**
|
---|
1696 | * Common helper for simple tag matching for strings.
|
---|
1697 | *
|
---|
1698 | * Check string encoding considerations.
|
---|
1699 | *
|
---|
1700 | * @returns IPRT status code.
|
---|
1701 | * @param pCursor The cursor (for error reporting).
|
---|
1702 | * @param pAsn1Core The ASN.1 core structure.
|
---|
1703 | * @param uTag The expected tag.
|
---|
1704 | * @param fClass The expected class.
|
---|
1705 | * @param fFlags The RTASN1CURSOR_GET_F_XXX flags.
|
---|
1706 | * @param pszErrorTag The error tag.
|
---|
1707 | * @param pszWhat The type/whatever name.
|
---|
1708 | * @internal
|
---|
1709 | */
|
---|
1710 | DECLINLINE(int) RTAsn1CursorMatchTagClassFlagsString(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core, uint32_t uTag, uint32_t fClass,
|
---|
1711 | uint32_t fFlags, const char *pszErrorTag, const char *pszWhat)
|
---|
1712 | {
|
---|
1713 | if (pAsn1Core->uTag == uTag && pAsn1Core->fClass == fClass)
|
---|
1714 | return VINF_SUCCESS;
|
---|
1715 | return RTAsn1CursorMatchTagClassFlagsEx(pCursor, pAsn1Core, uTag, fClass, true /*fString*/, fFlags, pszErrorTag, pszWhat);
|
---|
1716 | }
|
---|
1717 |
|
---|
1718 |
|
---|
1719 |
|
---|
1720 | /** @name RTASN1CURSOR_GET_F_XXX - Common flags for all the getters.
|
---|
1721 | * @{ */
|
---|
1722 | /** Used for decoding objects with implicit tags assigned to them. This only
|
---|
1723 | * works when calling getters with a unambigious types. */
|
---|
1724 | #define RTASN1CURSOR_GET_F_IMPLICIT RT_BIT_32(0)
|
---|
1725 | /** @} */
|
---|
1726 |
|
---|
1727 | /**
|
---|
1728 | * Read ANY object.
|
---|
1729 | *
|
---|
1730 | * @returns IPRT status code.
|
---|
1731 | * @param pCursor The cursor we're decoding from.
|
---|
1732 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1733 | * @param pAsn1Core The output object core.
|
---|
1734 | * @param pszErrorTag Error tag.
|
---|
1735 | */
|
---|
1736 | RTDECL(int) RTAsn1CursorGetCore(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1CORE pAsn1Core, const char *pszErrorTag);
|
---|
1737 |
|
---|
1738 | /**
|
---|
1739 | * Read a NULL object.
|
---|
1740 | *
|
---|
1741 | * @returns IPRT status code.
|
---|
1742 | * @param pCursor The cursor we're decoding from.
|
---|
1743 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1744 | * @param pNull The output NULL object.
|
---|
1745 | * @param pszErrorTag Error tag.
|
---|
1746 | */
|
---|
1747 | RTDECL(int) RTAsn1CursorGetNull(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1NULL pNull, const char *pszErrorTag);
|
---|
1748 |
|
---|
1749 | /**
|
---|
1750 | * Read an INTEGER object.
|
---|
1751 | *
|
---|
1752 | * @returns IPRT status code.
|
---|
1753 | * @param pCursor The cursor we're decoding from.
|
---|
1754 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1755 | * @param pInteger The output integer object.
|
---|
1756 | * @param pszErrorTag Error tag.
|
---|
1757 | */
|
---|
1758 | RTDECL(int) RTAsn1CursorGetInteger(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1INTEGER pInteger, const char *pszErrorTag);
|
---|
1759 |
|
---|
1760 | /**
|
---|
1761 | * Read an BOOLEAN object.
|
---|
1762 | *
|
---|
1763 | * @returns IPRT status code.
|
---|
1764 | * @param pCursor The cursor we're decoding from.
|
---|
1765 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1766 | * @param pBoolean The output boolean object.
|
---|
1767 | * @param pszErrorTag Error tag.
|
---|
1768 | */
|
---|
1769 | RTDECL(int) RTAsn1CursorGetBoolean(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1BOOLEAN pBoolean, const char *pszErrorTag);
|
---|
1770 |
|
---|
1771 | /**
|
---|
1772 | * Retrives an object identifier (aka ObjId or OID) item from the ASN.1 stream.
|
---|
1773 | *
|
---|
1774 | * @returns IPRT status code.
|
---|
1775 | * @param pCursor The cursor.
|
---|
1776 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1777 | * @param pObjId The output ODI object.
|
---|
1778 | * @param pszErrorTag Error tag.
|
---|
1779 | */
|
---|
1780 | RTDECL(int) RTAsn1CursorGetObjId(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1OBJID pObjId, const char *pszErrorTag);
|
---|
1781 |
|
---|
1782 | /**
|
---|
1783 | * Retrives and verifies an object identifier.
|
---|
1784 | *
|
---|
1785 | * @returns IPRT status code.
|
---|
1786 | * @param pCursor The cursor.
|
---|
1787 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1788 | * @param pObjId Where to return the parsed object ID, optional.
|
---|
1789 | * @param pszExpectedObjId The expected object identifier (dotted).
|
---|
1790 | * @param pszErrorTag Error tag.
|
---|
1791 | */
|
---|
1792 | RTDECL(int) RTAsn1CursorGetAndCheckObjId(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1OBJID pObjId,
|
---|
1793 | const char *pszExpectedObjId, const char *pszErrorTag);
|
---|
1794 |
|
---|
1795 | /**
|
---|
1796 | * Read an UTC TIME or GENERALIZED TIME object.
|
---|
1797 | *
|
---|
1798 | * @returns IPRT status code.
|
---|
1799 | * @param pCursor The cursor we're decoding from.
|
---|
1800 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1801 | * @param pTime The output time object.
|
---|
1802 | * @param pszErrorTag Error tag.
|
---|
1803 | */
|
---|
1804 | RTDECL(int) RTAsn1CursorGetTime(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1TIME pTime, const char *pszErrorTag);
|
---|
1805 |
|
---|
1806 | /**
|
---|
1807 | * Read an BIT STRING object (skips past the content).
|
---|
1808 | *
|
---|
1809 | * @returns IPRT status ocde.
|
---|
1810 | * @param pCursor The cursor.
|
---|
1811 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1812 | * @param pBitString The output bit string object.
|
---|
1813 | * @param pszErrorTag Error tag.
|
---|
1814 | */
|
---|
1815 | RTDECL(int) RTAsn1CursorGetBitString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1BITSTRING pBitString,
|
---|
1816 | const char *pszErrorTag);
|
---|
1817 |
|
---|
1818 | /**
|
---|
1819 | * Read an BIT STRING object (skips past the content), extended version with
|
---|
1820 | * cMaxBits.
|
---|
1821 | *
|
---|
1822 | * @returns IPRT status ocde.
|
---|
1823 | * @param pCursor The cursor.
|
---|
1824 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1825 | * @param cMaxBits The max length of the bit string in bits. Pass
|
---|
1826 | * UINT32_MAX if variable size.
|
---|
1827 | * @param pBitString The output bit string object.
|
---|
1828 | * @param pszErrorTag Error tag.
|
---|
1829 | */
|
---|
1830 | RTDECL(int) RTAsn1CursorGetBitStringEx(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t cMaxBits, PRTASN1BITSTRING pBitString,
|
---|
1831 | const char *pszErrorTag);
|
---|
1832 |
|
---|
1833 | /**
|
---|
1834 | * Read an OCTET STRING object (skips past the content).
|
---|
1835 | *
|
---|
1836 | * @returns IPRT status ocde.
|
---|
1837 | * @param pCursor The cursor.
|
---|
1838 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1839 | * @param pOctetString The output octet string object.
|
---|
1840 | * @param pszErrorTag Error tag.
|
---|
1841 | */
|
---|
1842 | RTDECL(int) RTAsn1CursorGetOctetString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1OCTETSTRING pOctetString,
|
---|
1843 | const char *pszErrorTag);
|
---|
1844 |
|
---|
1845 | /**
|
---|
1846 | * Read any kind of string object, except 'character string (29)'.
|
---|
1847 | *
|
---|
1848 | * @returns IPRT status code.
|
---|
1849 | * @param pCursor The cursor we're decoding from.
|
---|
1850 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1851 | * @param pString The output boolean object.
|
---|
1852 | * @param pszErrorTag Error tag.
|
---|
1853 | */
|
---|
1854 | RTDECL(int) RTAsn1CursorGetString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag);
|
---|
1855 |
|
---|
1856 | /**
|
---|
1857 | * Read a IA5 STRING object.
|
---|
1858 | *
|
---|
1859 | * @returns IPRT status code.
|
---|
1860 | * @param pCursor The cursor we're decoding from.
|
---|
1861 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1862 | * @param pString The output boolean object.
|
---|
1863 | * @param pszErrorTag Error tag.
|
---|
1864 | */
|
---|
1865 | RTDECL(int) RTAsn1CursorGetIa5String(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag);
|
---|
1866 |
|
---|
1867 | /**
|
---|
1868 | * Read a UTF8 STRING object.
|
---|
1869 | *
|
---|
1870 | * @returns IPRT status code.
|
---|
1871 | * @param pCursor The cursor we're decoding from.
|
---|
1872 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1873 | * @param pString The output boolean object.
|
---|
1874 | * @param pszErrorTag Error tag.
|
---|
1875 | */
|
---|
1876 | RTDECL(int) RTAsn1CursorGetUtf8String(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag);
|
---|
1877 |
|
---|
1878 | /**
|
---|
1879 | * Read a BMP STRING (UCS-2) object.
|
---|
1880 | *
|
---|
1881 | * @returns IPRT status code.
|
---|
1882 | * @param pCursor The cursor we're decoding from.
|
---|
1883 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1884 | * @param pString The output boolean object.
|
---|
1885 | * @param pszErrorTag Error tag.
|
---|
1886 | */
|
---|
1887 | RTDECL(int) RTAsn1CursorGetBmpString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag);
|
---|
1888 |
|
---|
1889 | /**
|
---|
1890 | * Read a SEQUENCE object and create a cursor for its content.
|
---|
1891 | *
|
---|
1892 | * @returns IPRT status code.
|
---|
1893 | * @param pCursor The cursor we're decoding from.
|
---|
1894 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1895 | * @param pSeqCore The output sequence core object.
|
---|
1896 | * @param pSeqCursor The output cursor for the sequence content.
|
---|
1897 | * @param pszErrorTag Error tag, this will be associated with the
|
---|
1898 | * returned cursor.
|
---|
1899 | */
|
---|
1900 | RTDECL(int) RTAsn1CursorGetSequenceCursor(PRTASN1CURSOR pCursor, uint32_t fFlags,
|
---|
1901 | PRTASN1SEQUENCECORE pSeqCore, PRTASN1CURSOR pSeqCursor, const char *pszErrorTag);
|
---|
1902 |
|
---|
1903 | /**
|
---|
1904 | * Read a SET object and create a cursor for its content.
|
---|
1905 | *
|
---|
1906 | * @returns IPRT status code.
|
---|
1907 | * @param pCursor The cursor we're decoding from.
|
---|
1908 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1909 | * @param pSetCore The output set core object.
|
---|
1910 | * @param pSetCursor The output cursor for the set content.
|
---|
1911 | * @param pszErrorTag Error tag, this will be associated with the
|
---|
1912 | * returned cursor.
|
---|
1913 | */
|
---|
1914 | RTDECL(int) RTAsn1CursorGetSetCursor(PRTASN1CURSOR pCursor, uint32_t fFlags,
|
---|
1915 | PRTASN1SETCORE pSetCore, PRTASN1CURSOR pSetCursor, const char *pszErrorTag);
|
---|
1916 |
|
---|
1917 | /**
|
---|
1918 | * Read a given constructed context tag and create a cursor for its content.
|
---|
1919 | *
|
---|
1920 | * @returns IPRT status code.
|
---|
1921 | * @param pCursor The cursor we're decoding from.
|
---|
1922 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1923 | * @param pCtxTagCore The output context tag object.
|
---|
1924 | * @param pCtxTagCursor The output cursor for the context tag content.
|
---|
1925 | * @param pszErrorTag Error tag, this will be associated with the
|
---|
1926 | * returned cursor.
|
---|
1927 | *
|
---|
1928 | * @remarks There are specialized version of this function for each of the
|
---|
1929 | * numbered context tag structures, like for RTASN1CONTEXTTAG0 there is
|
---|
1930 | * RTAsn1CursorGetContextTag0Cursor.
|
---|
1931 | */
|
---|
1932 | RTDECL(int) RTAsn1CursorGetContextTagNCursor(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t uExpectedTag,
|
---|
1933 | PRTASN1CONTEXTTAG pCtxTag, PRTASN1CURSOR pCtxTagCursor, const char *pszErrorTag);
|
---|
1934 |
|
---|
1935 | /**
|
---|
1936 | * Read a dynamic ASN.1 type.
|
---|
1937 | *
|
---|
1938 | * @returns IPRT status code.
|
---|
1939 | * @param pCursor The cursor we're decoding from.
|
---|
1940 | * @param fFlags RTASN1CURSOR_GET_F_XXX.
|
---|
1941 | * @param pDynType The output context tag object.
|
---|
1942 | * @param pszErrorTag Error tag.
|
---|
1943 | */
|
---|
1944 | RTDECL(int) RTAsn1CursorGetDynType(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1DYNTYPE pDynType, const char *pszErrorTag);
|
---|
1945 |
|
---|
1946 | /**
|
---|
1947 | * Peeks at the next ASN.1 object.
|
---|
1948 | *
|
---|
1949 | * @returns IPRT status code.
|
---|
1950 | * @param pCursor The cursore we're decoding from.
|
---|
1951 | * @param pAsn1Core Where to store the output of the peek.
|
---|
1952 | */
|
---|
1953 | RTDECL(int) RTAsn1CursorPeek(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core);
|
---|
1954 |
|
---|
1955 | /**
|
---|
1956 | * Checks if the next ASN.1 object matches the given tag and class/flags.
|
---|
1957 | *
|
---|
1958 | * @returns @c true on match, @c false on mismatch.
|
---|
1959 | * @param pCursor The cursore we're decoding from.
|
---|
1960 | * @param uTag The tag number to match against.
|
---|
1961 | * @param fClass The tag class and flags to match against.
|
---|
1962 | */
|
---|
1963 | RTDECL(bool) RTAsn1CursorIsNextEx(PRTASN1CURSOR pCursor, uint32_t uTag, uint8_t fClass);
|
---|
1964 |
|
---|
1965 |
|
---|
1966 |
|
---|
1967 | /** @internal */
|
---|
1968 | #define RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(a_uTag) \
|
---|
1969 | DECLINLINE(int) RT_CONCAT3(RTAsn1CursorGetContextTag,a_uTag,Cursor)(PRTASN1CURSOR pCursor, uint32_t fFlags, \
|
---|
1970 | RT_CONCAT(PRTASN1CONTEXTTAG,a_uTag) pCtxTag, \
|
---|
1971 | PRTASN1CURSOR pCtxTagCursor, const char *pszErrorTag) \
|
---|
1972 | { /* Constructed is automatically implied if you need a cursor to it. */ \
|
---|
1973 | return RTAsn1CursorGetContextTagNCursor(pCursor, fFlags, a_uTag, (PRTASN1CONTEXTTAG)pCtxTag, pCtxTagCursor, pszErrorTag); \
|
---|
1974 | } \
|
---|
1975 | DECLINLINE(int) RT_CONCAT3(RTAsn1ContextTag,a_uTag,InitDefault)(RT_CONCAT(PRTASN1CONTEXTTAG,a_uTag) pCtxTag) \
|
---|
1976 | { /* Constructed is automatically implied if you need to init it with a default value. */ \
|
---|
1977 | return RTAsn1Core_InitDefault(&pCtxTag->Asn1Core, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED); \
|
---|
1978 | } \
|
---|
1979 | DECLINLINE(int) RT_CONCAT3(RTAsn1CursorIsConstructedContextTag,a_uTag,Next)(PRTASN1CURSOR pCursor) \
|
---|
1980 | { \
|
---|
1981 | return RTAsn1CursorIsNextEx(pCursor, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED); \
|
---|
1982 | } \
|
---|
1983 | DECLINLINE(int) RT_CONCAT3(RTAsn1CursorIsPrimitiveContextTag,a_uTag,Next)(PRTASN1CURSOR pCursor) \
|
---|
1984 | { \
|
---|
1985 | return RTAsn1CursorIsNextEx(pCursor, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_PRIMITIVE); \
|
---|
1986 | } \
|
---|
1987 | DECLINLINE(int) RT_CONCAT3(RTAsn1CursorIsAnyContextTag,a_uTag,Next)(PRTASN1CURSOR pCursor) \
|
---|
1988 | { \
|
---|
1989 | return RTAsn1CursorIsNextEx(pCursor, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED) \
|
---|
1990 | || RTAsn1CursorIsNextEx(pCursor, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_PRIMITIVE);\
|
---|
1991 | } \
|
---|
1992 |
|
---|
1993 | RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(0)
|
---|
1994 | RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(1)
|
---|
1995 | RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(2)
|
---|
1996 | RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(3)
|
---|
1997 | RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(4)
|
---|
1998 | RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(5)
|
---|
1999 | RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(6)
|
---|
2000 | RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES(7)
|
---|
2001 | #undef RTASN1CONTEXTTAG_IMPL_CURSOR_INLINES
|
---|
2002 |
|
---|
2003 |
|
---|
2004 | /**
|
---|
2005 | * Checks if the next object is a boolean.
|
---|
2006 | *
|
---|
2007 | * @returns true / false
|
---|
2008 | * @param pCursor The cursore we're decoding from.
|
---|
2009 | * @remarks May produce error info output on mismatch.
|
---|
2010 | */
|
---|
2011 | DECLINLINE(bool) RTAsn1CursorIsBooleanNext(PRTASN1CURSOR pCursor)
|
---|
2012 | {
|
---|
2013 | return RTAsn1CursorIsNextEx(pCursor, ASN1_TAG_BOOLEAN, ASN1_TAGFLAG_PRIMITIVE | ASN1_TAGCLASS_UNIVERSAL);
|
---|
2014 | }
|
---|
2015 |
|
---|
2016 |
|
---|
2017 | /**
|
---|
2018 | * Checks if the next object is a set.
|
---|
2019 | *
|
---|
2020 | * @returns true / false
|
---|
2021 | * @param pCursor The cursore we're decoding from.
|
---|
2022 | * @remarks May produce error info output on mismatch.
|
---|
2023 | */
|
---|
2024 | DECLINLINE(bool) RTAsn1CursorIsSetNext(PRTASN1CURSOR pCursor)
|
---|
2025 | {
|
---|
2026 | return RTAsn1CursorIsNextEx(pCursor, ASN1_TAG_SET, ASN1_TAGFLAG_CONSTRUCTED | ASN1_TAGCLASS_UNIVERSAL);
|
---|
2027 | }
|
---|
2028 |
|
---|
2029 |
|
---|
2030 | /** @} */
|
---|
2031 |
|
---|
2032 |
|
---|
2033 | /** @name ASN.1 Utility APIs
|
---|
2034 | * @{ */
|
---|
2035 |
|
---|
2036 | /**
|
---|
2037 | * Dumps an IPRT representation of a ASN.1 object tree.
|
---|
2038 | *
|
---|
2039 | * @returns IPRT status code.
|
---|
2040 | * @param pAsn1Core The ASN.1 object which members should be dumped.
|
---|
2041 | * @param fFlags RTASN1DUMP_F_XXX.
|
---|
2042 | * @param uLevel The indentation level to start at.
|
---|
2043 | * @param pfnPrintfV The output function.
|
---|
2044 | * @param pvUser Argument to the output function.
|
---|
2045 | */
|
---|
2046 | RTDECL(int) RTAsn1Dump(PCRTASN1CORE pAsn1Core, uint32_t fFlags, uint32_t uLevel, PFNRTDUMPPRINTFV pfnPrintfV, void *pvUser);
|
---|
2047 |
|
---|
2048 | /** @} */
|
---|
2049 |
|
---|
2050 | /** @} */
|
---|
2051 |
|
---|
2052 | RT_C_DECLS_END
|
---|
2053 |
|
---|
2054 | #endif
|
---|
2055 |
|
---|