Debian Codegraph @

src/v4/metric/supplemental/r.rs

raw symbols SCIP
1 //! Recovery (R)
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 /// Recovery (R) - CVSS v4.0 Supplemental Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 5.4
13 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
14 pub enum Recovery {
15 /// Not Defined (X)
16 ///
17 /// > The metric has not been evaluated.
18 NotDefined,
19
20 /// Automatic (A)
21 ///
22 /// > The system recovers services automatically after an attack has been
23 /// > performed.
24 Automatic,
25
26 /// User (U)
27 ///
28 /// > The system requires manual intervention by the user to recover
29 /// > services, after an attack has been performed.
30 User,
31
32 /// Irrecoverable (I)
33 ///
34 /// > The system services are irrecoverable by the user, after an attack has
35 /// > been performed.
36 Irrecoverable,
37 }
38
39 impl Default for Recovery {
40 fn default() -> Self {
41 Self::NotDefined
42 }
43 }
44
45 impl Metric for Recovery {
46 const TYPE: MetricType = MetricType::R;
47
48 fn as_str(self) -> &'static str {
49 match self {
50 Recovery::NotDefined => "X",
51 Recovery::Automatic => "A",
52 Recovery::User => "U",
53 Recovery::Irrecoverable => "I",
54 }
55 }
56 }
57
58 impl fmt::Display for Recovery {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 write!(f, "{}:{}", Self::name(), self.as_str())
61 }
62 }
63
64 impl FromStr for Recovery {
65 type Err = Error;
66
67 fn from_str(s: &str) -> Result<Self> {
68 match s {
69 "X" => Ok(Recovery::NotDefined),
70 "A" => Ok(Recovery::Automatic),
71 "U" => Ok(Recovery::User),
72 "I" => Ok(Recovery::Irrecoverable),
73 _ => Err(Error::InvalidMetricV4 {
74 metric_type: Self::TYPE,
75 value: s.to_owned(),
76 }),
77 }
78 }
79 }