use crate::header::SframeHeader;
mod replay_attack_protection;
mod replay_attack_protection_store;
mod replay_token;
mod sliding_window;
mod tolerance;
mod util;
pub use replay_attack_protection::{ReplayAttackProtection, ReplayAttackProtectionError};
pub use replay_attack_protection_store::{ReplayAttackProtectionStore, ReplayStoreToken};
pub use replay_token::ReplayToken;
pub use tolerance::Tolerance;
pub trait FrameValidation {
type Token;
type Error: std::error::Error + Send + Sync + 'static;
#[must_use = "a screened frame must be recorded once it decrypts, or dropped"]
fn screen(&self, unvalidated: UnvalidatedFrame<'_>) -> Result<Self::Token, Self::Error>;
fn record(&mut self, token: Self::Token);
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct NoValidation;
impl FrameValidation for NoValidation {
type Token = ();
type Error = std::convert::Infallible;
fn screen(&self, _unvalidated: UnvalidatedFrame<'_>) -> Result<Self::Token, Self::Error> {
Ok(())
}
fn record(&mut self, _token: Self::Token) {}
}
#[derive(Debug, Clone, Copy)]
pub struct UnvalidatedFrame<'frame> {
header: &'frame SframeHeader,
meta_data: &'frame [u8],
}
impl<'frame> UnvalidatedFrame<'frame> {
pub fn new(header: &'frame SframeHeader, meta_data: &'frame [u8]) -> Self {
Self { header, meta_data }
}
pub fn header(&self) -> &'frame SframeHeader {
self.header
}
pub fn meta_data(&self) -> &'frame [u8] {
self.meta_data
}
}