Expand description
One opaque token grammar, and the memory-only key that seals it.
<tag> "." base64url-nopad(payload JSON) "." base64url-nopad(HMAC-SHA256)Two authorities mint tokens in this shape: the peer file handles in crate::peer_handoff,
and the spawn credentials and approvals mur-roost issues. The parts that must not vary live
here — the constant-time comparison, the unambiguous MAC input, and a key that never leaves the
process it was generated in.
A token is bound to its family by two values a caller cannot influence: the version tag, compared before the MAC, and the MAC domain, mixed into the MAC. Distinct pairs mean a token of one family can never verify as another, so an authority that mints several families cannot be made to accept one in another’s place.
Verification order is fixed: shape → MAC → payload. Nothing downstream of the MAC is
evaluated before it passes, so a caller that fails it learns nothing about which field to
change next. For the same reason MacTokenError carries two variants and not five.
A value passed as bound_to is covered by the MAC without being carried in the token. That is
what makes a token non-bearer: holding it is not enough, the holder must also assert the exact
value it was sealed against.
Structs§
- MintKey
- The 32-byte HMAC key one authority mints and verifies with.
Enums§
- MacToken
Error - Why a token’s shape or MAC was not accepted.
Constants§
- B64
- The base64 alphabet used for both token segments: URL-safe and unpadded, so a whole token is
safe in a header value or a request path and has no
=for a transport to mangle. - NONCE_
BYTES - Nonce width in bytes, for a payload field that has to distinguish two otherwise identical tokens.
Functions§
- open
- Verifies one token of the family named by
taganddomainand returns its payload bytes. - payload_
segment - The payload bytes of a token whose MAC has not been checked, for the family named by
tag. - random_
hex bytesrandom bytes as lowercase hex.- seal
- Mints one token over
payload_json, for the family named bytaganddomain. - token_
id - The stable identifier a mint and a redemption are correlated by: the first
[
TOKEN_ID_HEX_CHARS] lowercase hex characters ofsha256(token).