Skip to main content

hyperion_vault_core/
rotation.rs

1use std::time::Duration;
2
3#[derive(Debug, Clone, Copy)]
4pub struct RotationPolicy {
5    pub interval: Duration,
6    pub grace: Duration,
7}
8
9impl RotationPolicy {
10    pub fn new(interval: Duration, grace: Duration) -> Self {
11        Self { interval, grace }
12    }
13
14    pub fn next_rotation_unix(&self, from_unix: i64) -> i64 {
15        from_unix.saturating_add(self.interval.as_secs() as i64)
16    }
17
18    pub fn grace_expiry_unix(&self, superseded_at_unix: i64) -> i64 {
19        superseded_at_unix.saturating_add(self.grace.as_secs() as i64)
20    }
21}
22
23pub fn is_due(now_unix: i64, next_rotation_unix: i64) -> bool {
24    next_rotation_unix <= now_unix
25}
26
27pub fn version_active(now_unix: i64, expires_at_unix: Option<i64>) -> bool {
28    match expires_at_unix {
29        None => true,
30        Some(expiry) => now_unix < expiry,
31    }
32}