wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
pem.h File Reference

RFC 7468 2-3: textual (PEM) encoding of DER structures. More...

Go to the source code of this file.

Functions

int wired_pem_next (wired_span text, usz *at, wired_span *label, wired_obuf *der)
 Decode the next PEM block of text at or after *at.

Detailed Description

RFC 7468 2-3: textual (PEM) encoding of DER structures.

A PEM text is a sequence of "-----BEGIN <label>-----" / "-----END <label>-----" blocks whose body is base64 (RFC 4648 4) of the DER bytes; anything outside the markers (comment lines, openssl x509 -text dumps) is ignored. The one entry point walks the text block by block so a fullchain file decodes with repeated calls.

Function Documentation

◆ wired_pem_next()

int wired_pem_next ( wired_span text,
usz * at,
wired_span * label,
wired_obuf * der )

Decode the next PEM block of text at or after *at.

Scans forward from *at for a "-----BEGIN <label>-----" line, base64-decodes the body up to the matching "-----END " line into der (appending at der->len, RFC 4648 4: =/== padding honored, CR/LF skipped), and advances *at past the END line so the following call returns the next block. label receives a view of the bytes between "BEGIN " and the closing dashes (e.g. "CERTIFICATE"), borrowed from text.

der is a caller-owned output buffer (see obuf_of): the caller retains ownership and der->p must have room for the decoded bytes, this call only appends and advances der->len, it never allocates or frees.

Parameters
textthe whole PEM text (borrowed; must outlive label)
atscan cursor into text; advanced past the decoded block
labelreceives the block's label as a view into text
derreceives the decoded DER bytes; the callee advances der->len
Returns
1 when a block was decoded, 0 when no BEGIN marker remains or the block is broken (invalid base64, missing END line, or der overflow).