1use core::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum PolicyWarning {
11 InvalidIdentityHash { identity_hash: String, label: String },
14 InvalidBlockedPrefix { prefix: String },
17 NormalizedIdentityHash { original: String, normalized: String },
19 NormalizedBlockedPrefix { original: String, normalized: String },
21 UnknownGrant { identity_hash: String, grant: String },
24 DuplicateRosterEntry { identity_hash: String, kept_role: String, dropped_role: String },
27}
28
29impl fmt::Display for PolicyWarning {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Self::InvalidIdentityHash { identity_hash, label } => write!(
33 f,
34 "dropped roster entry: invalid identity hash '{identity_hash}' \
35 (must be 32 hex chars){label_suffix}",
36 label_suffix =
37 if label.is_empty() { String::new() } else { format!(" [label: {label}]") }
38 ),
39 Self::InvalidBlockedPrefix { prefix } => {
40 write!(f, "dropped blocked prefix: '{prefix}' (must be >= 8 hex chars)")
41 }
42 Self::NormalizedIdentityHash { original, normalized } => {
43 write!(f, "normalized identity hash: '{original}' -> '{normalized}'")
44 }
45 Self::NormalizedBlockedPrefix { original, normalized } => {
46 write!(f, "normalized blocked prefix: '{original}' -> '{normalized}'")
47 }
48 Self::UnknownGrant { identity_hash, grant } => write!(
49 f,
50 "dropped unknown grant '{grant}' from identity '{identity_hash}' \
51 (not a known capability — possible typo?)"
52 ),
53 Self::DuplicateRosterEntry { identity_hash, kept_role, dropped_role } => write!(
54 f,
55 "duplicate roster entry for '{identity_hash}': \
56 kept role '{kept_role}', dropped role '{dropped_role}'"
57 ),
58 }
59 }
60}