Digestif. Hasher behaviour
(digestif v0.2.0)
Copy Markdown
Behaviour and migration dispatcher for password hashers.
A hasher is configured as a {module, options} tuple. The module performs
one algorithm; this dispatcher identifies the self-describing algorithm in
a stored hash and routes verification only to the configured primary or
legacy hashers.
Hashers may expose a rehash predicate, configuration validation, aliases for compatible stored prefixes, and a password byte limit. The bundled adapters also perform a small resource preflight before invoking their cryptographic backend.
Use the simpler Digestif facade in ordinary applications. This module is
the extension and integration boundary for authentication libraries and
custom hashers.
Summary
Functions
Returns whether a verified hash should be replaced by the primary hasher.
Returns a hasher's declared password byte limit, or nil when unlimited.
Validates one hasher tuple and its options.
Validates a primary hasher and its legacy migration set.
Verifies a value against the hasher selected by the stored algorithm.
Types
Callbacks
@callback algorithm() :: String.t()
@callback algorithm_aliases() :: [String.t()]
@callback password_byte_limit() :: pos_integer()
@callback validate_options!(options :: keyword()) :: :ok
Functions
Returns whether a verified hash should be replaced by the primary hasher.
A hash verified by a legacy hasher always needs rehashing. For the primary
hasher, its optional needs_rehash?/2 callback decides.
@spec password_byte_limit(t()) :: pos_integer() | nil
Returns a hasher's declared password byte limit, or nil when unlimited.
@spec validate!(t()) :: :ok
Validates one hasher tuple and its options.
Validates a primary hasher and its legacy migration set.
Legacy hashers must declare self-describing algorithm identifiers. All identifiers and aliases must be unique, so dispatch cannot depend on list order.
Verifies a value against the hasher selected by the stored algorithm.
Only the primary hasher and explicitly listed legacy hashers are eligible. Unknown or malformed algorithm identifiers fall back to the primary hasher, which must fail closed for foreign encodings.