code wiki / (root) / nx_pem.nx

nx_pem.nx

buildroot/runtime/nx_pem.nx

6559 B190 linesdepth 2pulls 3 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

pem.nx -- RFC 7468 PEM (Privacy-Enhanced Mail) container parser. PEM is the ASCII-armor wrapper around binary DER content in X.509 certs, PKCS#8 private keys, SSH keys, cryptographic signatures. Format: -----BEGIN <LABEL>----- <base64-encoded DER, line-wrapped at 64 chars> -----END <LABEL>----- Common labels: CERTIFICATE (X.509 public cert) PRIVATE KEY (PKCS#8 envelope, algorithm in ASN.1 inside) PUBLIC KEY (SubjectPublicKeyInfo DER) RSA PRIVATE KEY (PKCS#1; legacy, still used) ENCRYPTED PRIVATE KEY (PKCS#8 with PBKDF2) API: pem_decode(buf, len, out_der, out_cap) -> (label_off, label_len, der_len) Returns DER bytes written to out_der, or negative on error. Caller supplies out_der sized >= 3/4 of base64 input. Invariants: PEM1 Finds the FIRST BEGIN/END block in the input; callers needing multiple blocks (cert chains) iterate by advancing past the previous END line. PEM2 Label must match between BEGIN and END (RFC 7468 ยง3); mismatch returns a negative error. PEM3 Whitespace inside the base64 body (newlines, spaces) is tolerated and stripped before base64_decode. Other non-alphabet bytes return an error. PEM4 Output buffer bounds-checked; overrun returns negative.

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_base64.nx nx_pem.nx nx_acme_dns01_issue.nx

imports: nx_syscalls.nxnx_base64.nx

imported by: nx_acme_dns01_issue.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap pem_decode sys_mmap ↻ pem_locate pem_find_dashes pem_match_lit b64_decode b64_grab b64_dec_char

structs

80struct PemResult

consts

44const PEM_ERR_NO_BEGIN: i64 = -1
45const PEM_ERR_NO_END: i64 = -2
46const PEM_ERR_LABEL_MISMATCH: i64 = -3
47const PEM_ERR_OVERFLOW: i64 = -4
48const PEM_ERR_BAD_BODY: i64 = -5

functions

52func pem_find_dashes(buf: *u8, len: i64, pos: i64) -> i64
called by 1: pem_locate
70func pem_match_lit(buf: *u8, off: i64, lit: *u8) -> i64
called by 1: pem_locate
89func pem_locate(buf: *u8, len: i64, out: *PemResult) -> i64
136func pem_decode(buf: *u8, len: i64,
177func main() -> i64