Skip to main content

Module hash

Module hash 

Source
Expand description

Keeping and checking secrets: bearer keys and passwords, as self-describing strings.

These are plain functions and types for anyone writing a provider over their own data; nothing here knows about tables or files.

Kept asWrittenFor
SHA-256sha256:<64 lowercase hex>bearer keys of 256 random bits, which need no slow hash
Argon2id$argon2id$v=19$m=…,t=…,p=…$salt$hashpasswords, or keys that must resist guessing

A stored string names its own algorithm, so one table may hold both.

Structs§

Argon2Params
The cost of an Argon2id hash. The default is the Argon2 crate’s: 19 MiB, 2 passes, 1 lane.
PasswordHasher
Hashes passwords with Argon2id and checks them, with a dummy hash for names nobody keeps.

Enums§

KeyHash
How a bearer key is kept.

Constants§

DEFAULT_MAX_PASSWORD_BYTES
The longest password hashed or verified unless PasswordHasher::max_password_bytes says otherwise: 4 096 bytes. It bounds the work one attempt costs.

Traits§

Argon2ParamsSetters
The typed setters of Argon2Params, for any builder that holds its settings.

Functions§

generate_key
Makes a key: prefix and 256 random bits. See secret::generate.
is_key_hash
Whether stored is a string verify_key can check: a well-formed sha256: digest or an Argon2id hash.
is_password_hash
Whether stored is a well-formed Argon2id hash, as PasswordHasher::hash writes it.
verify_key
Whether presented is the secret stored was made from, whatever algorithm stored names. A string that names no known algorithm is never a match.
verify_password
Whether presented is the password stored (an Argon2id hash) was made from. A password over DEFAULT_MAX_PASSWORD_BYTES or a stored string that is not Argon2id never matches; PasswordHasher::verify applies the hasher’s own bound instead.