Skip to content

File syn_asn1.c

FileList > crypto > syn_asn1.c

Go to the source code of this file

Zero-Heap ASN.1 DER (Distinguished Encoding Rules) TLV Parser implementation.

  • #include "syntropic/crypto/syn_asn1.h"
  • #include <string.h>

Public Functions

Type Name
bool syn_asn1_enter_container (const SYN_ASN1_Element * container, const uint8_t ** child_buf, size_t * child_len)
Unwraps a constructed container (SEQUENCE, SET, or context-specific tag) for child iteration.
bool syn_asn1_get_bit_string (const SYN_ASN1_Element * elem, const uint8_t ** bits_out, size_t * bit_len_out)
Extract Bit String payload (stripping unused bits count prefix byte).
bool syn_asn1_get_integer (const SYN_ASN1_Element * elem, const uint8_t ** int_out, size_t * int_len_out)
Extract raw integer bytes (stripping leading sign zero padding if present).
bool syn_asn1_match_oid (const SYN_ASN1_Element * elem, const uint8_t * expected_oid, size_t oid_len)
Compare ASN.1 Object Identifier (OID) against expected byte array.
bool syn_asn1_parse_element (const uint8_t * buf, size_t len, SYN_ASN1_Element * elem_out)
Parse a single ASN.1 DER TLV element from buffer.
bool syn_asn1_step (const uint8_t ** buf, size_t * len, SYN_ASN1_Element * elem_out)
Skip/advance past current TLV element in a DER buffer.

Public Functions Documentation

function syn_asn1_enter_container

Unwraps a constructed container (SEQUENCE, SET, or context-specific tag) for child iteration.

bool syn_asn1_enter_container (
    const SYN_ASN1_Element * container,
    const uint8_t ** child_buf,
    size_t * child_len
) 

Parameters:

  • container Pointer to container TLV element header.
  • child_buf [out] Sub-slice buffer pointer to container payload.
  • child_len [out] Length of container payload.

Returns:

true if element is constructed and valid payload extracted.


function syn_asn1_get_bit_string

Extract Bit String payload (stripping unused bits count prefix byte).

bool syn_asn1_get_bit_string (
    const SYN_ASN1_Element * elem,
    const uint8_t ** bits_out,
    size_t * bit_len_out
) 

Parameters:

  • elem Parsed ASN.1 BIT STRING element.
  • bits_out [out] Pointer to raw bit string bytes.
  • bit_len_out [out] Number of valid bits in payload.

Returns:

true on success.


function syn_asn1_get_integer

Extract raw integer bytes (stripping leading sign zero padding if present).

bool syn_asn1_get_integer (
    const SYN_ASN1_Element * elem,
    const uint8_t ** int_out,
    size_t * int_len_out
) 

Parameters:

  • elem Parsed ASN.1 INTEGER element.
  • int_out [out] Pointer to integer payload bytes.
  • int_len_out [out] Length of integer payload bytes.

Returns:

true on success.


function syn_asn1_match_oid

Compare ASN.1 Object Identifier (OID) against expected byte array.

bool syn_asn1_match_oid (
    const SYN_ASN1_Element * elem,
    const uint8_t * expected_oid,
    size_t oid_len
) 

Parameters:

  • elem Parsed ASN.1 OID element.
  • expected_oid Expected encoded OID payload bytes.
  • oid_len Length of expected OID payload bytes.

Returns:

true if OIDs match.


function syn_asn1_parse_element

Parse a single ASN.1 DER TLV element from buffer.

bool syn_asn1_parse_element (
    const uint8_t * buf,
    size_t len,
    SYN_ASN1_Element * elem_out
) 

Parameters:

  • buf Data buffer.
  • len Length of available bytes in buffer.
  • elem_out [out] Output parsed element.

Returns:

true if valid TLV element parsed, false on truncation or encoding error.


function syn_asn1_step

Skip/advance past current TLV element in a DER buffer.

bool syn_asn1_step (
    const uint8_t ** buf,
    size_t * len,
    SYN_ASN1_Element * elem_out
) 

Parameters:

  • buf Pointer to buffer pointer (updated on success).
  • len Pointer to available length (updated on success).
  • elem_out [out] Optional parsed element header.

Returns:

true on success.



The documentation for this class was generated from the following file src/syntropic/crypto/syn_asn1.c