openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
tlv.h
1/* Minimal strict BER/DER-TLV reader for Aliro APDU payloads. */
2#pragma once
3
4#include <stddef.h>
5#include <stdint.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
16 uint32_t tag;
17 const uint8_t *value;
18 size_t length;
19 size_t encoded_length;
20};
21
22enum woz_aliro_tlv_result {
23 WOZ_ALIRO_TLV_OK = 0,
24 WOZ_ALIRO_TLV_END = 1,
25 WOZ_ALIRO_TLV_INVALID = -1,
26};
27
28/* Parse one TLV at *offset and advance the offset past it. Indefinite and
29 * non-minimal DER lengths are rejected. */
30int woz_aliro_tlv_next(const uint8_t *data, size_t data_length, size_t *offset,
31 struct woz_aliro_tlv *out);
32
33/* Return the encoded size of a definite-length TLV, or zero when the tag or
34 * length cannot be represented by this codec. Tags are supplied in their
35 * normal big-endian encoded form (for example 0x7f66). */
36size_t woz_aliro_tlv_encoded_size(uint32_t tag, size_t value_length);
37
38/* Append one definite-length TLV at *offset. */
39int woz_aliro_tlv_write(uint8_t *data, size_t data_capacity, size_t *offset, uint32_t tag,
40 const uint8_t *value, size_t value_length);
41
42#ifdef __cplusplus
43}
44#endif
Parsed TLV (Tag-Length-Value): tag (uint32), value (pointer to payload bytes), length (payload size),...
Definition tlv.h:15