Debian Codegraph @

src/v4/metric/supplemental/v.rs

raw symbols SCIP
1 //! Value Density (V)
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 /// Value Density (V) - CVSS v4.0 Supplemental Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 5.5
13 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
14 pub enum ValueDensity {
15 /// Not Defined (X)
16 ///
17 /// > The metric has not been evaluated.
18 NotDefined,
19
20 /// Diffuse (D)
21 ///
22 /// > The vulnerable system has limited resources. That is, the resources
23 /// > that the attacker will gain control over with a single exploitation
24 /// > event are relatively small. An example of Diffuse (think: limited)
25 /// > Value Density would be an attack on a single email client
26 /// > vulnerability.
27 Diffuse,
28
29 /// Concentrated (C)
30 ///
31 /// > The vulnerable system is rich in resources. Heuristically, such
32 /// > systems are often the direct responsibility of “system operators”
33 /// > rather than users. An example of Concentrated (think: broad) Value
34 /// > Density would be an attack on a central email server.
35 Concentrated,
36 }
37
38 impl Default for ValueDensity {
39 fn default() -> Self {
40 Self::NotDefined
41 }
42 }
43
44 impl Metric for ValueDensity {
45 const TYPE: MetricType = MetricType::V;
46
47 fn as_str(self) -> &'static str {
48 match self {
49 ValueDensity::NotDefined => "X",
50 ValueDensity::Diffuse => "D",
51 ValueDensity::Concentrated => "C",
52 }
53 }
54 }
55
56 impl fmt::Display for ValueDensity {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 write!(f, "{}:{}", Self::name(), self.as_str())
59 }
60 }
61
62 impl FromStr for ValueDensity {
63 type Err = Error;
64
65 fn from_str(s: &str) -> Result<Self> {
66 match s {
67 "X" => Ok(ValueDensity::NotDefined),
68 "D" => Ok(ValueDensity::Diffuse),
69 "C" => Ok(ValueDensity::Concentrated),
70 _ => Err(Error::InvalidMetricV4 {
71 metric_type: Self::TYPE,
72 value: s.to_owned(),
73 }),
74 }
75 }
76 }