nx_pem.nx
buildroot/runtime/nx_pem.nx
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
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
structs
| 80 | struct PemResult |
consts
| 44 | const PEM_ERR_NO_BEGIN: i64 = -1 |
| 45 | const PEM_ERR_NO_END: i64 = -2 |
| 46 | const PEM_ERR_LABEL_MISMATCH: i64 = -3 |
| 47 | const PEM_ERR_OVERFLOW: i64 = -4 |
| 48 | const PEM_ERR_BAD_BODY: i64 = -5 |
functions
| 52 | func pem_find_dashes(buf: *u8, len: i64, pos: i64) -> i64 called by 1: pem_locate |
| 70 | func pem_match_lit(buf: *u8, off: i64, lit: *u8) -> i64 called by 1: pem_locate |
| 89 | func pem_locate(buf: *u8, len: i64, out: *PemResult) -> i64 |
| 136 | func pem_decode(buf: *u8, len: i64, |
| 177 | func main() -> i64 |