1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! CVSS v3 temporal metrics

use crate::common::{AsStr, NumValue, Optional, ParseError};
use std::str;

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq)]
pub enum ExploitCodeMaturity {
    NotDefined,
    High,
    Functional,
    ProofOfConcept,
    Unproven,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq)]
pub enum RemediationLevel {
    NotDefined,
    Unavailable,
    Workaround,
    TemporaryFix,
    OfficialFix,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq)]
pub enum ReportConfidence {
    NotDefined,
    Confirmed,
    Reasonable,
    Unknown,
}

impl AsStr for ExploitCodeMaturity {
    fn as_str(&self) -> &str {
        match self {
            ExploitCodeMaturity::NotDefined => "X",
            ExploitCodeMaturity::High => "H",
            ExploitCodeMaturity::Functional => "F",
            ExploitCodeMaturity::ProofOfConcept => "P",
            ExploitCodeMaturity::Unproven => "U",
        }
    }
}

impl str::FromStr for ExploitCodeMaturity {
    type Err = ParseError;

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        match value {
            "X" => Ok(ExploitCodeMaturity::NotDefined),
            "H" => Ok(ExploitCodeMaturity::High),
            "F" => Ok(ExploitCodeMaturity::Functional),
            "P" => Ok(ExploitCodeMaturity::ProofOfConcept),
            "U" => Ok(ExploitCodeMaturity::Unproven),
            _ => Err(ParseError::IncorrectValue),
        }
    }
}

impl NumValue for ExploitCodeMaturity {
    fn num_value(&self) -> f64 {
        match self {
            ExploitCodeMaturity::NotDefined => 1.0,
            ExploitCodeMaturity::High => 1.0,
            ExploitCodeMaturity::Functional => 0.97,
            ExploitCodeMaturity::ProofOfConcept => 0.94,
            ExploitCodeMaturity::Unproven => 0.91,
        }
    }
}

impl Optional for ExploitCodeMaturity {
    fn is_undefined(&self) -> bool {
        match self {
            ExploitCodeMaturity::NotDefined => true,
            _ => false,
        }
    }
}

impl AsStr for RemediationLevel {
    fn as_str(&self) -> &str {
        match self {
            RemediationLevel::NotDefined => "X",
            RemediationLevel::Unavailable => "U",
            RemediationLevel::Workaround => "W",
            RemediationLevel::TemporaryFix => "T",
            RemediationLevel::OfficialFix => "O",
        }
    }
}

impl str::FromStr for RemediationLevel {
    type Err = ParseError;

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        match value {
            "X" => Ok(RemediationLevel::NotDefined),
            "U" => Ok(RemediationLevel::Unavailable),
            "W" => Ok(RemediationLevel::Workaround),
            "T" => Ok(RemediationLevel::TemporaryFix),
            "O" => Ok(RemediationLevel::OfficialFix),
            _ => Err(ParseError::IncorrectValue),
        }
    }
}

impl NumValue for RemediationLevel {
    fn num_value(&self) -> f64 {
        match self {
            RemediationLevel::NotDefined => 1.0,
            RemediationLevel::Unavailable => 1.0,
            RemediationLevel::Workaround => 0.97,
            RemediationLevel::TemporaryFix => 0.96,
            RemediationLevel::OfficialFix => 0.95,
        }
    }
}

impl Optional for RemediationLevel {
    fn is_undefined(&self) -> bool {
        match self {
            RemediationLevel::NotDefined => true,
            _ => false,
        }
    }
}

impl AsStr for ReportConfidence {
    fn as_str(&self) -> &str {
        match self {
            ReportConfidence::NotDefined => "X",
            ReportConfidence::Confirmed => "C",
            ReportConfidence::Reasonable => "R",
            ReportConfidence::Unknown => "U",
        }
    }
}

impl str::FromStr for ReportConfidence {
    type Err = ParseError;

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        match value {
            "X" => Ok(ReportConfidence::NotDefined),
            "C" => Ok(ReportConfidence::Confirmed),
            "R" => Ok(ReportConfidence::Reasonable),
            "U" => Ok(ReportConfidence::Unknown),
            _ => Err(ParseError::IncorrectValue),
        }
    }
}

impl NumValue for ReportConfidence {
    fn num_value(&self) -> f64 {
        match self {
            ReportConfidence::NotDefined => 1.0,
            ReportConfidence::Confirmed => 1.0,
            ReportConfidence::Reasonable => 0.96,
            ReportConfidence::Unknown => 0.92,
        }
    }
}

impl Optional for ReportConfidence {
    fn is_undefined(&self) -> bool {
        match self {
            ReportConfidence::NotDefined => true,
            _ => false,
        }
    }
}