facil.io

#./fio-stl/155 der.h

18 public symbols.

#Types

#fio_der_tag_e

c
typedef enum {
FIO_DER_EOC = 0x00, /**< End-of-contents */
FIO_DER_BOOLEAN = 0x01, /**< Boolean */
FIO_DER_INTEGER = 0x02, /**< Integer */
FIO_DER_BIT_STRING = 0x03, /**< Bit String */
FIO_DER_OCTET_STRING = 0x04, /**< Octet String */
FIO_DER_NULL = 0x05, /**< Null */
FIO_DER_OID = 0x06, /**< Object Identifier */
FIO_DER_OBJECT_DESCRIPTOR = 0x07, /**< Object Descriptor */
FIO_DER_EXTERNAL = 0x08, /**< External */
FIO_DER_REAL = 0x09, /**< Real (float) */
FIO_DER_ENUMERATED = 0x0A, /**< Enumerated */
FIO_DER_EMBEDDED_PDV = 0x0B, /**< Embedded PDV */
FIO_DER_UTF8_STRING = 0x0C, /**< UTF-8 String */
FIO_DER_RELATIVE_OID = 0x0D, /**< Relative OID */
FIO_DER_SEQUENCE = 0x10, /**< Sequence (0x30 with constructed bit) */
FIO_DER_SET = 0x11, /**< Set (0x31 with constructed bit) */
FIO_DER_NUMERIC_STRING = 0x12, /**< Numeric String */
FIO_DER_PRINTABLE_STRING = 0x13, /**< Printable String */
FIO_DER_T61_STRING = 0x14, /**< T61 String (Teletex) */
FIO_DER_VIDEOTEX_STRING = 0x15, /**< Videotex String */
FIO_DER_IA5_STRING = 0x16, /**< IA5 String (ASCII) */
FIO_DER_UTC_TIME = 0x17, /**< UTC Time */
FIO_DER_GENERALIZED_TIME = 0x18, /**< Generalized Time */
FIO_DER_GRAPHIC_STRING = 0x19, /**< Graphic String */
FIO_DER_VISIBLE_STRING = 0x1A, /**< Visible String */
FIO_DER_GENERAL_STRING = 0x1B, /**< General String */
FIO_DER_UNIVERSAL_STRING = 0x1C, /**< Universal String */
FIO_DER_BMP_STRING = 0x1E, /**< BMP String (UCS-2) */
/* Context-specific tags (0x80 | tag_number) with constructed bit (0x20) */
FIO_DER_CONTEXT_0 = 0xA0, /**< [0] EXPLICIT/IMPLICIT */
FIO_DER_CONTEXT_1 = 0xA1, /**< [1] EXPLICIT/IMPLICIT */
FIO_DER_CONTEXT_2 = 0xA2, /**< [2] EXPLICIT/IMPLICIT */
FIO_DER_CONTEXT_3 = 0xA3, /**< [3] EXPLICIT/IMPLICIT */
} fio_der_tag_e

ASN.1 Universal Tag Types

Symbol type: type

#fio_der_class_e

c
typedef enum {
FIO_DER_CLASS_UNIVERSAL = 0, /**< Universal (built-in types) */
FIO_DER_CLASS_APPLICATION = 1, /**< Application-specific */
FIO_DER_CLASS_CONTEXT = 2, /**< Context-specific */
FIO_DER_CLASS_PRIVATE = 3, /**< Private */
} fio_der_class_e

ASN.1 Tag Class (bits 7-6 of tag byte)

Symbol type: type

#fio_der_element_s

c
typedef struct {
const uint8_t *data; /**< Pointer to element content (after tag+length) */
size_t len; /**< Length of content */
uint8_t tag; /**< Raw tag byte */
uint8_t is_constructed; /**< 1 if constructed (contains other elements) */
uint8_t tag_class; /**< 0=Universal, 1=Application, 2=Context, 3=Private */
uint8_t tag_number; /**< Tag number (bits 4-0, or extended) */
} fio_der_element_s

Parsed ASN.1 DER element

Symbol type: type

#fio_der_iterator_s

c
typedef struct {
const uint8_t *pos; /**< Current position */
const uint8_t *end; /**< End of sequence */
} fio_der_iterator_s

Iterator for SEQUENCE or SET contents

Symbol type: type

#Functions

#fio_der_parse

c
const uint8_t *fio_der_parse(fio_der_element_s *elem, const uint8_t *data, size_t data_len)

Parse one ASN.1 element from DER-encoded data.

Parameters:

  • elem - Output structure to fill with parsed element info
  • data - Pointer to DER-encoded data
  • data_len - Length of data buffer

Returns:

  • Pointer to next element (after this one), or NULL on error

Symbol type: function

#fio_der_element_total_len

c
inline size_t fio_der_element_total_len(const fio_der_element_s *elem, const uint8_t *data)

Get the total encoded length of an ASN.1 element (tag + length + content).

Parameters:

  • elem - Parsed element
  • data - Original data pointer where element was parsed from

Returns:

  • Total bytes used by the element encoding

Symbol type: function

#fio_der_parse_integer

c
int fio_der_parse_integer(const fio_der_element_s *elem, uint64_t *value)

Parse an ASN.1 INTEGER element.

For small integers (<= 64-bit), sets *value. For large integers (RSA modulus), use elem->data/len directly. Leading zero bytes for positive numbers are handled correctly.

Parameters:

  • elem - Parsed element (must be INTEGER type)
  • value - Output for integer value (can be NULL for large integers)

Returns:

  • 0 on success, -1 on error

Symbol type: function

#fio_der_parse_bit_string

c
int fio_der_parse_bit_string(const fio_der_element_s *elem, const uint8_t **bits, size_t *bit_len, uint8_t *unused_bits)

Parse an ASN.1 BIT STRING element.

Parameters:

  • elem - Parsed element (must be BIT STRING type)
  • bits - Output pointer to bit data (first byte is unused bits count)
  • bit_len - Output length of bit data in bytes
  • unused_bits - Output number of unused bits in last byte (0-7)

Returns:

  • 0 on success, -1 on error

Symbol type: function

#fio_der_parse_oid

c
int fio_der_parse_oid(const fio_der_element_s *elem, char *buf, size_t buf_len)

Parse an ASN.1 OID into a dot-separated string.

Example output: "1.2.840.113549.1.1.11"

Parameters:

  • elem - Parsed element (must be OID type)
  • buf - Output buffer for string
  • buf_len - Buffer size

Returns:

  • Number of chars written (excluding NUL), or -1 on error

Symbol type: function

#fio_der_parse_time

c
int fio_der_parse_time(const fio_der_element_s *elem, int64_t *unix_time)

Parse an ASN.1 time (UTC Time or Generalized Time) to Unix timestamp.

Parameters:

  • elem - Parsed element (must be UTC_TIME or GENERALIZED_TIME type)
  • unix_time - Output Unix timestamp (seconds since 1970-01-01 00:00:00

UTC) Returns:

  • 0 on success, -1 on error

Symbol type: function

#fio_der_parse_string

c
inline const char *fio_der_parse_string(const fio_der_element_s *elem, size_t *len)

Parse an ASN.1 string element.

Supports UTF8String, PrintableString, IA5String, etc. Returns pointer directly into the element data (no copy).

Parameters:

  • elem - Parsed element (must be a string type)
  • len - Output length of string

Returns:

  • Pointer to string data, or NULL on error

Symbol type: function

#fio_der_parse_boolean

c
inline int fio_der_parse_boolean(const fio_der_element_s *elem, int *value)

Parse an ASN.1 BOOLEAN element.

Parameters:

  • elem - Parsed element (must be BOOLEAN type)
  • value - Output boolean value (0 = false, non-zero = true)

Returns:

  • 0 on success, -1 on error

Symbol type: function

#fio_der_iterator_init

c
inline void fio_der_iterator_init(fio_der_iterator_s *it, const fio_der_element_s *sequence)

Initialize an iterator for a SEQUENCE or SET element.

Parameters:

  • it - Iterator to initialize
  • sequence - Parsed element (must be SEQUENCE or SET)

Symbol type: function

#fio_der_iterator_next

c
int fio_der_iterator_next(fio_der_iterator_s *it, fio_der_element_s *elem)

Get the next element from an iterator.

Parameters:

  • it - Iterator (updated to point to next element)
  • elem - Output for parsed element

Returns:

  • 0 if element available, -1 if end or error

Symbol type: function

#fio_der_iterator_has_next

c
inline int fio_der_iterator_has_next(const fio_der_iterator_s *it)

Check if iterator has more elements.

Parameters:

  • it - Iterator

Returns:

  • 1 if more elements available, 0 otherwise

Symbol type: function

#fio_der_is_tag

c
inline int fio_der_is_tag(const fio_der_element_s *elem, uint8_t tag)

Check if an element is a specific tag type.

Parameters:

  • elem - Parsed element
  • tag - Expected tag (e.g., FIO_DER_INTEGER)

Returns:

  • 1 if match, 0 otherwise

Symbol type: function

#fio_der_is_context_tag

c
inline int fio_der_is_context_tag(const fio_der_element_s *elem, uint8_t tag_num)

Check if an element is a context-specific tag.

Parameters:

  • elem - Parsed element
  • tag_num - Context tag number (0-31)

Returns:

  • 1 if match, 0 otherwise

Symbol type: function

#fio_der_tag_number

c
inline uint8_t fio_der_tag_number(const fio_der_element_s *elem)

Get the tag number from an element.

For universal tags, returns the tag value (0-30). For context-specific tags, returns the context number.

Parameters:

  • elem - Parsed element

Returns:

  • Tag number

Symbol type: function