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
//! Severity assigned to findings produced by detection rules.
use core::fmt;
/// Indicates the impact of a detected finding.
///
/// Severity expresses how important a finding is from a security or operational
/// perspective. It is assigned by the matching rule and does not depend on how
/// confident the scanner is that the finding is correct.
///
/// The ordering of the variants follows their natural importance:
///
/// ```text
/// Info < Low < Medium < High < Critical
/// ```
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum Severity {
/// Informational finding with no immediate action required.
Info,
/// Low-impact finding.
Low,
/// Medium-impact finding.
Medium,
/// High-impact finding.
High,
/// Critical finding requiring immediate attention.
Critical,
}
impl Severity {
/// Returns `true` when this severity is considered high priority.
#[must_use]
pub const fn is_high_priority(self) -> bool {
matches!(self, Self::High | Self::Critical)
}
}
impl fmt::Display for Severity {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(match self {
Self::Info => "info",
Self::Low => "low",
Self::Medium => "medium",
Self::High => "high",
Self::Critical => "critical",
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn severity_order_matches_documentation() {
assert!(Severity::Info < Severity::Low);
assert!(Severity::Low < Severity::Medium);
assert!(Severity::Medium < Severity::High);
assert!(Severity::High < Severity::Critical);
}
#[test]
fn detects_high_priority_levels() {
assert!(!Severity::Info.is_high_priority());
assert!(!Severity::Medium.is_high_priority());
assert!(Severity::High.is_high_priority());
assert!(Severity::Critical.is_high_priority());
}
}