Skip to main content

Module mac_token

Module mac_token 

Source
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§

MacTokenError
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 tag and domain and 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
bytes random bytes as lowercase hex.
seal
Mints one token over payload_json, for the family named by tag and domain.
token_id
The stable identifier a mint and a redemption are correlated by: the first [TOKEN_ID_HEX_CHARS] lowercase hex characters of sha256(token).