Debian Codegraph @

src/v4/metric/base/vi.rs

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