nx_jwt.nx
buildroot/runtime/nx_jwt.nx
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
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
structs
| none |
consts
| 37 | const JWT_ERR_FORMAT: i64 = -1 |
| 38 | const JWT_ERR_SHORT: i64 = -2 |
| 39 | const JWT_ERR_SIG: i64 = -3 |
functions
| 43 | func jwt_b64url_encode(data: *u8, n: i64, out: *u8) -> i64 |
| 64 | func jwt_b64url_decode(chars: *u8, n: i64, out: *u8) -> i64 |
| 88 | func jwt_sign_hs256(out: *u8, cap: i64, |
| 144 | func jwt_verify_hs256(token: *u8, n: i64, |
| 195 | func main() -> i64 |