QSC Post Quantum Cryptographic Library 1.1.0.2 (B2)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
asn1.h File Reference

ASN.1 helper functions and data types built on the QSC BER and DER encoding layer. More...

#include "qsccommon.h"
#include "encoding.h"

Go to the source code of this file.

Data Structures

struct  qsc_asn1_oid_t
 A decoded ASN.1 OBJECT IDENTIFIER. More...
struct  qsc_asn1_bit_string_t
 A normalized ASN.1 BIT STRING representation. More...
struct  qsc_asn1_time_t
 A normalized ASN.1 time representation. More...

Macros

#define QSC_ASN1_OID_MAX_SIZE   32U
 The maximum number of encoded OBJECT IDENTIFIER bytes supported by the helper layer.
#define QSC_ASN1_OID_MAX_ARCS   16U
 The maximum number of arcs stored in the decoded OBJECT IDENTIFIER structure.
#define QSC_ASN1_BIT_STRING_MAX_UNUSED_BITS   7U
 The maximum legal number of unused bits in a BIT STRING final octet.

Typedefs

typedef enum qsc_asn1_status_t qsc_asn1_status
 ASN.1 helper status codes.
typedef QSC_EXPORT_API struct qsc_asn1_oid_t qsc_asn1_oid
 A decoded ASN.1 OBJECT IDENTIFIER.
typedef QSC_EXPORT_API struct qsc_asn1_bit_string_t qsc_asn1_bit_string
 A normalized ASN.1 BIT STRING representation.
typedef QSC_EXPORT_API struct qsc_asn1_time_t qsc_asn1_time
 A normalized ASN.1 time representation.

Enumerations

enum  qsc_asn1_status_t {
  QSC_ASN1_STATUS_SUCCESS = 0 , QSC_ASN1_STATUS_FAILURE = -1 , QSC_ASN1_STATUS_INVALID_INPUT = -2 , QSC_ASN1_STATUS_INVALID_TAG = -3 ,
  QSC_ASN1_STATUS_INVALID_LENGTH = -4 , QSC_ASN1_STATUS_INVALID_ENCODING = -5 , QSC_ASN1_STATUS_BUFFER_TOO_SMALL = -6 , QSC_ASN1_STATUS_OUT_OF_RANGE = -7 ,
  QSC_ASN1_STATUS_NOT_FOUND = -8 , QSC_ASN1_STATUS_UNSUPPORTED = -9
}
 ASN.1 helper status codes. More...

Functions

QSC_EXPORT_API qsc_asn1_status qsc_asn1_der_decode_exact (const uint8_t *der, size_t derlen, qsc_encoding_ber_element **element)
 Decode a complete DER element and reject trailing octets.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_der_get_child_region (const uint8_t *der, size_t derlen, size_t index, const uint8_t **child, size_t *childlen)
 Returns the exact encoded DER slice of a child element within a parent element.
QSC_EXPORT_API bool qsc_asn1_oid_compare (const qsc_asn1_oid *a, const qsc_asn1_oid *b)
 Compares two decoded ASN.1 OBJECT IDENTIFIER values.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_require_sequence (const qsc_encoding_ber_element *element, size_t minchildren, size_t maxchildren)
 Validates that an element is a constructed ASN.1 SEQUENCE.
QSC_EXPORT_API const qsc_encoding_ber_elementqsc_asn1_get_child (const qsc_encoding_ber_element *element, size_t index)
 Retrieves a child element from a constructed ASN.1 element.
QSC_EXPORT_API bool qsc_asn1_is_boolean (const qsc_encoding_ber_element *element)
 Tests whether an ASN.1 element is a BOOLEAN.
QSC_EXPORT_API bool qsc_asn1_is_integer (const qsc_encoding_ber_element *element)
 Tests whether an ASN.1 element is an INTEGER.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_integer_u64 (const qsc_encoding_ber_element *element, uint64_t *value)
 Decodes an ASN.1 INTEGER into a 64-bit unsigned value.
QSC_EXPORT_API bool qsc_asn1_is_null (const qsc_encoding_ber_element *element)
 Tests whether an ASN.1 element is a NULL value.
QSC_EXPORT_API bool qsc_asn1_is_oid (const qsc_encoding_ber_element *element)
 Tests whether an ASN.1 element is an OBJECT IDENTIFIER.
QSC_EXPORT_API bool qsc_asn1_element_is_tag (const qsc_encoding_ber_element *element, uint8_t tagclass, bool constructed, uint32_t tagnumber)
 Tests whether an ASN.1 element matches an expected tag description.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_require_tag (const qsc_encoding_ber_element *element, uint8_t tagclass, bool constructed, uint32_t tagnumber)
 Validates that an ASN.1 element matches an expected tag description.
QSC_EXPORT_API size_t qsc_asn1_child_count (const qsc_encoding_ber_element *element)
 Gets the number of child elements in a constructed ASN.1 element.
QSC_EXPORT_API const qsc_encoding_ber_elementqsc_asn1_child_at (const qsc_encoding_ber_element *element, size_t index)
 Gets a child element by index.
QSC_EXPORT_API const qsc_encoding_ber_elementqsc_asn1_find_context_child (const qsc_encoding_ber_element *element, uint32_t tagnumber)
 Gets an optional context-specific child by tag number.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_get_explicit_child (const qsc_encoding_ber_element *element, const qsc_encoding_ber_element **child)
 Gets the sole child of an explicitly tagged context-specific element.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_boolean (const qsc_encoding_ber_element *element, bool *value)
 Decodes a BOOLEAN value.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_uint64 (const qsc_encoding_ber_element *element, uint64_t *value)
 Decodes a non-negative INTEGER into a 64-bit unsigned integer.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_octet_string (const qsc_encoding_ber_element *element, uint8_t *output, size_t otplen, size_t *outlen)
 Copies the contents of an OCTET STRING into a caller-provided buffer.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_bit_string (const qsc_encoding_ber_element *element, qsc_asn1_bit_string *value)
 Decodes a BIT STRING to a normalized descriptor.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_null (const qsc_encoding_ber_element *element)
 Validates that an ASN.1 NULL element is correctly encoded.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_oid (const qsc_encoding_ber_element *element, qsc_asn1_oid *oid)
 Decodes an OBJECT IDENTIFIER value.
QSC_EXPORT_API bool qsc_asn1_oid_are_equal (const qsc_asn1_oid *a, const qsc_asn1_oid *b)
 Compares two decoded OBJECT IDENTIFIER values for equality.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_oid_to_string (const qsc_asn1_oid *oid, char *output, size_t otplen)
 Converts a decoded OBJECT IDENTIFIER to dotted-decimal text.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_string (const qsc_encoding_ber_element *element, char *output, size_t otplen, size_t *outlen)
 Copies the contents of a supported ASN.1 string type into a character buffer.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_time (const qsc_encoding_ber_element *element, qsc_asn1_time *value)
 Decodes a UTCTime or GeneralizedTime value to a normalized structure.
QSC_EXPORT_API int32_t qsc_asn1_time_compare (const qsc_asn1_time *a, const qsc_asn1_time *b)
 Compares two normalized ASN.1 times.
QSC_EXPORT_API qsc_asn1_status qsc_asn1_der_size (const qsc_encoding_ber_element *element, size_t *size)
 Computes the encoded DER size of a decoded ASN.1 element.

Detailed Description

ASN.1 helper functions and data types built on the QSC BER and DER encoding layer.

This header provides a compact ASN.1 support layer intended for use by the X.509 certificate parser and validator. The implementation does not replace the generic BER and DER routines in encoding.h. Instead, it adds strict validation and typed decoding helpers for the ASN.1 forms that are required by X.509 and related public key structures.

The functions in this module operate on qsc_encoding_ber_element objects produced by qsc_encoding_der_decode_element() or qsc_encoding_ber_decode_element(). The primary design goal is to provide a small and explicit bridge between the generic tree representation and the strongly typed objects needed by certificate parsing code.

The module includes support for:

  • Tag and class validation.
  • Sequence, set, and context-specific element handling.
  • INTEGER, BOOLEAN, BIT STRING, OCTET STRING, NULL, and OBJECT IDENTIFIER decoding.
  • Printable string extraction for common distinguished name fields.
  • UTCTime and GeneralizedTime parsing to a normalized internal time structure.
  • Helper functions for DER size calculation and child traversal.

This layer is intentionally conservative. It is intended for DER-centric certificate parsing, and rejects malformed or ambiguous encodings where a strict X.509 implementation should fail.

Typedef Documentation

◆ qsc_asn1_oid

A decoded ASN.1 OBJECT IDENTIFIER.

The structure stores both the original DER value octets and the decoded arc sequence. The encoded form is useful for table lookups and direct comparison, while the arc array is useful for debugging and diagnostics.

Enumeration Type Documentation

◆ qsc_asn1_status_t

ASN.1 helper status codes.

Enumerator
QSC_ASN1_STATUS_SUCCESS 

Operation completed successfully.

QSC_ASN1_STATUS_FAILURE 

A generic parsing or validation error occurred.

QSC_ASN1_STATUS_INVALID_INPUT 

An input parameter was invalid.

QSC_ASN1_STATUS_INVALID_TAG 

The element tag class, form, or tag number was not as expected.

QSC_ASN1_STATUS_INVALID_LENGTH 

The element length was malformed or inconsistent.

QSC_ASN1_STATUS_INVALID_ENCODING 

The ASN.1 value encoding was malformed.

QSC_ASN1_STATUS_BUFFER_TOO_SMALL 

The caller-provided output buffer is too small.

QSC_ASN1_STATUS_OUT_OF_RANGE 

The value exceeded the supported numeric or structural range.

QSC_ASN1_STATUS_NOT_FOUND 

The requested child or optional element was not found.

QSC_ASN1_STATUS_UNSUPPORTED 

The encoding is recognized but not supported by this helper layer.

Function Documentation

◆ qsc_asn1_child_at()

QSC_EXPORT_API const qsc_encoding_ber_element * qsc_asn1_child_at ( const qsc_encoding_ber_element * element,
size_t index )

Gets a child element by index.

Parameters
element[const qsc_encoding_ber_element*] The parent constructed element.
index[size_t] The child index.
Returns
[const qsc_encoding_ber_element*] Returns a pointer to the requested child, or NULL on error.

◆ qsc_asn1_child_count()

QSC_EXPORT_API size_t qsc_asn1_child_count ( const qsc_encoding_ber_element * element)

Gets the number of child elements in a constructed ASN.1 element.

Parameters
element[const qsc_encoding_ber_element*] The constructed element.
Returns
[size_t] Returns the number of child elements, or 0 if the input is invalid.

◆ qsc_asn1_decode_bit_string()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_bit_string ( const qsc_encoding_ber_element * element,
qsc_asn1_bit_string * value )

Decodes a BIT STRING to a normalized descriptor.

Parameters
element[const qsc_encoding_ber_element*] The BIT STRING element.
value[qsc_asn1_bit_string*] Receives the normalized BIT STRING descriptor.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_decode_boolean()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_boolean ( const qsc_encoding_ber_element * element,
bool * value )

Decodes a BOOLEAN value.

Parameters
element[const qsc_encoding_ber_element*] The BOOLEAN element.
value[bool*] Receives the decoded boolean value.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_decode_integer_u64()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_integer_u64 ( const qsc_encoding_ber_element * element,
uint64_t * value )

Decodes an ASN.1 INTEGER into a 64-bit unsigned value.

This function is a compatibility wrapper around qsc_asn1_decode_uint64(). The INTEGER must be non-negative and must fit within a 64-bit unsigned integer.

Parameters
element[const qsc_encoding_ber_element*] Pointer to the INTEGER element.
value[uint64_t*] Receives the decoded integer value.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS if decoding succeeds.

◆ qsc_asn1_decode_null()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_null ( const qsc_encoding_ber_element * element)

Validates that an ASN.1 NULL element is correctly encoded.

Parameters
element[const qsc_encoding_ber_element*] The NULL element.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS if the NULL encoding is valid.

◆ qsc_asn1_decode_octet_string()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_octet_string ( const qsc_encoding_ber_element * element,
uint8_t * output,
size_t otplen,
size_t * outlen )

Copies the contents of an OCTET STRING into a caller-provided buffer.

Parameters
element[const qsc_encoding_ber_element*] The OCTET STRING element.
output[uint8_t*] The destination byte array.
otplen[size_t] The size of the destination byte array.
outlen[size_t*] Receives the number of bytes copied.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_decode_oid()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_oid ( const qsc_encoding_ber_element * element,
qsc_asn1_oid * oid )

Decodes an OBJECT IDENTIFIER value.

Parameters
element[const qsc_encoding_ber_element*] The OBJECT IDENTIFIER element.
oid[qsc_asn1_oid*] Receives the decoded object identifier.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_decode_string()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_string ( const qsc_encoding_ber_element * element,
char * output,
size_t otplen,
size_t * outlen )

Copies the contents of a supported ASN.1 string type into a character buffer.

This function supports the common string types used by X.509 distinguished names, including PrintableString, UTF8String, IA5String, T61String, VisibleString, BMPString, and UniversalString. For multi-byte encodings such as BMPString and UniversalString, this helper accepts only values in the 7-bit ASCII subset and rejects non-ASCII code points.

Parameters
element[const qsc_encoding_ber_element*] The ASN.1 string element.
output[char*] The destination character array.
otplen[size_t] The size of the destination character array.
outlen[size_t*] Receives the length of the copied string, excluding the terminator.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_decode_time()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_time ( const qsc_encoding_ber_element * element,
qsc_asn1_time * value )

Decodes a UTCTime or GeneralizedTime value to a normalized structure.

Parameters
element[const qsc_encoding_ber_element*] The ASN.1 time element.
value[qsc_asn1_time*] Receives the normalized time value.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_decode_uint64()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_decode_uint64 ( const qsc_encoding_ber_element * element,
uint64_t * value )

Decodes a non-negative INTEGER into a 64-bit unsigned integer.

Parameters
element[const qsc_encoding_ber_element*] The INTEGER element.
value[uint64_t*] Receives the decoded integer value.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_der_decode_exact()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_der_decode_exact ( const uint8_t * der,
size_t derlen,
qsc_encoding_ber_element ** element )

Decode a complete DER element and reject trailing octets.

This helper wraps qsc_encoding_der_decode_element() and requires the input buffer to contain exactly one complete DER element. Inputs with trailing bytes are rejected so callers can fail closed on ambiguous or concatenated encodings.

Parameters
der[const uint8_t*] Pointer to the DER input buffer.
derlen[size_t] Length of the DER input buffer in bytes.
element[qsc_encoding_ber_element**] Receives the decoded element tree on success.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_der_get_child_region()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_der_get_child_region ( const uint8_t * der,
size_t derlen,
size_t index,
const uint8_t ** child,
size_t * childlen )

Returns the exact encoded DER slice of a child element within a parent element.

The parent buffer must contain exactly one DER element. The function walks the encoded child sequence inside the parent content and returns the exact byte range for the requested child element. This is intended for preserving signed substructures such as TBSCertificate, CertificationRequestInfo, and TBSCertList without reconstructing them from normalized fields.

Parameters
der[const uint8_t*] Pointer to the complete parent DER element.
derlen[size_t] Length of the parent DER element in bytes.
index[size_t] Zero-based child index inside the parent content.
child[const uint8_t**] Receives a pointer to the exact child DER encoding.
childlen[size_t*] Receives the length of the child DER encoding in bytes.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_der_size()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_der_size ( const qsc_encoding_ber_element * element,
size_t * size )

Computes the encoded DER size of a decoded ASN.1 element.

This helper calculates the size of the element as it would appear in DER, including the tag, length field, and content octets. For decoded BER trees, this is useful when reconstructing exact spans of explicit wrappers or when checking structure sizes during certificate parsing.

Parameters
element[const qsc_encoding_ber_element*] The ASN.1 element.
length[size_t*] Receives the computed encoded length.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_element_is_tag()

QSC_EXPORT_API bool qsc_asn1_element_is_tag ( const qsc_encoding_ber_element * element,
uint8_t tagclass,
bool constructed,
uint32_t tagnumber )

Tests whether an ASN.1 element matches an expected tag description.

Parameters
element[const qsc_encoding_ber_element*] The element to test.
tagclass[uint8_t] The expected tag class.
constructed[bool] The expected constructed flag.
tagnumber[uint32_t] The expected tag number.
Returns
[bool] Returns true if the element matches the requested tag description.

◆ qsc_asn1_find_context_child()

QSC_EXPORT_API const qsc_encoding_ber_element * qsc_asn1_find_context_child ( const qsc_encoding_ber_element * element,
uint32_t tagnumber )

Gets an optional context-specific child by tag number.

Parameters
element[const qsc_encoding_ber_element*] The parent constructed element.
tagnumber[uint32_t] The requested context-specific tag number.
Returns
[const qsc_encoding_ber_element*] Returns a pointer to the requested child, or NULL if no matching child exists.

◆ qsc_asn1_get_child()

QSC_EXPORT_API const qsc_encoding_ber_element * qsc_asn1_get_child ( const qsc_encoding_ber_element * element,
size_t index )

Retrieves a child element from a constructed ASN.1 element.

This function returns the child element at the specified index. It is a compatibility alias for qsc_asn1_child_at().

Parameters
element[const qsc_encoding_ber_element*] Pointer to the parent element.
index[size_t] The zero-based child index.
Returns
[const qsc_encoding_ber_element*] Returns a pointer to the child element, or NULL if the index is invalid.

◆ qsc_asn1_get_explicit_child()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_get_explicit_child ( const qsc_encoding_ber_element * element,
const qsc_encoding_ber_element ** child )

Gets the sole child of an explicitly tagged context-specific element.

Parameters
element[const qsc_encoding_ber_element*] The context-specific wrapper element.
child[const qsc_encoding_ber_element**] Receives the wrapped child element.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_is_boolean()

QSC_EXPORT_API bool qsc_asn1_is_boolean ( const qsc_encoding_ber_element * element)

Tests whether an ASN.1 element is a BOOLEAN.

The function verifies that the supplied element has the universal BOOLEAN tag and is encoded as a primitive value.

Parameters
element[const qsc_encoding_ber_element*] Pointer to the ASN.1 element.
Returns
[bool] Returns true if the element is a BOOLEAN.

◆ qsc_asn1_is_integer()

QSC_EXPORT_API bool qsc_asn1_is_integer ( const qsc_encoding_ber_element * element)

Tests whether an ASN.1 element is an INTEGER.

The function verifies that the supplied element has the universal INTEGER tag and is encoded as a primitive value.

Parameters
element[const qsc_encoding_ber_element*] Pointer to the ASN.1 element.
Returns
[bool] Returns true if the element is an INTEGER.

◆ qsc_asn1_is_null()

QSC_EXPORT_API bool qsc_asn1_is_null ( const qsc_encoding_ber_element * element)

Tests whether an ASN.1 element is a NULL value.

The function verifies that the supplied element has the universal NULL tag and is encoded as a primitive value.

Parameters
element[const qsc_encoding_ber_element*] Pointer to the ASN.1 element.
Returns
[bool] Returns true if the element is a NULL.

◆ qsc_asn1_is_oid()

QSC_EXPORT_API bool qsc_asn1_is_oid ( const qsc_encoding_ber_element * element)

Tests whether an ASN.1 element is an OBJECT IDENTIFIER.

The function verifies that the supplied element has the universal OBJECT IDENTIFIER tag and is encoded as a primitive value.

Parameters
element[const qsc_encoding_ber_element*] Pointer to the ASN.1 element.
Returns
[bool] Returns true if the element is an OBJECT IDENTIFIER.

◆ qsc_asn1_oid_are_equal()

QSC_EXPORT_API bool qsc_asn1_oid_are_equal ( const qsc_asn1_oid * a,
const qsc_asn1_oid * b )

Compares two decoded OBJECT IDENTIFIER values for equality.

Parameters
a[const qsc_asn1_oid*] The first object identifier.
b[const qsc_asn1_oid*] The second object identifier.
Returns
[bool] Returns true if the object identifiers are equal.

◆ qsc_asn1_oid_compare()

QSC_EXPORT_API bool qsc_asn1_oid_compare ( const qsc_asn1_oid * a,
const qsc_asn1_oid * b )

Compares two decoded ASN.1 OBJECT IDENTIFIER values.

This function performs an exact comparison of two OID structures. It is a compatibility wrapper around qsc_asn1_oid_are_equal() used by the X.509 implementation.

Parameters
a[const qsc_asn1_oid*] Pointer to the first OID.
b[const qsc_asn1_oid*] Pointer to the second OID.
Returns
[bool] Returns true if both OIDs are identical.

◆ qsc_asn1_oid_to_string()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_oid_to_string ( const qsc_asn1_oid * oid,
char * output,
size_t otplen )

Converts a decoded OBJECT IDENTIFIER to dotted-decimal text.

Parameters
oid[const qsc_asn1_oid*] The decoded object identifier.
output[char*] The destination character array.
otplen[size_t] The size of the destination character array.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_require_sequence()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_require_sequence ( const qsc_encoding_ber_element * element,
size_t minchildren,
size_t maxchildren )

Validates that an element is a constructed ASN.1 SEQUENCE.

The function verifies that the supplied element has the universal SEQUENCE tag and that the number of child elements lies within the specified inclusive bounds.

This helper is used by the X.509 parser to validate DER structures before accessing their child elements.

Parameters
element[const qsc_encoding_ber_element*] Pointer to the ASN.1 element.
minchildren[size_t] Minimum allowed number of children.
maxchildren[size_t] Maximum allowed number of children.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS if validation succeeds.

◆ qsc_asn1_require_tag()

QSC_EXPORT_API qsc_asn1_status qsc_asn1_require_tag ( const qsc_encoding_ber_element * element,
uint8_t tagclass,
bool constructed,
uint32_t tagnumber )

Validates that an ASN.1 element matches an expected tag description.

Parameters
element[const qsc_encoding_ber_element*] The element to validate.
tagclass[uint8_t] The expected tag class.
constructed[bool] The expected constructed flag.
tagnumber[uint32_t] The expected tag number.
Returns
[qsc_asn1_status] Returns QSC_ASN1_STATUS_SUCCESS on success.

◆ qsc_asn1_time_compare()

QSC_EXPORT_API int32_t qsc_asn1_time_compare ( const qsc_asn1_time * a,
const qsc_asn1_time * b )

Compares two normalized ASN.1 times.

Parameters
a[const qsc_asn1_time*] The first time value.
b[const qsc_asn1_time*] The second time value.
Returns
[int32_t] Returns -1 if a is earlier than b, 0 if equal, and 1 if later.