issuance.rs (2061B)
1 use crate::{ContextError, UnixSeconds}; 2 3 /// Maximum interval between checked preparation and first signing invocation. 4 pub const FIRST_ISSUANCE_MAX_SECONDS: u64 = 120; 5 6 /// Validated retained timing data. This value observes no clock and grants no 7 /// permission to sign. Current authority and dispatch must be checked separately; 8 /// expiry never proves that an already dispatched request remained unissued. 9 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 10 pub struct IssuanceWindow { 11 prepared_at: UnixSeconds, 12 first_issue_not_after: UnixSeconds, 13 } 14 impl IssuanceWindow { 15 /// Validates an explicitly retained, possibly stricter first-issue interval. 16 pub fn new( 17 prepared_at: UnixSeconds, 18 first_issue_not_after: UnixSeconds, 19 ) -> Result<Self, ContextError> { 20 if prepared_at.get() == 0 21 || first_issue_not_after <= prepared_at 22 || first_issue_not_after.get() - prepared_at.get() > FIRST_ISSUANCE_MAX_SECONDS 23 { 24 return Err(ContextError::OutOfRange); 25 } 26 Ok(Self { 27 prepared_at, 28 first_issue_not_after, 29 }) 30 } 31 /// Captures the default interval using the host's checked observation and 32 /// exact authorization deadline. Neither input is independently trusted here. 33 pub fn capture( 34 prepared_at: UnixSeconds, 35 authorization_not_after: UnixSeconds, 36 ) -> Result<Self, ContextError> { 37 let ceiling = prepared_at 38 .get() 39 .checked_add(FIRST_ISSUANCE_MAX_SECONDS) 40 .ok_or(ContextError::OutOfRange)?; 41 let deadline = UnixSeconds::new(core::cmp::min(ceiling, authorization_not_after.get()))?; 42 Self::new(prepared_at, deadline) 43 } 44 /// Returns the original checked preparation observation. 45 pub const fn prepared_at(self) -> UnixSeconds { 46 self.prepared_at 47 } 48 /// Returns the exclusive first-issue bound; retries must never extend it. 49 pub const fn first_issue_not_after(self) -> UnixSeconds { 50 self.first_issue_not_after 51 } 52 }