pub trait TimeProvider {
fn now(&mut self) -> (u64, Option<u64>);
#[expect(
unused_variables,
reason = "Names are human visible part of API description"
)]
fn past_trusted(&mut self, timestamp: u64) {}
}
impl<T: TimeProvider> TimeProvider for &mut T {
fn now(&mut self) -> (u64, Option<u64>) {
(*self).now()
}
fn past_trusted(&mut self, timestamp: u64) {
(*self).past_trusted(timestamp);
}
}
pub struct TimeUnknown;
impl TimeProvider for TimeUnknown {
#[inline]
fn now(&mut self) -> (u64, Option<u64>) {
(0, None)
}
}
#[derive(Copy, Clone, Debug)]
pub struct TimeConstraint {
exp: Option<u64>,
}
impl TimeConstraint {
#[must_use]
pub fn unbounded() -> Self {
Self { exp: None }
}
#[must_use]
pub fn from_claims_set(claims: &crate::ace::CwtClaimsSet<'_>) -> Self {
TimeConstraint {
exp: Some(claims.exp),
}
}
pub(crate) fn is_valid_with(&self, time_provider: &mut impl TimeProvider) -> bool {
let Some(exp) = self.exp else {
return true;
};
let (now_early, _now_late) = time_provider.now();
exp > now_early
}
}