use crate::traits::Kem;
use std::time::{Duration, Instant};
#[derive(Clone, Copy, Debug)]
pub struct RekeyPolicy {
pub max_bytes: u64,
pub max_records: u64,
pub max_duration: Duration,
}
#[derive(Debug)]
pub struct RekeyState {
pub bytes: u64,
pub records: u64,
pub started: Instant,
}
impl RekeyState {
pub fn new() -> Self { Self { bytes: 0, records: 0, started: Instant::now() } }
pub fn add_record(&mut self, size: u64) { self.bytes += size; self.records += 1; }
pub fn should_rekey(&self, p: &RekeyPolicy) -> bool {
self.bytes >= p.max_bytes || self.records >= p.max_records || self.started.elapsed() >= p.max_duration
}
}
pub fn new_kem_secret<K: Kem>(kem: &K, peer_pk: &K::PublicKey) -> (K::Ciphertext, K::SharedSecret) {
kem.encapsulate(peer_pk)
}