nx_hex_codec.nx
buildroot/runtime/nx_hex_codec.nx
about
hex.nx -- lowercase hex encoder + decoder.
Complement to base64.nx for the common "print bytes as text"
use cases where readability matters more than density:
- SHA-256 / SHA-3 digest display
- Git-style object IDs
- TLS handshake transcripts for debugging
- URL query parameters carrying short binary values
Deterministic output (lowercase always). Decoder tolerates
both upper and lower case. No "0x" prefix, no whitespace.
Invariants:
H1 Encoder output is exactly 2*n chars for n input bytes.
H2 Decoder requires even-length input; rejects odd-length
with a negative return.
H3 Decoder rejects any non-hex char (not [0-9A-Fa-f]) with a
negative return -- no silent skip.
H4 Round-trip is exact: decode(encode(x)) == x for any byte
sequence.
dependencies 1 imports · 5 importers
imports: nx_syscalls.nx
imported by: nx_digest_auth.nxnx_etag.nxnx_f6_gate.nxnx_md5_kat.nxnx_uuid_v1.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 30 | const HEX_ERR_ODD_LENGTH: i64 = -1 |
| 31 | const HEX_ERR_INVALID_CHAR: i64 = -2 |
functions
| 35 | func hex_encode(in_bytes: *u8, n: i64, out: *u8) -> i64 |
| 53 | func hex_nibble(c: i64) -> i64 called by 1: hex_decode |
| 62 | func hex_decode(in_chars: *u8, n: i64, out: *u8) -> i64 |
| 80 | func main() -> i64 |