Debian Codegraph @

src/v4/metric/environmental/mpr.rs

raw symbols SCIP
1 //! Privileges Required (MPR)
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 /// Privileges Required (MPR) - CVSS v4.0 Environmental Metric Group
11 ///
12 /// Described in CVSS v4.0 Specification: Section 4.2
13 ///
14 /// > This metric describes the level of privileges an attacker must possess
15 /// > prior to successfully exploiting the vulnerability. The method by which
16 /// > the attacker obtains privileged credentials prior to the attack (e.g.,
17 /// > free trial accounts), is outside the scope of this metric. Generally,
18 /// > self-service provisioned accounts do not constitute a privilege
19 /// > requirement if the attacker can grant themselves privileges as part of the
20 /// > attack.
21 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
22 pub enum ModifiedPrivilegesRequired {
23 /// Not Defined (X)
24 ///
25 /// > The metric has not been evaluated.
26 NotDefined,
27
28 /// High (H)
29 ///
30 /// > The attacker requires privileges that provide significant (e.g.,
31 /// > administrative) control over the vulnerable system allowing full
32 /// > access to the vulnerable system’s settings and files.
33 High,
34
35 /// Low (L)
36 ///
37 /// > The attacker requires privileges that provide basic capabilities that
38 /// > are typically limited to settings and resources owned by a single
39 /// > low-privileged user. Alternatively, an attacker with Low privileges
40 /// > has the ability to access only non-sensitive resources.
41 Low,
42
43 /// None (N)
44 ///
45 /// > The attacker is unauthenticated prior to attack, and therefore does
46 /// > not require any access to settings or files of the vulnerable system
47 /// > to carry out an attack.
48 None,
49 }
50
51 impl Default for ModifiedPrivilegesRequired {
52 fn default() -> Self {
53 Self::NotDefined
54 }
55 }
56
57 impl Metric for ModifiedPrivilegesRequired {
58 const TYPE: MetricType = MetricType::MPR;
59
60 fn as_str(self) -> &'static str {
61 match self {
62 ModifiedPrivilegesRequired::NotDefined => "X",
63 ModifiedPrivilegesRequired::None => "N",
64 ModifiedPrivilegesRequired::Low => "L",
65 ModifiedPrivilegesRequired::High => "H",
66 }
67 }
68 }
69
70 impl fmt::Display for ModifiedPrivilegesRequired {
71 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72 write!(f, "{}:{}", Self::name(), self.as_str())
73 }
74 }
75
76 impl FromStr for ModifiedPrivilegesRequired {
77 type Err = Error;
78
79 fn from_str(s: &str) -> Result<Self> {
80 match s {
81 "X" => Ok(ModifiedPrivilegesRequired::NotDefined),
82 "N" => Ok(ModifiedPrivilegesRequired::None),
83 "L" => Ok(ModifiedPrivilegesRequired::Low),
84 "H" => Ok(ModifiedPrivilegesRequired::High),
85 _ => Err(Error::InvalidMetricV4 {
86 metric_type: Self::TYPE,
87 value: s.to_owned(),
88 }),
89 }
90 }
91 }