code wiki / (root) / base64.nx

base64.nx

buildroot/runtime/base64.nx

5967 B163 linesdepth 3pulls 3 transitivereach 9 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

syscalls.nx base64.nx basic_auth.nx csrf_token.nx jwt.nx nx_cenc.nx nx_cenc_gate.nx oauth2_pkce.nx pem.nx signed_cookie.nx websocket_handshake.nx

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

main b64_encode b64_enc_char b64_decode b64_grab b64_dec_char

structs

none

consts

34const B64_PAD: i64 = 0x3D // '='

functions

37func b64_enc_char(n: i64) -> i64 {
called by 1: b64_encode
47func b64url_enc_char(n: i64) -> i64 {
58func b64_dec_char(c: i64) -> i64 {
called by 1: b64_grab
71func b64_encode(in_bytes: *u8, n: i64, out: *u8) -> i64 {
108func b64_grab(in_chars: *u8, n: i64, pos: *i64) -> i64 {
called by 1: b64_decode calls 1: b64_dec_char
125func b64_decode(in_chars: *u8, n: i64, out: *u8) -> i64 {
154func main() -> i64 {