use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PolicyWarning {
InvalidIdentityHash { identity_hash: String, label: String },
InvalidBlockedPrefix { prefix: String },
NormalizedIdentityHash { original: String, normalized: String },
NormalizedBlockedPrefix { original: String, normalized: String },
UnknownGrant { identity_hash: String, grant: String },
DuplicateRosterEntry { identity_hash: String, kept_role: String, dropped_role: String },
}
impl fmt::Display for PolicyWarning {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidIdentityHash { identity_hash, label } => write!(
f,
"dropped roster entry: invalid identity hash '{identity_hash}' \
(must be 32 hex chars){label_suffix}",
label_suffix =
if label.is_empty() { String::new() } else { format!(" [label: {label}]") }
),
Self::InvalidBlockedPrefix { prefix } => {
write!(f, "dropped blocked prefix: '{prefix}' (must be >= 8 hex chars)")
}
Self::NormalizedIdentityHash { original, normalized } => {
write!(f, "normalized identity hash: '{original}' -> '{normalized}'")
}
Self::NormalizedBlockedPrefix { original, normalized } => {
write!(f, "normalized blocked prefix: '{original}' -> '{normalized}'")
}
Self::UnknownGrant { identity_hash, grant } => write!(
f,
"dropped unknown grant '{grant}' from identity '{identity_hash}' \
(not a known capability — possible typo?)"
),
Self::DuplicateRosterEntry { identity_hash, kept_role, dropped_role } => write!(
f,
"duplicate roster entry for '{identity_hash}': \
kept role '{kept_role}', dropped role '{dropped_role}'"
),
}
}
}