Value-level helpers for JWT NumericDate comparisons and Unix-second clocks.
This module deliberately does not choose protocol policy. Callers provide requiredness, non-negative validation, leeway, future skew, and maximum age, then map the result to their own error atom.
Summary
Functions
Resolve a positive lifetime option that may only shorten default.
Fetch a NumericDate claim from claims.
Classify an issued-at value against a future-skew and maximum-age window.
Return whether a not-before NumericDate has been reached.
Return whether an expiry remains strictly beyond now - leeway.
Resolve a Unix-second clock from options.
Return whether value is an integer NumericDate for the selected policy.
Return whether finish is no more than max_seconds after start.
Types
@type fetch_result() :: {:ok, integer()} | :missing | {:error, :missing | :invalid}
@type freshness_result() :: :ok | :future | :stale | :invalid
Functions
@spec bounded_lifetime(keyword(), atom(), pos_integer()) :: pos_integer()
Resolve a positive lifetime option that may only shorten default.
A missing, non-positive, non-integer, or longer requested lifetime falls back to the supplied default.
@spec fetch(map(), term(), keyword()) :: fetch_result()
Fetch a NumericDate claim from claims.
Missing optional claims return :missing; missing required claims return
{:error, :missing}. A present value that is not an integer, or is negative
when non_negative: true, returns {:error, :invalid}.
@spec fresh?(term(), term(), keyword()) :: freshness_result()
Classify an issued-at value against a future-skew and maximum-age window.
Boundary values are accepted: iat == now + future_skew and
iat == now - max_age both return :ok.
Return whether a not-before NumericDate has been reached.
Return whether an expiry remains strictly beyond now - leeway.
Resolve a Unix-second clock from options.
| `default: :datetime | :system` preserves the caller's original live-clock |
| source. `invalid_override: :raise | :fallback` preserves whether an invalid |
:now override raised or silently used that live clock.
Return whether value is an integer NumericDate for the selected policy.
Return whether finish is no more than max_seconds after start.