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