1use crate::common::{NumValue, Optional, ParseError};
4use std::str;
5
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
8pub enum Exploitability {
9 NotDefined,
10 High,
11 Functional,
12 ProofOfConcept,
13 Unproven,
14}
15
16#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
17#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
18pub enum RemediationLevel {
19 NotDefined,
20 Unavailable,
21 Workaround,
22 TemporaryFix,
23 OfficialFix,
24}
25
26#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
27#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
28pub enum ReportConfidence {
29 Unconfirmed,
30 Uncorroborated,
31 Confirmed,
32 NotDefined,
33}
34
35impl AsRef<str> for Exploitability {
36 fn as_ref(&self) -> &str {
37 match self {
38 Exploitability::NotDefined => "ND",
39 Exploitability::High => "H",
40 Exploitability::Functional => "F",
41 Exploitability::ProofOfConcept => "POC",
42 Exploitability::Unproven => "U",
43 }
44 }
45}
46
47impl str::FromStr for Exploitability {
48 type Err = ParseError;
49
50 fn from_str(value: &str) -> Result<Self, Self::Err> {
51 match value {
52 "ND" => Ok(Exploitability::NotDefined),
53 "H" => Ok(Exploitability::High),
54 "F" => Ok(Exploitability::Functional),
55 "POC" => Ok(Exploitability::ProofOfConcept),
56 "U" => Ok(Exploitability::Unproven),
57 _ => Err(ParseError::IncorrectValue),
58 }
59 }
60}
61
62impl NumValue for Exploitability {
63 fn num_value(&self) -> f64 {
64 match self {
65 Exploitability::NotDefined => 1.0,
66 Exploitability::High => 1.0,
67 Exploitability::Functional => 0.95,
68 Exploitability::ProofOfConcept => 0.9,
69 Exploitability::Unproven => 0.85,
70 }
71 }
72}
73
74impl Optional for Exploitability {
75 fn is_undefined(&self) -> bool {
76 match self {
77 Exploitability::NotDefined => true,
78 _ => false,
79 }
80 }
81}
82
83impl AsRef<str> for RemediationLevel {
84 fn as_ref(&self) -> &str {
85 match self {
86 RemediationLevel::NotDefined => "ND",
87 RemediationLevel::Unavailable => "U",
88 RemediationLevel::Workaround => "W",
89 RemediationLevel::TemporaryFix => "TF",
90 RemediationLevel::OfficialFix => "OF",
91 }
92 }
93}
94
95impl str::FromStr for RemediationLevel {
96 type Err = ParseError;
97
98 fn from_str(value: &str) -> Result<Self, Self::Err> {
99 match value {
100 "ND" => Ok(RemediationLevel::NotDefined),
101 "U" => Ok(RemediationLevel::Unavailable),
102 "W" => Ok(RemediationLevel::Workaround),
103 "TF" => Ok(RemediationLevel::TemporaryFix),
104 "OF" => Ok(RemediationLevel::OfficialFix),
105 _ => Err(ParseError::IncorrectValue),
106 }
107 }
108}
109
110impl NumValue for RemediationLevel {
111 fn num_value(&self) -> f64 {
112 match self {
113 RemediationLevel::NotDefined => 1.0,
114 RemediationLevel::Unavailable => 1.0,
115 RemediationLevel::Workaround => 0.95,
116 RemediationLevel::TemporaryFix => 0.90,
117 RemediationLevel::OfficialFix => 0.87,
118 }
119 }
120}
121
122impl Optional for RemediationLevel {
123 fn is_undefined(&self) -> bool {
124 match self {
125 RemediationLevel::NotDefined => true,
126 _ => false,
127 }
128 }
129}
130
131impl AsRef<str> for ReportConfidence {
132 fn as_ref(&self) -> &str {
133 match self {
134 ReportConfidence::Unconfirmed => "UC",
135 ReportConfidence::Uncorroborated => "UR",
136 ReportConfidence::Confirmed => "C",
137 ReportConfidence::NotDefined => "ND",
138 }
139 }
140}
141
142impl str::FromStr for ReportConfidence {
143 type Err = ParseError;
144
145 fn from_str(value: &str) -> Result<Self, Self::Err> {
146 match value {
147 "UC" => Ok(ReportConfidence::Unconfirmed),
148 "UR" => Ok(ReportConfidence::Uncorroborated),
149 "C" => Ok(ReportConfidence::Confirmed),
150 "ND" => Ok(ReportConfidence::NotDefined),
151 _ => Err(ParseError::IncorrectValue),
152 }
153 }
154}
155
156impl NumValue for ReportConfidence {
157 fn num_value(&self) -> f64 {
158 match self {
159 ReportConfidence::Unconfirmed => 0.90,
160 ReportConfidence::Uncorroborated => 0.95,
161 ReportConfidence::Confirmed => 1.0,
162 ReportConfidence::NotDefined => 1.0,
163 }
164 }
165}
166
167impl Optional for ReportConfidence {
168 fn is_undefined(&self) -> bool {
169 match self {
170 ReportConfidence::NotDefined => true,
171 _ => false,
172 }
173 }
174}