base64.nx
buildroot/runtime/base64.nx
about
base64.nx -- RFC 4648 base64 encoder + decoder.
Used for:
- PEM decoding of X.509 certs (thin ASCII wrapper around DER)
- TLS 1.3 pre-shared key encoding
- HTTP Basic auth, OAuth tokens, JWT
- Web content (data: URIs, JSON-embedded bytes)
Standard alphabet (RFC 4648 §4):
0-25 : A-Z
26-51 : a-z
52-61 : 0-9
62 : +
63 : /
pad : =
URL-safe alphabet variant (§5) swaps +/ for -_; provided as
b64url_encode / b64url_decode.
Invariants:
B1 Input/output lengths are predictable:
encode(n bytes) -> 4 * ceil(n / 3) chars
decode(n chars) -> 3 * (n / 4) - padding bytes
B2 Decoder rejects invalid input (non-alphabet chars) by
returning a negative length. No silent skip.
B3 Decoder is tolerant of missing padding (RFC 4648 §3.2
permits this as "unpadded" variant).
B4 Encoder is deterministic; same input -> same output. No
trailing whitespace, no line breaks inserted. Callers
that want MIME-style 76-char wrap do it outside.
dependencies 1 imports · 9 importers
imports: syscalls.nx
imported by: basic_auth.nxcsrf_token.nxjwt.nxnx_cenc.nxnx_cenc_gate.nxoauth2_pkce.nxpem.nxsigned_cookie.nxwebsocket_handshake.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 34 | const B64_PAD: i64 = 0x3D // '=' |
functions
| 37 | func b64_enc_char(n: i64) -> i64 {
called by 1: b64_encode |
| 47 | func b64url_enc_char(n: i64) -> i64 { |
| 58 | func b64_dec_char(c: i64) -> i64 {
called by 1: b64_grab |
| 71 | func b64_encode(in_bytes: *u8, n: i64, out: *u8) -> i64 {
called by 7: mainbasic_auth_encodecsrf_b64url_encodejwt_b64url_encodepkce_challengesc_sign_bytes+1 calls 1: b64_enc_char |
| 108 | func b64_grab(in_chars: *u8, n: i64, pos: *i64) -> i64 { |
| 125 | func b64_decode(in_chars: *u8, n: i64, out: *u8) -> i64 {
called by 6: mainbasic_auth_decodecsrf_b64url_decodejwt_b64url_decodecenc_b64url_decodepem_decode calls 1: b64_grab |
| 154 | func main() -> i64 { |