VirtualBox

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

Last change on this file since 74942 was 74760, checked in by vboxsync, 6 years ago

IPRT/ldr/asn1/pkcs7: Ironed out issues in decoding indefinite ASN.1 length records and successfully verified the first Mach-O signature. bugref:9232

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

© 2023 Oracle
ContactPrivacy policyTerms of Use