pem.nx
buildroot/runtime/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 · 0 importers
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
structs
| 74 | struct PemResult { |
consts
| 38 | const PEM_ERR_NO_BEGIN: i64 = -1 |
| 39 | const PEM_ERR_NO_END: i64 = -2 |
| 40 | const PEM_ERR_LABEL_MISMATCH: i64 = -3 |
| 41 | const PEM_ERR_OVERFLOW: i64 = -4 |
| 42 | const PEM_ERR_BAD_BODY: i64 = -5 |
functions
| 46 | func pem_find_dashes(buf: *u8, len: i64, pos: i64) -> i64 {
called by 1: pem_locate |
| 64 | func pem_match_lit(buf: *u8, off: i64, lit: *u8) -> i64 {
called by 1: pem_locate |
| 83 | func pem_locate(buf: *u8, len: i64, out: *PemResult) -> i64 { |
| 130 | func pem_decode(buf: *u8, len: i64, |
| 171 | func main() -> i64 {
calls 1: pem_decode |