use super::{AccessContext, FailureContext, SecurityMonitor, ThresholdContext};
#[derive(Debug, Default, Clone, Copy)]
pub struct LogMonitor;
impl LogMonitor {
#[must_use]
pub fn new() -> Self {
Self
}
}
impl SecurityMonitor for LogMonitor {
fn on_decryption_failure(&self, ctx: &FailureContext) {
let elapsed_ms = u64::try_from(ctx.window_elapsed.as_millis()).unwrap_or(u64::MAX);
tracing::warn!(
target: "key_vault::monitor",
key_name = %ctx.key_name,
consecutive_failures = ctx.consecutive_failures,
window_elapsed_ms = elapsed_ms,
note = %ctx.note,
"key access failure",
);
}
fn on_anomalous_access(&self, ctx: &AccessContext) {
tracing::warn!(
target: "key_vault::monitor",
key_name = %ctx.key_name,
note = %ctx.note,
"anomalous key access",
);
}
fn on_threshold_breach(&self, ctx: &ThresholdContext) {
let window_ms = u64::try_from(ctx.window.as_millis()).unwrap_or(u64::MAX);
tracing::error!(
target: "key_vault::monitor",
key_name = %ctx.key_name,
failures_in_window = ctx.failures_in_window,
window_ms = window_ms,
lockout_triggered = ctx.lockout_triggered,
"threshold breach",
);
}
}