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 as | Written | For |
|---|---|---|
| SHA-256 | sha256:<64 lowercase hex> | bearer keys of 256 random bits, which need no slow hash |
| Argon2id | $argon2id$v=19$m=…,t=…,p=…$salt$hash | passwords, or keys that must resist guessing |
A stored string names its own algorithm, so one table may hold both.
Structs§
- Argon2
Params - The cost of an Argon2id hash. The default is the Argon2 crate’s: 19 MiB, 2 passes, 1 lane.
- Password
Hasher - 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_bytessays otherwise: 4 096 bytes. It bounds the work one attempt costs.
Traits§
- Argon2
Params Setters - The typed setters of
Argon2Params, for any builder that holds its settings.
Functions§
- generate_
key - Makes a key:
prefixand 256 random bits. Seesecret::generate. - is_
key_ hash - Whether
storedis a stringverify_keycan check: a well-formedsha256:digest or an Argon2id hash. - is_
password_ hash - Whether
storedis a well-formed Argon2id hash, asPasswordHasher::hashwrites it. - verify_
key - Whether
presentedis the secretstoredwas made from, whatever algorithmstorednames. A string that names no known algorithm is never a match. - verify_
password - Whether
presentedis the passwordstored(an Argon2id hash) was made from. A password overDEFAULT_MAX_PASSWORD_BYTESor a stored string that is not Argon2id never matches;PasswordHasher::verifyapplies the hasher’s own bound instead.