tlv.c
Overview
@file tlv.c BER-TLV parser and encoder for Aliro protocol: parse TLVs with definite length and advance offset, compute encoded sizes, and write new TLVs.
depends on tlv.h
API
Fint woz_aliro_tlv_next(const uint8_t *data, size_t data_length, size_t *offset, struct woz_aliro_tlv *out)
Parse one TLV at *offset and advance the offset past it. Indefinite and non-minimal DER lengths are rejected.
Fstatic size_t tag_size(uint32_t tag)
Compute the BER-TLV tag byte count for a given tag value: 1 byte for 0x00–0xff, 2 for 0x0100–0xffff, 3 for 0x010000–0xffffff, or 0 if tag is unsupported.
woz_aliro_tlv_encoded_size, woz_aliro_tlv_writeFstatic size_t length_size(size_t length)
Compute the BER-TLV length field byte count for a given value length: 1 byte for 0x00–0x7f, 2 for 0x80–0xff, 3 for 0x0100–0xffff, or 0 if length is unsupported.
woz_aliro_tlv_encoded_sizeFsize_t woz_aliro_tlv_encoded_size(uint32_t tag, size_t value_length)
Return the encoded size of a definite-length TLV, or zero when the tag or length cannot be represented by this codec. Tags are supplied in their normal big-endian encoded form (for example 0x7f66).
woz_aliro_tlv_write · calls length_size, tag_sizeFint woz_aliro_tlv_write(uint8_t *data, size_t data_capacity, size_t *offset, uint32_t tag, const uint8_t *value, size_t value_length)
Append one definite-length TLV at *offset.
tag_size, woz_aliro_tlv_encoded_size