use alloc::borrow::Cow;
use alloc::string::String;
use core::time::Duration;
mod composite;
#[cfg(feature = "monitor-tracing")]
mod log_monitor;
mod no_monitor;
pub use self::composite::CompositeMonitor;
#[cfg(feature = "monitor-tracing")]
pub use self::log_monitor::LogMonitor;
pub use self::no_monitor::NoMonitor;
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct FailureContext {
pub key_name: String,
pub consecutive_failures: u32,
pub window_elapsed: Duration,
pub note: Cow<'static, str>,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct AccessContext {
pub key_name: String,
pub note: Cow<'static, str>,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct ThresholdContext {
pub key_name: String,
pub failures_in_window: u32,
pub window: Duration,
pub lockout_triggered: bool,
}
pub trait SecurityMonitor: Send + Sync {
fn on_decryption_failure(&self, ctx: &FailureContext);
fn on_anomalous_access(&self, ctx: &AccessContext);
fn on_threshold_breach(&self, ctx: &ThresholdContext);
}
impl SecurityMonitor for alloc::sync::Arc<dyn SecurityMonitor> {
fn on_decryption_failure(&self, ctx: &FailureContext) {
(**self).on_decryption_failure(ctx);
}
fn on_anomalous_access(&self, ctx: &AccessContext) {
(**self).on_anomalous_access(ctx);
}
fn on_threshold_breach(&self, ctx: &ThresholdContext) {
(**self).on_threshold_breach(ctx);
}
}