Debian Codegraph @

src/v3/base/ui.rs

raw symbols SCIP
1 //! User Interaction (UI)
2
3 use crate::{Error, Metric, MetricType, Result};
4 use alloc::borrow::ToOwned;
5 use core::{fmt, str::FromStr};
6
7 /// User Interaction (UI) - CVSS v3.1 Base Metric Group
8 ///
9 /// Described in CVSS v3.1 Specification: Section 2.1.4:
10 /// <https://www.first.org/cvss/specification-document#t6>
11 ///
12 /// > This metric captures the requirement for a human user, other than the
13 /// > attacker, to participate in the successful compromise of the vulnerable
14 /// > component. This metric determines whether the vulnerability can be
15 /// > exploited solely at the will of the attacker, or whether a separate user
16 /// > (or user-initiated process) must participate in some manner.
17 /// > The Base Score is greatest when no user interaction is required.
18 #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
19 pub enum UserInteraction {
20 /// Required (R)
21 ///
22 /// > Successful exploitation of this vulnerability requires a user to
23 /// > take some action before the vulnerability can be exploited. For
24 /// > example, a successful exploit may only be possible during the
25 /// > installation of an application by a system administrator.
26 Required,
27
28 /// None (N)
29 ///
30 /// > The vulnerable system can be exploited without interaction from any user.
31 None,
32 }
33
34 impl Metric for UserInteraction {
35 const TYPE: MetricType = MetricType::UI;
36
37 fn score(self) -> f64 {
38 match self {
39 UserInteraction::Required => 0.62,
40 UserInteraction::None => 0.85,
41 }
42 }
43
44 fn as_str(self) -> &'static str {
45 match self {
46 UserInteraction::Required => "R",
47 UserInteraction::None => "N",
48 }
49 }
50 }
51
52 impl fmt::Display for UserInteraction {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 write!(f, "{}:{}", Self::name(), self.as_str())
55 }
56 }
57
58 impl FromStr for UserInteraction {
59 type Err = Error;
60
61 fn from_str(s: &str) -> Result<Self> {
62 match s {
63 "R" => Ok(UserInteraction::Required),
64 "N" => Ok(UserInteraction::None),
65 _ => Err(Error::InvalidMetric {
66 metric_type: Self::TYPE,
67 value: s.to_owned(),
68 }),
69 }
70 }
71 }