Debian Codegraph @

src/v3/base/i.rs

raw symbols SCIP
1 //! Integrity Impact (I)
2
3 use crate::{Error, Metric, MetricType, Result};
4 use alloc::borrow::ToOwned;
5 use core::{fmt, str::FromStr};
6
7 /// Integrity Impact (I) - CVSS v3.1 Base Metric Group
8 ///
9 /// Described in CVSS v3.1 Specification: Section 2.3.2:
10 /// <https://www.first.org/cvss/specification-document#t6>
11 ///
12 /// > This metric measures the impact to integrity of a successfully exploited
13 /// > vulnerability. Integrity refers to the trustworthiness and veracity of
14 /// > information. The Base Score is greatest when the consequence to the
15 /// > impacted component is highest.
16 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
17 pub enum Integrity {
18 /// None (N)
19 ///
20 /// > There is no loss of integrity within the impacted component.
21 None,
22
23 /// Low (L)
24 ///
25 /// > Modification of data is possible, but the attacker does not have
26 /// > control over the consequence of a modification, or the amount of
27 /// > modification is limited. The data modification does not have a
28 /// > direct, serious impact on the impacted component.
29 Low,
30
31 /// High (H)
32 ///
33 /// > There is a total loss of integrity, or a complete loss of protection.
34 /// > For example, the attacker is able to modify any/all files protected
35 /// > by the impacted component. Alternatively, only some files can be
36 /// > modified, but malicious modification would present a direct, serious
37 /// > consequence to the impacted component.
38 High,
39 }
40
41 impl Metric for Integrity {
42 const TYPE: MetricType = MetricType::I;
43
44 fn score(self) -> f64 {
45 match self {
46 Integrity::None => 0.0,
47 Integrity::Low => 0.22,
48 Integrity::High => 0.56,
49 }
50 }
51
52 fn as_str(self) -> &'static str {
53 match self {
54 Integrity::None => "N",
55 Integrity::Low => "L",
56 Integrity::High => "H",
57 }
58 }
59 }
60
61 impl fmt::Display for Integrity {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 write!(f, "{}:{}", Self::name(), self.as_str())
64 }
65 }
66
67 impl FromStr for Integrity {
68 type Err = Error;
69
70 fn from_str(s: &str) -> Result<Self> {
71 match s {
72 "N" => Ok(Integrity::None),
73 "L" => Ok(Integrity::Low),
74 "H" => Ok(Integrity::High),
75 _ => Err(Error::InvalidMetric {
76 metric_type: Self::TYPE,
77 value: s.to_owned(),
78 }),
79 }
80 }
81 }