Skip to content
Start free evaluation

pdcomm_secs_decode

Function

Decodes exactly one SECS-II item from encoded bytes.

PdcommStatus pdcomm_secs_decode(const uint8_t *data, size_t length, const PdcommSecsLimits *options, PdcommSecsItem **out, size_t *error_offset)

Declared in: #include <pdcomm.h>

The input is validated against options before any tree allocation and then copied, so the new item does not reference data. Item headers may use more length bytes than necessary; pdcomm_secs_encode() always writes minimal headers.

Parameters

NameDescription
dataEncoded item. May be NULL only when length is 0, which reports #PDCOMM_TRUNCATED.
lengthNumber of bytes at data. Every byte must belong to the single item.
optionsLimits to enforce; struct_size must be at least sizeof(PdcommSecsLimits).
outReceives the new item. Set to NULL first, so it is NULL after every failure.
error_offsetOptional. Set to 0 at the start; on a decode error it receives the byte offset of the start of the field that failed, not of the first missing byte. May be NULL.

Returns

#PDCOMM_OK on success; #PDCOMM_INVALID_ARGUMENT when out or options is NULL, options->struct_size is too small, or data is NULL with a nonzero length; #PDCOMM_TRUNCATED when the input ends inside the item; #PDCOMM_INVALID_DATA when the encoding is malformed or bytes follow the item; #PDCOMM_LIMIT_EXCEEDED when a limit in options is exceeded; #PDCOMM_ALLOCATION_FAILED or #PDCOMM_INTERNAL_ERROR.

Notes

  • Ownership: release the item with pdcomm_secs_destroy().
  • out and error_offset must not overlap each other, data, or options.