Debian Codegraph @

src/v3/base/a.rs

raw symbols SCIP
1 //! Availability Impact (A)
2
3 use crate::{Error, Metric, MetricType, Result};
4 use alloc::borrow::ToOwned;
5 use core::{fmt, str::FromStr};
6
7 /// Availability Impact (A) - CVSS v3.1 Base Metric Group
8 ///
9 /// Described in CVSS v3.1 Specification: Section 2.3.3:
10 /// <https://www.first.org/cvss/specification-document#t6>
11 ///
12 /// > This metric measures the impact to the availability of the impacted
13 /// > component resulting from a successfully exploited vulnerability.
14 /// > While the Confidentiality and Integrity impact metrics apply to the
15 /// > loss of confidentiality or integrity of data (e.g., information,
16 /// > files) used by the impacted component, this metric refers to the loss
17 /// > of availability of the impacted component itself, such as a networked
18 /// > service (e.g., web, database, email). Since availability refers to the
19 /// > accessibility of information resources, attacks that consume network
20 /// > bandwidth, processor cycles, or disk space all impact the availability
21 /// > of an impacted component. The Base Score is greatest when the
22 /// > consequence to the impacted component is highest.
23 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
24 pub enum Availability {
25 /// None (N)
26 ///
27 /// > There is no impact to availability within the impacted component.
28 None,
29
30 /// Low (L)
31 ///
32 /// > Performance is reduced or there are interruptions in resource
33 /// > availability. Even if repeated exploitation of the vulnerability
34 /// > is possible, the attacker does not have the ability to completely
35 /// > deny service to legitimate users. The resources in the impacted
36 /// > component are either partially available all of the time, or fully
37 /// > available only some of the time, but overall there is no direct,
38 /// > serious consequence to the impacted component.
39 Low,
40
41 /// High (H)
42 ///
43 /// > There is a total loss of availability, resulting in the attacker
44 /// > being able to fully deny access to resources in the impacted
45 /// > component; this loss is either sustained (while the attacker
46 /// > continues to deliver the attack) or persistent (the condition
47 /// > persists even after the attack has completed). Alternatively,
48 /// > the attacker has the ability to deny some availability, but
49 /// > the loss of availability presents a direct, serious consequence
50 /// > to the impacted component (e.g., the attacker cannot disrupt
51 /// > existing connections, but can prevent new connections; the
52 /// > attacker can repeatedly exploit a vulnerability that, in each
53 /// > instance of a successful attack, leaks a only small amount of
54 /// > memory, but after repeated exploitation causes a service to become
55 /// > completely unavailable).
56 High,
57 }
58
59 impl Metric for Availability {
60 const TYPE: MetricType = MetricType::A;
61
62 fn score(self) -> f64 {
63 match self {
64 Availability::None => 0.0,
65 Availability::Low => 0.22,
66 Availability::High => 0.56,
67 }
68 }
69
70 fn as_str(self) -> &'static str {
71 match self {
72 Availability::None => "N",
73 Availability::Low => "L",
74 Availability::High => "H",
75 }
76 }
77 }
78
79 impl fmt::Display for Availability {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 write!(f, "{}:{}", Self::name(), self.as_str())
82 }
83 }
84
85 impl FromStr for Availability {
86 type Err = Error;
87
88 fn from_str(s: &str) -> Result<Self> {
89 match s {
90 "N" => Ok(Availability::None),
91 "L" => Ok(Availability::Low),
92 "H" => Ok(Availability::High),
93 _ => Err(Error::InvalidMetric {
94 metric_type: Self::TYPE,
95 value: s.to_owned(),
96 }),
97 }
98 }
99 }