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