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.
Default whole-second tolerance used by Attesto's signed-token profiles.
Fetch a NumericDate claim from claims.
Classify an issued-at value against a future-skew and maximum-age window.
Resolve a Unix-second clock and reject negative values.
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 at or after start and no more than max_seconds later.
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 default_clock_skew_seconds() :: pos_integer()
Default whole-second tolerance used by Attesto's signed-token profiles.
@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.
@spec non_negative_now!(keyword(), keyword()) :: non_neg_integer()
Resolve a Unix-second clock and reject negative values.
Stateful grant transitions use this boundary so a malformed clock cannot produce a record with an invalid expiry or reach a mutating store callback.
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 | :non_negative preserves
whether an invalid :now override raises the generic clock error, silently
uses the live clock, or uses the state-transition non-negative error.
Return whether value is an integer NumericDate for the selected policy.
Return whether finish is at or after start and no more than max_seconds later.