VirtualBox

source: vbox/trunk/include/iprt/asn1.h@ 82968

Last change on this file since 82968 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette