Debian Codegraph @

src/v4/metric/supplemental/au.rs

raw symbols SCIP
1 //! Automatable (AU)
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 /// Automatable (AU) - CVSS v4.0 Supplemental Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 5.2
13 ///
14 /// > The “Automatable” metric captures the answer to the question ”Can an
15 /// > attacker automate exploitation events for this vulnerability across
16 /// > multiple targets?” based on steps 1-4 of the kill chain [Hutchins et al.,
17 /// > 2011]. These steps are reconnaissance, weaponization, delivery, and
18 /// > exploitation.
19 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
20 pub enum Automatable {
21 /// Not Defined (X)
22 ///
23 /// > The metric has not been evaluated.
24 NotDefined,
25
26 /// Yes (Y)
27 ///
28 /// > Attackers can reliably automate all 4 steps of the kill chain. These
29 /// > steps are reconnaissance, weaponization, delivery, and exploitation
30 /// > (e.g., the vulnerability is “wormable”).
31 Yes,
32
33 /// No (N)
34 ///
35 /// > Attackers cannot reliably automate all 4 steps of the kill chain for
36 /// > this vulnerability for some reason. These steps are reconnaissance,
37 /// > weaponization, delivery, and exploitation.
38 No,
39 }
40
41 impl Default for Automatable {
42 fn default() -> Self {
43 Self::NotDefined
44 }
45 }
46
47 impl Metric for Automatable {
48 const TYPE: MetricType = MetricType::AU;
49
50 fn as_str(self) -> &'static str {
51 match self {
52 Automatable::NotDefined => "X",
53 Automatable::Yes => "Y",
54 Automatable::No => "N",
55 }
56 }
57 }
58
59 impl fmt::Display for Automatable {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 write!(f, "{}:{}", Self::name(), self.as_str())
62 }
63 }
64
65 impl FromStr for Automatable {
66 type Err = Error;
67
68 fn from_str(s: &str) -> Result<Self> {
69 match s {
70 "X" => Ok(Automatable::NotDefined),
71 "Y" => Ok(Automatable::Yes),
72 "N" => Ok(Automatable::No),
73 _ => Err(Error::InvalidMetricV4 {
74 metric_type: Self::TYPE,
75 value: s.to_owned(),
76 }),
77 }
78 }
79 }