Skip to main content

mint_token

Function mint_token 

Source
pub fn mint_token() -> Result<(BundleToken, [u8; 32]), AppError>
Expand description

Mint a fresh bearer token for a new bundle.

Generates 32 random bytes from the OS CSPRNG, encodes as base64url (no padding) for transport, and returns the plaintext token paired with its SHA-256(token_b64) hash. The plaintext is wrapped in a BundleToken so it zeroizes on drop and redacts on Debug; the hash is the value persisted in BundleRecord::token_hash.

Caller responsibility: deliver the plaintext to the client exactly once (in the descriptor response) and then drop it. The server never needs the plaintext again — every subsequent blob-endpoint request validates by re-hashing the caller-supplied header value and constant-time-comparing against the stored hash.