Repository navigation
Conversation
verify_claims always read the system clock, so callers with their own time source (deterministic simulation, tests, a trusted clock) had to disable the exp/nbf checks and reimplement them. Add VerificationOptions::now(timestamp); when unset, the system clock is used as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zshenker
force-pushed
the
verification-clock
branch
from
October 19, 2026 21:43
d3e3b0c to
9bdbaf2
Compare
VerificationOptions::leeway(seconds) tolerates small clock differences between issuer and verifier in one pass: a token stays valid up to `leeway` seconds after exp and becomes valid `leeway` seconds before nbf. Additions saturate. Defaults to 0, so behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Token::verify_claimsalways reads the system clock for theexpandnbfchecks. Callers with their own time source have to turn those checks off and reimplement them. Examples include deterministic simulation, tests, and services with a trusted clock.Change
VerificationOptionsgains a new field,now: Option<u64>, with a builder method,now(timestamp). When it's set,verify_claimsuses that value instead of the system clock. When it's unset, the system clock is used as before.VerificationOptions::leeway(seconds)tolerates clock skew in the same pass: a token stays valid up toleewayseconds afterexpand becomes validleewayseconds beforenbf(saturating; default 0).The informational helpers (
Token::is_expired,expires_in,is_valid_yetand theRegisteredClaimsequivalents) are unchanged and still use the system clock.This PR is based on
main. A dry merge shows no conflicts with #6, #8, #9 or #10. The tests are in a newsrc/tests_clock.rsto avoid conflicts with the edits #6 makes tosrc/tests.rs.Tests
test_injected_clock_drives_exp_and_nbfchecks thenbfandexpboundaries under an injected time. The token is rejected one second beforenbf, accepted atnbfand atexp − 1, and rejected atexp.test_system_clock_is_the_defaultchecks that the system clock is still used whennowis unset.test_leeway_extends_exp_and_nbf_in_the_permissive_directionandtest_leeway_saturatescover the leeway boundaries and saturation.cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testall pass: 59 unit tests and 73 doctests.🤖 Generated with Claude Code