Expand description
One strict grammar for every protocol time.
Credentials, status lists, receipts and every other signed object carry
their times as strings. If two modules (or two languages) read the same
string differently, a time one of them refuses can pass in another. So every
protocol time in the core goes through this module, and the grammar is the
same one the Python, TypeScript and Go implementations use
(test-vectors/time/vector.json is the shared contract):
YYYY-MM-DDTHH:MM:SS[.fraction](Z | +HH:MM | -HH:MM)TandZare upper case and nothing else may appear in the string (no spaces, no trailing newline, no missing offset).- Years run 0001-9999, months and days are real calendar days, hours are
00-23, minutes and seconds 00-59 (a leap second
:60is refused). - The fraction has 1 to 9 digits and is kept at full precision: compare
instants with
parse_protocol_time_ns, never with whole seconds. - The offset is at most 23:59 either way, and the instant it names, moved to UTC, must still fall inside 0001-01-01T00:00:00Z .. 9999-12-31T23:59:59.999999999Z.
A now without a timezone does not match the grammar, so it is refused like
any other malformed time. Clock skew is 0 to 120 seconds
(check_clock_skew); anything else is refused.
Enums§
- Window
State - Where
nowfalls against a validity window.
Constants§
- MAX_
CLOCK_ SKEW_ SECONDS - The largest clock skew a verifier may allow, in seconds.
Functions§
- check_
clock_ skew - Return the clock skew in nanoseconds when it is an allowed value (0 to
MAX_CLOCK_SKEW_SECONDSseconds), else an error. - clock_
skew_ from_ json - Read a clock skew from a JSON request: a whole number of seconds (an
integral float such as 30.0 counts as 30) in 0 to
MAX_CLOCK_SKEW_SECONDS. Booleans, strings, null, fractions and numbers outside the range are refused. - epoch_
seconds_ to_ iso - Format whole seconds since the Unix epoch as
YYYY-MM-DDTHH:MM:SSZ, the inverse ofiso_to_epoch_secondsfor whole-second UTC instants. The wrappers use it to turn the host clock into thenowa verifier passes to the core. - iso_
to_ epoch_ seconds - Parse a protocol time to whole Unix epoch seconds (the floor of the exact
instant). Uses the strict grammar of
parse_protocol_time_ns. - parse_
protocol_ time_ ns - Parse a protocol time into exact nanoseconds since 1970-01-01T00:00:00Z (negative before 1970). Works on bytes and checks every position, so malformed or non-ASCII input returns an error and never panics.
- seconds_
to_ ns - Seconds to nanoseconds, for comparing a whole-second bound (a max age, an interval) against parsed instants.
- window_
state window_state_nsover protocol-time strings. Errors on a malformed time or an out-of-range skew.- window_
state_ ns - Place
now_nsagainst[from - skew, until + skew]at full precision. A missing bound is open on that side. An inverted window is reported first.