Debian Codegraph @

src/v3/base/c.rs

raw symbols SCIP
1 //! Confidentiality Impact (C)
2
3 use crate::{Error, Metric, MetricType};
4 use alloc::borrow::ToOwned;
5 use core::{fmt, str::FromStr};
6
7 /// Confidentiality Impact (C) - CVSS v3.1 Base Metric Group
8 ///
9 /// Described in CVSS v3.1 Specification: Section 2.3.1:
10 /// <https://www.first.org/cvss/specification-document#t6>
11 ///
12 /// > This metric measures the impact to the confidentiality of the information
13 /// > resources managed by a software component due to a successfully exploited
14 /// > vulnerability. Confidentiality refers to limiting information access and
15 /// > disclosure to only authorized users, as well as preventing access by, or
16 /// > disclosure to, unauthorized ones. The Base Score is greatest when the loss
17 /// > to the impacted component is highest.
18 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
19 pub enum Confidentiality {
20 /// None (N)
21 ///
22 /// > There is no loss of confidentiality within the impacted component.
23 None,
24
25 /// Low (L)
26 ///
27 /// > There is some loss of confidentiality. Access to some restricted
28 /// > information is obtained, but the attacker does not have control over
29 /// > what information is obtained, or the amount or kind of loss is
30 /// > limited. The information disclosure does not cause a direct, serious
31 /// > loss to the impacted component.
32 Low,
33
34 /// High (H)
35 ///
36 /// > There is a total loss of confidentiality, resulting in all resources
37 /// > within the impacted component being divulged to the attacker.
38 /// > Alternatively, access to only some restricted information is
39 /// > obtained, but the disclosed information presents a direct, serious
40 /// > impact. For example, an attacker steals the administrator's password,
41 /// > or private encryption keys of a web server.
42 High,
43 }
44
45 impl Metric for Confidentiality {
46 const TYPE: MetricType = MetricType::C;
47
48 fn score(self) -> f64 {
49 match self {
50 Confidentiality::None => 0.0,
51 Confidentiality::Low => 0.22,
52 Confidentiality::High => 0.56,
53 }
54 }
55
56 fn as_str(self) -> &'static str {
57 match self {
58 Confidentiality::None => "N",
59 Confidentiality::Low => "L",
60 Confidentiality::High => "H",
61 }
62 }
63 }
64
65 impl fmt::Display for Confidentiality {
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 Confidentiality {
72 type Err = Error;
73
74 fn from_str(s: &str) -> Result<Self, Error> {
75 match s {
76 "N" => Ok(Confidentiality::None),
77 "L" => Ok(Confidentiality::Low),
78 "H" => Ok(Confidentiality::High),
79 _ => Err(Error::InvalidMetric {
80 metric_type: Self::TYPE,
81 value: s.to_owned(),
82 }),
83 }
84 }
85 }