Debian Codegraph @

src/v4/metric/supplemental/s.rs

raw symbols SCIP
1 //! Safety (S)
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 /// Safety (S) - CVSS v4.0 Supplemental Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 5.1
13 ///
14 /// > Like all Supplemental Metrics, providing a value for Safety is completely
15 /// > optional. Suppliers and vendors (AKA: scoring providers) may or may not
16 /// > provide Safety as a Supplemental Metric as they see fit.
17 /// > When a system does have an intended use or fitness of purpose aligned to
18 /// > safety, it is possible that exploiting a vulnerability within that system
19 /// > may have Safety impact which can be represented in the Supplemental
20 /// > Metrics group. Lack of a Safety metric value being supplied does NOT mean
21 /// > that there may not be any Safety-related impacts.
22 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
23 pub enum Safety {
24 /// Not Defined (X)
25 ///
26 /// > The metric has not been evaluated.
27 NotDefined,
28
29 /// Present (P)
30 ///
31 /// > Consequences of the vulnerability meet definition of IEC 61508
32 /// > consequence categories of "marginal," "critical," or "catastrophic."
33 Present,
34
35 /// Negligible (N)
36 ///
37 /// > Consequences of the vulnerability meet definition of IEC 61508
38 /// > consequence category "negligible."
39 Negligible,
40 }
41
42 impl Default for Safety {
43 fn default() -> Self {
44 Self::NotDefined
45 }
46 }
47
48 impl Metric for Safety {
49 const TYPE: MetricType = MetricType::S;
50
51 fn as_str(self) -> &'static str {
52 match self {
53 Safety::NotDefined => "X",
54 Safety::Present => "P",
55 Safety::Negligible => "N",
56 }
57 }
58 }
59
60 impl fmt::Display for Safety {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 write!(f, "{}:{}", Self::name(), self.as_str())
63 }
64 }
65
66 impl FromStr for Safety {
67 type Err = Error;
68
69 fn from_str(s: &str) -> Result<Self> {
70 match s {
71 "X" => Ok(Safety::NotDefined),
72 "P" => Ok(Safety::Present),
73 "N" => Ok(Safety::Negligible),
74 _ => Err(Error::InvalidMetricV4 {
75 metric_type: Self::TYPE,
76 value: s.to_owned(),
77 }),
78 }
79 }
80 }