1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Layer 8 — Security monitor.
//!
//! A [`SecurityMonitor`] is the vault's outbound channel for anomaly events:
//! repeated decryption failures, unusual access patterns, and threshold
//! breaches. Monitor calls happen on the failure path only; the success path
//! costs nothing.
//!
//! Built-in monitors (`NoMonitor`, `LogMonitor`, `MetricsMonitor`,
//! `WebhookMonitor`, `CompositeMonitor`) arrive in Phase 0.8. This module
//! currently defines the trait surface and the three event-context structs.
use Cow;
use String;
use Duration;
/// Context passed when a decryption attempt fails — wrong key, tampered
/// ciphertext, etc.
/// Context for a successful access that the monitor flagged as anomalous —
/// unusual caller, unusual frequency, off-hours activity.
/// Context for a configured threshold being crossed (e.g. N failures in M
/// seconds).
/// Outbound channel for anomaly events.
///
/// Implementations should treat monitor calls as advisory and fire-and-forget:
/// the vault must not block on a monitor, must not crash if a monitor panics
/// or returns an error, and must not retry. Implementations that need
/// retry, queuing, or batching are expected to handle that internally
/// (typically on a background thread).
///
/// # Implementor contract
///
/// - **Non-blocking.** Calls must return promptly. Network or disk work should
/// be deferred to a background worker.
/// - **No panics.** A panicking monitor implementation is a bug in the
/// implementation, not the vault. Wrap fallible operations and absorb
/// their errors.
/// - **No key material in calls.** None of the context structs carry raw key
/// bytes; do not introduce custom side-channels that do.
/// - **`Send + Sync`.** Monitors are shared across threads.