Skip to content

Encoding

Source: std/encoding.mw.

Hex, Base64 (standard and URL-safe) and UTF-8 validation and conversion.

Hex, Base64 (RFC 4648, standard and URL-safe) and UTF-8 helpers. Encoders write into a caller buffer and return the length; decoders return the decoded length or -1 on malformed input. *_len helpers give the worst-case output size.

fn hex_encode_len(n: i64) -> i64
fn hex_decode_len(n: i64) -> i64
fn hex_encode(src: *u8, n: i64, out: *u8) -> i64
fn hex_decode(src: *u8, n: i64, out: *u8) -> i64
fn base64_encode_len(n: i64) -> i64
fn base64_decode_len(n: i64) -> i64
fn base64_encode(src: *u8, n: i64, out: *u8) -> i64
fn base64url_encode(src: *u8, n: i64, out: *u8) -> i64

URL-safe alphabet, no padding (as used by JWT).

fn base64_decode(src: *u8, n: i64, out: *u8) -> i64

Accepts both alphabets, optional padding, and skips ASCII whitespace (so PEM bodies can be decoded directly).

fn utf8_valid(s: *u8, n: i64) -> bool
fn utf8_count(s: *u8, n: i64) -> i64
fn utf8_decode(s: *u8, n: i64, len: *i64) -> i64

Decodes one code point; stores its byte length in *len. Returns -1 if malformed.

fn utf8_encode(cp: i64, out: *u8) -> i64

Encodes a code point into out (up to 4 bytes); returns the length, 0 if invalid.