code wiki / (root) / nx_etag.nx

nx_etag.nx

buildroot/runtime/nx_etag.nx

5777 B161 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

etag.nx -- generate + compare HTTP ETag headers (RFC 7232). The ETag header identifies a specific version of a resource so conditional requests (If-None-Match / If-Match) can avoid re-sending bytes that haven't changed. Every static-file server needs this, every CDN lives or dies on it. Format (RFC 7232 §2.3): ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4" <- strong ETag: W/"3ad4a9c3" <- weak Strong ETags mean byte-exact match; weak (W/-prefixed) means semantically equivalent but possibly byte-different (e.g. same content reflowed whitespace). We generate ETags by: 1. sha256 (existing) of the file contents -> 32 bytes 2. hex-encode (existing) -> 64 ASCII chars 3. truncate to etag_size bytes (caller choice; 8-32 typical) 4. wrap in double quotes Comparison follows RFC 7232 §2.3.2: strong match requires both to be strong and byte-identical; weak match matches regardless of W/- prefix. Invariants: ET1 Output always ends with a trailing DQUOTE. ET2 Weak prefix is exactly "W/" (2 ASCII bytes, case-sensitive). ET3 Caller chooses truncation length; 8 hex chars (4 bytes of entropy) is the minimum practical, 32 (128 bits) is plenty.

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_sha256.nx nx_hex_codec.nx nx_etag.nx

imports: nx_syscalls.nxnx_sha256.nxnx_hex_codec.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap etag_gen_strong sys_mmap ↻ sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word blk_byte sha256_final blk_set_byte ↻ sha256_compress ↻ hex_encode etag_gen_weak etag_gen_strong ↻ etag_weak_match sys_mmap ↻ etag_strip_quotes etag_is_weak etag_strong_match etag_is_weak ↻ etag_weak_match ↻

structs

none

consts

43const ETAG_ERR_SHORT: i64 = -1

functions

49func etag_gen_strong(data: *u8, n: i64,
72func etag_gen_weak(data: *u8, n: i64,
called by 1: main calls 1: etag_gen_strong
83func etag_is_weak(tag: *u8, n: i64) -> i64
93func etag_strip_quotes(tag: *u8, n: i64,
called by 1: etag_weak_match calls 1: etag_is_weak
107func etag_weak_match(a: *u8, a_len: i64,
127func etag_strong_match(a: *u8, a_len: i64,
called by 1: main calls 2: etag_is_weaketag_weak_match
135func main() -> i64