Debian Codegraph @

src/v4/metric/base/si.rs

raw symbols SCIP
1 //! Integrity Impact to the Subsequent System (SI)
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 /// Integrity Impact to the Subsequent System (SI) - CVSS v4.0 Base Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 2.2.5
13 ///
14 /// > This metric measures the impact to integrity of a successfully exploited
15 /// > vulnerability. Integrity refers to the trustworthiness and veracity of
16 /// > information. Integrity of a system is impacted when an attacker causes
17 /// > unauthorized modification of system data. Integrity is also impacted when
18 /// > a system user can repudiate critical actions taken in the context of the
19 /// > system (e.g. due to insufficient logging).
20 /// > The resulting score is greatest when the consequence to the system is
21 /// > highest.
22 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
23 pub enum IntegrityImpactToTheSubsequentSystem {
24 /// None (N)
25 ///
26 /// > There is no loss of integrity within the Subsequent System or all
27 /// > integrity impact is constrained to the Vulnerable System.
28 None,
29
30 /// Low (L)
31 ///
32 /// > Modification of data is possible, but the attacker does not have
33 /// > control over the consequence of a modification, or the amount of
34 /// > modification is limited. The data modification does not have a direct,
35 /// > serious impact to the Subsequent System.
36 Low,
37
38 /// High (H)
39 ///
40 /// > There is a total loss of integrity, or a complete loss of protection.
41 /// > For example, the attacker is able to modify any/all files protected by
42 /// > the Subsequent System. Alternatively, only some files can be modified,
43 /// > but malicious modification would present a direct, serious consequence
44 /// > to the Subsequent System.
45 High,
46 }
47
48 impl Default for IntegrityImpactToTheSubsequentSystem {
49 fn default() -> Self {
50 Self::High
51 }
52 }
53
54 impl Metric for IntegrityImpactToTheSubsequentSystem {
55 const TYPE: MetricType = MetricType::SI;
56
57 fn as_str(self) -> &'static str {
58 match self {
59 IntegrityImpactToTheSubsequentSystem::None => "N",
60 IntegrityImpactToTheSubsequentSystem::Low => "L",
61 IntegrityImpactToTheSubsequentSystem::High => "H",
62 }
63 }
64 }
65
66 impl fmt::Display for IntegrityImpactToTheSubsequentSystem {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 write!(f, "{}:{}", Self::name(), self.as_str())
69 }
70 }
71
72 impl FromStr for IntegrityImpactToTheSubsequentSystem {
73 type Err = Error;
74
75 fn from_str(s: &str) -> Result<Self> {
76 match s {
77 "N" => Ok(IntegrityImpactToTheSubsequentSystem::None),
78 "L" => Ok(IntegrityImpactToTheSubsequentSystem::Low),
79 "H" => Ok(IntegrityImpactToTheSubsequentSystem::High),
80 _ => Err(Error::InvalidMetricV4 {
81 metric_type: Self::TYPE,
82 value: s.to_owned(),
83 }),
84 }
85 }
86 }
87
88 #[cfg(feature = "std")]
89 pub(crate) mod merge {
90 use super::*;
91 use crate::{
92 Error,
93 v4::{
94 MetricType,
95 metric::{MetricLevel, environmental::ModifiedIntegrityImpactToTheSubsequentSystem},
96 },
97 };
98 use alloc::borrow::ToOwned;
99 use core::str::FromStr;
100
101 /// Result of the merging of the base and modified metrics.
102 ///
103 /// Used in scoring.
104 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
105 pub(crate) enum MergedIntegrityImpactToTheSubsequentSystem {
106 Safety,
107 High,
108 Low,
109 None,
110 }
111
112 impl Default for MergedIntegrityImpactToTheSubsequentSystem {
113 fn default() -> Self {
114 Self::High
115 }
116 }
117
118 impl FromStr for MergedIntegrityImpactToTheSubsequentSystem {
119 type Err = Error;
120
121 fn from_str(s: &str) -> Result<Self> {
122 match s {
123 "S" => Ok(MergedIntegrityImpactToTheSubsequentSystem::Safety),
124 "H" => Ok(MergedIntegrityImpactToTheSubsequentSystem::High),
125 "L" => Ok(MergedIntegrityImpactToTheSubsequentSystem::Low),
126 "N" => Ok(MergedIntegrityImpactToTheSubsequentSystem::None),
127 _ => Err(Error::InvalidMetricV4 {
128 metric_type: MetricType::SI,
129 value: s.to_owned(),
130 }),
131 }
132 }
133 }
134
135 impl MetricLevel for MergedIntegrityImpactToTheSubsequentSystem {
136 fn level(self) -> f64 {
137 // SI_levels = {'S': 0.0, 'H': 0.1, 'L': 0.2, 'N': 0.3}
138 match self {
139 Self::Safety => 0.0,
140 Self::High => 0.1,
141 Self::Low => 0.2,
142 Self::None => 0.3,
143 }
144 }
145 }
146
147 impl IntegrityImpactToTheSubsequentSystem {
148 pub(crate) fn merge(
149 self,
150 value: Option<ModifiedIntegrityImpactToTheSubsequentSystem>,
151 ) -> MergedIntegrityImpactToTheSubsequentSystem {
152 match value {
153 Some(ModifiedIntegrityImpactToTheSubsequentSystem::NotDefined) | None => match self
154 {
155 Self::High => MergedIntegrityImpactToTheSubsequentSystem::High,
156 Self::Low => MergedIntegrityImpactToTheSubsequentSystem::Low,
157 Self::None => MergedIntegrityImpactToTheSubsequentSystem::None,
158 },
159 Some(ModifiedIntegrityImpactToTheSubsequentSystem::High) => {
160 MergedIntegrityImpactToTheSubsequentSystem::High
161 }
162 Some(ModifiedIntegrityImpactToTheSubsequentSystem::Low) => {
163 MergedIntegrityImpactToTheSubsequentSystem::Low
164 }
165 Some(ModifiedIntegrityImpactToTheSubsequentSystem::Negligible) => {
166 MergedIntegrityImpactToTheSubsequentSystem::None
167 }
168 Some(ModifiedIntegrityImpactToTheSubsequentSystem::Safety) => {
169 MergedIntegrityImpactToTheSubsequentSystem::Safety
170 }
171 }
172 }
173 }
174 }