Debian Codegraph @

src/v4/metric/base/sa.rs

raw symbols SCIP
1 //! Availability Impact to the Subsequent System (SA)
2
3 use crate::{
4 Error, Result,
5 v4::metric::{Metric, MetricType},
6 };
7 use alloc::borrow::ToOwned;
8 use core::{fmt, str::FromStr};
9
10 /// Availability Impact to the Subsequent System (SA) - CVSS v4.0 Base Metric
11 /// Group
12 ///
13 /// Described in CVSS v4.0 Specification: Section 2.2.8
14 ///
15 /// > This metric measures the impact to the availability of the impacted system
16 /// > resulting from a successfully exploited vulnerability. While the
17 /// > Confidentiality and Integrity impact metrics apply to the loss of
18 /// > confidentiality or integrity of data (e.g., information, files) used by
19 /// > the system, this metric refers to the loss of availability of the impacted
20 /// > system itself, such as a networked service (e.g., web, database, email).
21 /// > Since availability refers to the accessibility of information resources,
22 /// > attacks that consume network bandwidth, processor cycles, or disk space
23 /// > all impact the availability of a system. The resulting score is greatest
24 /// > when the consequence to the system is highest.
25 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
26 pub enum AvailabilityImpactToTheSubsequentSystem {
27 /// None (N)
28 ///
29 /// > There is no impact to availability within the Subsequent System or all
30 /// > availability impact is constrained to the Vulnerable System.
31 None,
32
33 /// Low (L)
34 ///
35 /// > Performance is reduced or there are interruptions in resource
36 /// > availability. Even if repeated exploitation of the vulnerability is
37 /// > possible, the attacker does not have the ability to completely deny
38 /// > service to legitimate users. The resources in the Subsequent System
39 /// > are either partially available all of the time, or fully available
40 /// > only some of the time, but overall there is no direct, serious
41 /// > consequence to the Subsequent System.
42 Low,
43
44 /// High (H)
45 ///
46 /// > There is a total loss of availability, resulting in the attacker being
47 /// > able to fully deny access to resources in the Subsequent System; this
48 /// > loss is either sustained (while the attacker continues to deliver the
49 /// > attack) or persistent (the condition persists even after the attack
50 /// > has completed). Alternatively, the attacker has the ability to deny
51 /// > some availability, but the loss of availability presents a direct,
52 /// > serious consequence to the Subsequent System (e.g., the attacker
53 /// > cannot disrupt existing connections, but can prevent new connections;
54 /// > the attacker can repeatedly exploit a vulnerability that, in each
55 /// > instance of a successful attack, leaks a only small amount of memory,
56 /// > but after repeated exploitation causes a service to become completely
57 /// > unavailable).
58 High,
59 }
60
61 impl Default for AvailabilityImpactToTheSubsequentSystem {
62 fn default() -> Self {
63 Self::High
64 }
65 }
66
67 impl Metric for AvailabilityImpactToTheSubsequentSystem {
68 const TYPE: MetricType = MetricType::SA;
69
70 fn as_str(self) -> &'static str {
71 match self {
72 AvailabilityImpactToTheSubsequentSystem::None => "N",
73 AvailabilityImpactToTheSubsequentSystem::Low => "L",
74 AvailabilityImpactToTheSubsequentSystem::High => "H",
75 }
76 }
77 }
78
79 impl fmt::Display for AvailabilityImpactToTheSubsequentSystem {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 write!(f, "{}:{}", Self::name(), self.as_str())
82 }
83 }
84
85 impl FromStr for AvailabilityImpactToTheSubsequentSystem {
86 type Err = Error;
87
88 fn from_str(s: &str) -> Result<Self> {
89 match s {
90 "N" => Ok(AvailabilityImpactToTheSubsequentSystem::None),
91 "L" => Ok(AvailabilityImpactToTheSubsequentSystem::Low),
92 "H" => Ok(AvailabilityImpactToTheSubsequentSystem::High),
93 _ => Err(Error::InvalidMetricV4 {
94 metric_type: Self::TYPE,
95 value: s.to_owned(),
96 }),
97 }
98 }
99 }
100
101 #[cfg(feature = "std")]
102 pub(crate) mod merge {
103 use super::*;
104 use crate::{
105 Error,
106 v4::{
107 MetricType,
108 metric::{MetricLevel, environmental::ModifiedAvailabilityImpactToTheSubsequentSystem},
109 },
110 };
111 use alloc::borrow::ToOwned;
112 use core::str::FromStr;
113
114 /// Result of the merging of the base and modified metrics.
115 ///
116 /// Used in scoring.
117 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
118 pub(crate) enum MergedAvailabilityImpactToTheSubsequentSystem {
119 Safety,
120 High,
121 Low,
122 None,
123 }
124
125 impl Default for MergedAvailabilityImpactToTheSubsequentSystem {
126 fn default() -> Self {
127 Self::High
128 }
129 }
130
131 impl FromStr for MergedAvailabilityImpactToTheSubsequentSystem {
132 type Err = Error;
133
134 fn from_str(s: &str) -> Result<Self> {
135 match s {
136 "S" => Ok(MergedAvailabilityImpactToTheSubsequentSystem::Safety),
137 "H" => Ok(MergedAvailabilityImpactToTheSubsequentSystem::High),
138 "L" => Ok(MergedAvailabilityImpactToTheSubsequentSystem::Low),
139 "N" => Ok(MergedAvailabilityImpactToTheSubsequentSystem::None),
140 _ => Err(Error::InvalidMetricV4 {
141 metric_type: MetricType::SA,
142 value: s.to_owned(),
143 }),
144 }
145 }
146 }
147
148 impl MetricLevel for MergedAvailabilityImpactToTheSubsequentSystem {
149 fn level(self) -> f64 {
150 // SA_levels = {'S': 0.0, 'H': 0.1, 'L': 0.2, 'N': 0.3}
151 match self {
152 Self::Safety => 0.0,
153 Self::High => 0.1,
154 Self::Low => 0.2,
155 Self::None => 0.3,
156 }
157 }
158 }
159
160 impl AvailabilityImpactToTheSubsequentSystem {
161 pub(crate) fn merge(
162 self,
163 value: Option<ModifiedAvailabilityImpactToTheSubsequentSystem>,
164 ) -> MergedAvailabilityImpactToTheSubsequentSystem {
165 match value {
166 Some(ModifiedAvailabilityImpactToTheSubsequentSystem::NotDefined) | None => {
167 match self {
168 Self::High => MergedAvailabilityImpactToTheSubsequentSystem::High,
169 Self::Low => MergedAvailabilityImpactToTheSubsequentSystem::Low,
170 Self::None => MergedAvailabilityImpactToTheSubsequentSystem::None,
171 }
172 }
173 Some(ModifiedAvailabilityImpactToTheSubsequentSystem::High) => {
174 MergedAvailabilityImpactToTheSubsequentSystem::High
175 }
176 Some(ModifiedAvailabilityImpactToTheSubsequentSystem::Low) => {
177 MergedAvailabilityImpactToTheSubsequentSystem::Low
178 }
179 Some(ModifiedAvailabilityImpactToTheSubsequentSystem::Negligible) => {
180 MergedAvailabilityImpactToTheSubsequentSystem::None
181 }
182 Some(ModifiedAvailabilityImpactToTheSubsequentSystem::Safety) => {
183 MergedAvailabilityImpactToTheSubsequentSystem::Safety
184 }
185 }
186 }
187 }
188 }