code wiki / (root) / nx_jwt.nx

nx_jwt.nx

buildroot/runtime/nx_jwt.nx

7959 B235 linesdepth 6pulls 8 transitivereach 10 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

jwt.nx -- JSON Web Token sign + verify (HS256 only). RFC 7519 JWT + RFC 7515 JWS + RFC 7518 algorithms. Compact serialisation: BASE64URL(header) . BASE64URL(payload) . BASE64URL(sig) Header: {\"alg\":\"HS256\",\"typ\":\"JWT\"} Payload: arbitrary JSON -- caller decides claims Sig: HMAC-SHA-256(key, \"header64.payload64\") HS256 only today -- RS256/ES256 require RSA/ECDSA, which we haven't finished. HS256 is fine for single-service auth (web app signs its own tokens, verifies its own tokens). For third-party delegation (OAuth 2) the stack will need RS256 later via rsa.nx (pending). Invariants: J1 Verification uses ct_memcmp for the signature compare -- timing-safe against forgery attempts. J2 Input parse is tolerant of missing trailing padding (base64url variant omits '='). J3 We do NOT validate payload claims (exp / nbf / iss). Caller parses the returned payload JSON and checks.

dependencies 4 imports · 4 importers

nx_syscalls.nx nx_hmac.nx nx_base64.nx nx_ct.nx nx_jwt.nx nx_jose.nx nx_jose_es256.nx nx_jwk.nx nx_jwk_ec.nx

imports: nx_syscalls.nxnx_hmac.nxnx_base64.nxnx_ct.nx

imported by: nx_jose.nxnx_jose_es256.nxnx_jwk.nxnx_jwk_ec.nx

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

main sys_mmap jwt_sign_hs256 sys_mmap ↻ jwt_b64url_encode b64_encode b64_enc_char hmac_sha256 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 sha256_final blk_set_byte ↻ sha256_compress ↻ sha256_init ↻ sha256_update ↻ sha256_final ↻ jwt_verify_hs256 sys_mmap ↻ hmac_sha256 ↻ jwt_b64url_encode ↻ ct_memcmp ct_eq jwt_b64url_decode sys_mmap ↻ b64_decode b64_grab b64_dec_char

structs

none

consts

37const JWT_ERR_FORMAT: i64 = -1
38const JWT_ERR_SHORT: i64 = -2
39const JWT_ERR_SIG: i64 = -3

functions

43func jwt_b64url_encode(data: *u8, n: i64, out: *u8) -> i64
64func jwt_b64url_decode(chars: *u8, n: i64, out: *u8) -> i64
called by 1: jwt_verify_hs256 calls 2: sys_mmapb64_decode
88func jwt_sign_hs256(out: *u8, cap: i64,
144func jwt_verify_hs256(token: *u8, n: i64,
195func main() -> i64