Debian Codegraph @

src/v4/metric/base/vc.rs

raw symbols SCIP
1 //! Confidentiality Impact to the Vulnerable System (VC)
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 /// Confidentiality Impact to the Vulnerable System (VC) - CVSS v4.0 Base Metric
11 /// Group
12 ///
13 /// Described in CVSS v4.0 Specification: Section 2.2.2
14 ///
15 /// > This metric measures the impact to the confidentiality of the information
16 /// > managed by the system due to a successfully exploited vulnerability.
17 /// > Confidentiality refers to limiting information access and disclosure to
18 /// > only authorized users, as well as preventing access by, or disclosure to,
19 /// > unauthorized ones. The resulting score is greatest when the loss to the
20 /// > system is highest.
21 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
22 pub enum ConfidentialityImpactToTheVulnerableSystem {
23 /// None (N)
24 ///
25 /// > There is no loss of confidentiality within the Vulnerable System.
26 None,
27
28 /// Low (L)
29 ///
30 /// > There is some loss of confidentiality. Access to some restricted
31 /// > information is obtained, but the attacker does not have control over
32 /// > what information is obtained, or the amount or kind of loss is
33 /// > limited. The information disclosure does not cause a direct, serious
34 /// > loss to the Vulnerable System.
35 Low,
36
37 /// High (H)
38 ///
39 /// > There is a total loss of confidentiality, resulting in all information
40 /// > within the Vulnerable System being divulged to the attacker.
41 /// > Alternatively, access to only some restricted information is obtained,
42 /// > but the disclosed information presents a direct, serious impact. For
43 /// > example, an attacker steals the administrator's password, or private
44 /// > encryption keys of a web server.
45 High,
46 }
47
48 impl Default for ConfidentialityImpactToTheVulnerableSystem {
49 fn default() -> Self {
50 Self::High
51 }
52 }
53
54 impl Metric for ConfidentialityImpactToTheVulnerableSystem {
55 const TYPE: MetricType = MetricType::VC;
56
57 fn as_str(self) -> &'static str {
58 match self {
59 ConfidentialityImpactToTheVulnerableSystem::None => "N",
60 ConfidentialityImpactToTheVulnerableSystem::Low => "L",
61 ConfidentialityImpactToTheVulnerableSystem::High => "H",
62 }
63 }
64 }
65
66 impl fmt::Display for ConfidentialityImpactToTheVulnerableSystem {
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 ConfidentialityImpactToTheVulnerableSystem {
73 type Err = Error;
74
75 fn from_str(s: &str) -> Result<Self> {
76 match s {
77 "N" => Ok(ConfidentialityImpactToTheVulnerableSystem::None),
78 "L" => Ok(ConfidentialityImpactToTheVulnerableSystem::Low),
79 "H" => Ok(ConfidentialityImpactToTheVulnerableSystem::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::{
96 MetricLevel, environmental::ModifiedConfidentialityImpactToTheVulnerableSystem,
97 },
98 },
99 };
100 use alloc::borrow::ToOwned;
101 use core::str::FromStr;
102
103 /// Result of the merging of the base and modified metrics.
104 ///
105 /// Used in scoring.
106 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
107 pub(crate) enum MergedConfidentialityImpactToTheVulnerableSystem {
108 High,
109 Low,
110 None,
111 }
112
113 impl Default for MergedConfidentialityImpactToTheVulnerableSystem {
114 fn default() -> Self {
115 Self::High
116 }
117 }
118
119 impl MetricLevel for MergedConfidentialityImpactToTheVulnerableSystem {
120 fn level(self) -> f64 {
121 // VC_levels = {'H': 0.0, 'L': 0.1, 'N': 0.2}
122 match self {
123 Self::High => 0.0,
124 Self::Low => 0.1,
125 Self::None => 0.2,
126 }
127 }
128 }
129
130 impl FromStr for MergedConfidentialityImpactToTheVulnerableSystem {
131 type Err = Error;
132
133 fn from_str(s: &str) -> Result<Self> {
134 match s {
135 "H" => Ok(MergedConfidentialityImpactToTheVulnerableSystem::High),
136 "L" => Ok(MergedConfidentialityImpactToTheVulnerableSystem::Low),
137 "N" => Ok(MergedConfidentialityImpactToTheVulnerableSystem::None),
138 _ => Err(Error::InvalidMetricV4 {
139 metric_type: MetricType::VC,
140 value: s.to_owned(),
141 }),
142 }
143 }
144 }
145
146 impl ConfidentialityImpactToTheVulnerableSystem {
147 pub(crate) fn merge(
148 self,
149 value: Option<ModifiedConfidentialityImpactToTheVulnerableSystem>,
150 ) -> MergedConfidentialityImpactToTheVulnerableSystem {
151 match value {
152 Some(ModifiedConfidentialityImpactToTheVulnerableSystem::NotDefined) | None => {
153 match self {
154 Self::High => MergedConfidentialityImpactToTheVulnerableSystem::High,
155 Self::Low => MergedConfidentialityImpactToTheVulnerableSystem::Low,
156 Self::None => MergedConfidentialityImpactToTheVulnerableSystem::None,
157 }
158 }
159 Some(ModifiedConfidentialityImpactToTheVulnerableSystem::High) => {
160 MergedConfidentialityImpactToTheVulnerableSystem::High
161 }
162 Some(ModifiedConfidentialityImpactToTheVulnerableSystem::Low) => {
163 MergedConfidentialityImpactToTheVulnerableSystem::Low
164 }
165 Some(ModifiedConfidentialityImpactToTheVulnerableSystem::None) => {
166 MergedConfidentialityImpactToTheVulnerableSystem::None
167 }
168 }
169 }
170 }
171 }