Debian Codegraph @

src/v4/metric/base/sc.rs

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