Skip to main content

ClockSample

Struct ClockSample 

Source
pub struct ClockSample {
    pub wall_ns: u64,
    pub monotonic: Instant,
}
Expand description

A single paired capture of wall-clock and monotonic time.

Take one per admission with Self::now, then use wall_ns for every certificate/grant/proof freshness check and Self::monotonic_deadline_for to translate the proof’s wall-clock expiry into the monotonic deadline the replay guard retains it under — all relative to the SAME sample.

Fields§

§wall_ns: u64

Wall-clock now, unix NANOSECONDS. Every freshness check reads this — never a freshly-sampled clock.

§monotonic: Instant

Monotonic now, paired with wall_ns. Replay-retention deadlines derive from this so a wall-clock jump cannot shift retention out from under a freshness check.

Implementations§

Source§

impl ClockSample

Source

pub fn now() -> Self

Capture both clocks together. A pre-epoch system clock saturates wall_ns to 0 (the same fail-safe the org module’s current_timestamp uses).

§33 — what that fail-safe actually buys, corrected. The previous note said admission “treats every finite expiry as in the future, which is fine”. The first half is right and the conclusion is not: with wall_ns == 0, check_expiry_at(0, skew) can never expire a proof and its TTL ceiling collapses to MAX_ORG_PROOF_TTL + skew, so proof FRESHNESS is entirely defeated, not merely permissive.

The call is still denied — but by an unrelated check: is_valid_at_with_skew(0, skew) returns NotYetValid for any real certificate, because no certificate’s not_before is 0. So the composition is fail-closed today for a reason this comment did not state, and any future ClockSample consumer that checks only an UPPER time bound would fail OPEN on a machine that boots with a dead RTC.

Reachable in practice: a board with a dead battery comes up at the epoch, and this is exactly when an operator is least likely to be watching admission decisions.

Source

pub fn monotonic_deadline_for(&self, wall_deadline_ns: u64) -> Instant

The monotonic deadline corresponding to a wall-clock expiry (wall_deadline_ns, unix ns), derived RELATIVE to this one sample: monotonic + max(0, wall_deadline_ns - wall_ns).

A deadline already at or behind wall_ns yields self.monotonic (a zero-length retention — the proof is never held beyond its own life), so a proof that just failed freshness cannot be retained, and one that just passed is retained by exactly its remaining validity — consistent with the freshness check that used the same wall_ns.

Source

pub fn wall_secs(&self) -> u64

This sample’s wall clock in whole unix seconds — the single ns→s conversion the second-granularity credential checks (is_valid_at_with_skew, provider self_verify_at) share, so caller AND provider verification read the SAME instant with no hidden second wall read (AV-6 item 6).

Trait Implementations§

Source§

impl Clone for ClockSample

Source§

fn clone(&self) -> ClockSample

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ClockSample

Source§

impl Debug for ClockSample

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more