Skip to content

EDecoderStatus

Jay edited this page Oct 3, 2026 · 2 revisions

EDecoderStatus

#include <certpp/asn1/decoder.hpp> --- certpp::asn1

Represents the status of the ASN.1 decoder.

Enumerators

Enumerator Value Meaning
EDEC_OK 0
EDEC_NEED_MORE
EDEC_BAD_ARGS
EDEC_INDEFINITE
EDEC_RESERVED
EDEC_TOO_BIG
EDEC_PROHIBITED

Example

Drives a reader over bytes that arrive a chunk at a time. The point of the enum is the one distinction a bool cannot carry: EDEC_NEED_MORE means append more input and ask again, and every other non-OK status means this input will never parse however much is appended.

// given: IStreamPtr source, CBuffer& sofar, size_t& filled
CTag tag;
SReadOnlyByteSpan content;
size_t bytesRead = 0;

while (true) {
    const EDecoderStatus status = CDecoder::tryReadEncodedValue(
        SReadOnlyByteSpan(sofar.toPtr(), filled), EAENC_DER, tag, content, bytesRead);

    if (status == EDEC_OK) {
        return true;        // content and bytesRead are now meaningful
    }

    if (status != EDEC_NEED_MORE) {
        return false;       // malformed, prohibited under DER, or past a decoder limit
    }

    // Incomplete, not wrong. How much more is not knowable in general -- the length octets
    // may themselves be the truncated part -- so read what the source has and retry.
    if (filled >= sofar.size() && !sofar.resize(sofar.size() * 2 + 64)) {
        return false;
    }

    const size_t got = source->read(SByteSpan(sofar.toPtr() + filled, sofar.size() - filled));
    if (got == 0) {
        return false;       // the source ended mid-value: truncated for good
    }

    filled += got;
}

Reference generated from certpp/asn1/decoder.hpp at commit 0834b29 (v1.0.1). The header is authoritative --- if this page disagrees with it, the header is right and this page needs regenerating.

Clone this wiki locally