Debian Codegraph @

src/v4/metric/supplemental/u.rs

raw symbols SCIP
1 //! Provider Urgency (U)
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 /// Provider Urgency (U) - CVSS v4.0 Supplemental Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 5.3
13 ///
14 /// > Many vendors currently provide supplemental severity ratings to consumers
15 /// > via product security advisories. Other vendors publish Qualitative
16 /// > Severity Ratings from the CVSS Specification Document in their advisories.
17 /// >
18 /// > To facilitate a standardized method to incorporate additional
19 /// > provider-supplied assessment, an optional “pass-through” Supplemental
20 /// > Metric called Provider Urgency is available.
21 /// >
22 /// > Note: While any assessment provider along the product supply chain may
23 /// > provide a Provider Urgency rating:
24 /// >
25 /// > Library Maintainer → OS/Distro Maintainer → Provider 1 … Provider n (PPP)
26 /// > → Consumer
27 /// >
28 /// > The Penultimate Product Provider (PPP) is best positioned to provide a
29 /// > direct assessment of Provider Urgency.
30 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
31 pub enum ProviderUrgency {
32 /// Not Defined (X)
33 ///
34 /// > The metric has not been evaluated.
35 NotDefined,
36 /// Red
37 ///
38 /// > Provider has assessed the impact of this vulnerability as having the
39 /// > highest urgency.
40 Red,
41 /// Amber
42 ///
43 /// > Provider has assessed the impact of this vulnerability as having a
44 /// > moderate urgency.
45 Amber,
46 /// Green
47 ///
48 /// > Provider has assessed the impact of this vulnerability as having a
49 /// > reduced urgency.
50 Green,
51 /// Clear
52 ///
53 /// > Provider has assessed the impact of this vulnerability as having no
54 /// > urgency (Informational).
55 Clear,
56 }
57
58 impl Default for ProviderUrgency {
59 fn default() -> Self {
60 Self::NotDefined
61 }
62 }
63
64 impl Metric for ProviderUrgency {
65 const TYPE: MetricType = MetricType::U;
66
67 fn as_str(self) -> &'static str {
68 match self {
69 ProviderUrgency::NotDefined => "X",
70 ProviderUrgency::Red => "Red",
71 ProviderUrgency::Amber => "Amber",
72 ProviderUrgency::Green => "Green",
73 ProviderUrgency::Clear => "Clear",
74 }
75 }
76 }
77
78 impl fmt::Display for ProviderUrgency {
79 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80 write!(f, "{}:{}", Self::name(), self.as_str())
81 }
82 }
83
84 impl FromStr for ProviderUrgency {
85 type Err = Error;
86
87 fn from_str(s: &str) -> Result<Self> {
88 match s {
89 "X" => Ok(ProviderUrgency::NotDefined),
90 "RED" => Ok(ProviderUrgency::Red),
91 "AMBER" => Ok(ProviderUrgency::Amber),
92 "GREEN" => Ok(ProviderUrgency::Green),
93 "CLEAR" => Ok(ProviderUrgency::Clear),
94 _ => Err(Error::InvalidMetricV4 {
95 metric_type: Self::TYPE,
96 value: s.to_owned(),
97 }),
98 }
99 }
100 }