code wiki / (root) / pem.nx

pem.nx

buildroot/runtime/pem.nx

6486 B184 linesdepth 4pulls 4 transitivereach 0 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 · 0 importers

syscalls.nx base64.nx pem.nx

imports: syscalls.nxbase64.nx

imported by: nobody (leaf or entry point)

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

main pem_decode pem_locate pem_find_dashes pem_match_lit b64_decode b64_grab b64_dec_char

structs

74struct PemResult {

consts

38const PEM_ERR_NO_BEGIN: i64 = -1
39const PEM_ERR_NO_END: i64 = -2
40const PEM_ERR_LABEL_MISMATCH: i64 = -3
41const PEM_ERR_OVERFLOW: i64 = -4
42const PEM_ERR_BAD_BODY: i64 = -5

functions

46func pem_find_dashes(buf: *u8, len: i64, pos: i64) -> i64 {
called by 1: pem_locate
64func pem_match_lit(buf: *u8, off: i64, lit: *u8) -> i64 {
called by 1: pem_locate
83func pem_locate(buf: *u8, len: i64, out: *PemResult) -> i64 {
130func pem_decode(buf: *u8, len: i64,
called by 1: main calls 2: pem_locateb64_decode
171func main() -> i64 {
calls 1: pem_decode