| 1 |
|
| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 23 |
pub enum IntegrityImpactToTheVulnerableSystem { |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
None, |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
Low, |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
High, |
| 45 |
} |
| 46 |
|
| 47 |
impl Default for IntegrityImpactToTheVulnerableSystem { |
| 48 |
fn default() -> Self { |
| 49 |
Self::High |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
impl Metric for IntegrityImpactToTheVulnerableSystem { |
| 54 |
const TYPE: MetricType = MetricType::VI; |
| 55 |
|
| 56 |
fn as_str(self) -> &'static str { |
| 57 |
match self { |
| 58 |
IntegrityImpactToTheVulnerableSystem::None => "N", |
| 59 |
IntegrityImpactToTheVulnerableSystem::Low => "L", |
| 60 |
IntegrityImpactToTheVulnerableSystem::High => "H", |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
impl fmt::Display for IntegrityImpactToTheVulnerableSystem { |
| 66 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 67 |
write!(f, "{}:{}", Self::name(), self.as_str()) |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
impl FromStr for IntegrityImpactToTheVulnerableSystem { |
| 72 |
type Err = Error; |
| 73 |
|
| 74 |
fn from_str(s: &str) -> Result<Self> { |
| 75 |
match s { |
| 76 |
"N" => Ok(IntegrityImpactToTheVulnerableSystem::None), |
| 77 |
"L" => Ok(IntegrityImpactToTheVulnerableSystem::Low), |
| 78 |
"H" => Ok(IntegrityImpactToTheVulnerableSystem::High), |
| 79 |
_ => Err(Error::InvalidMetricV4 { |
| 80 |
metric_type: Self::TYPE, |
| 81 |
value: s.to_owned(), |
| 82 |
}), |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
#[cfg(feature = "std")] |
| 88 |
pub(crate) mod merge { |
| 89 |
use super::*; |
| 90 |
use crate::{ |
| 91 |
Error, |
| 92 |
v4::{ |
| 93 |
MetricType, |
| 94 |
metric::{MetricLevel, environmental::ModifiedIntegrityImpactToTheVulnerableSystem}, |
| 95 |
}, |
| 96 |
}; |
| 97 |
use alloc::borrow::ToOwned; |
| 98 |
use core::str::FromStr; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 104 |
pub(crate) enum MergedIntegrityImpactToTheVulnerableSystem { |
| 105 |
High, |
| 106 |
Low, |
| 107 |
None, |
| 108 |
} |
| 109 |
|
| 110 |
impl Default for MergedIntegrityImpactToTheVulnerableSystem { |
| 111 |
fn default() -> Self { |
| 112 |
Self::High |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
impl FromStr for MergedIntegrityImpactToTheVulnerableSystem { |
| 117 |
type Err = Error; |
| 118 |
|
| 119 |
fn from_str(s: &str) -> Result<Self> { |
| 120 |
match s { |
| 121 |
"H" => Ok(MergedIntegrityImpactToTheVulnerableSystem::High), |
| 122 |
"L" => Ok(MergedIntegrityImpactToTheVulnerableSystem::Low), |
| 123 |
"N" => Ok(MergedIntegrityImpactToTheVulnerableSystem::None), |
| 124 |
_ => Err(Error::InvalidMetricV4 { |
| 125 |
metric_type: MetricType::VI, |
| 126 |
value: s.to_owned(), |
| 127 |
}), |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
impl MetricLevel for MergedIntegrityImpactToTheVulnerableSystem { |
| 133 |
fn level(self) -> f64 { |
| 134 |
|
| 135 |
match self { |
| 136 |
Self::High => 0.0, |
| 137 |
Self::Low => 0.1, |
| 138 |
Self::None => 0.2, |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
impl IntegrityImpactToTheVulnerableSystem { |
| 144 |
pub(crate) fn merge( |
| 145 |
self, |
| 146 |
value: Option<ModifiedIntegrityImpactToTheVulnerableSystem>, |
| 147 |
) -> MergedIntegrityImpactToTheVulnerableSystem { |
| 148 |
match value { |
| 149 |
Some(ModifiedIntegrityImpactToTheVulnerableSystem::NotDefined) | None => match self |
| 150 |
{ |
| 151 |
Self::High => MergedIntegrityImpactToTheVulnerableSystem::High, |
| 152 |
Self::Low => MergedIntegrityImpactToTheVulnerableSystem::Low, |
| 153 |
Self::None => MergedIntegrityImpactToTheVulnerableSystem::None, |
| 154 |
}, |
| 155 |
Some(ModifiedIntegrityImpactToTheVulnerableSystem::High) => { |
| 156 |
MergedIntegrityImpactToTheVulnerableSystem::High |
| 157 |
} |
| 158 |
Some(ModifiedIntegrityImpactToTheVulnerableSystem::Low) => { |
| 159 |
MergedIntegrityImpactToTheVulnerableSystem::Low |
| 160 |
} |
| 161 |
Some(ModifiedIntegrityImpactToTheVulnerableSystem::None) => { |
| 162 |
MergedIntegrityImpactToTheVulnerableSystem::None |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
} |