use crate::v3;
#[cfg(feature = "v4")]
use crate::v4;
use alloc::string::String;
use core::fmt;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Error {
InvalidComponent {
component: String,
},
InvalidMetric {
metric_type: v3::metric::MetricType,
value: String,
},
#[cfg(feature = "v4")]
InvalidMetricV4 {
metric_type: v4::MetricType,
value: String,
},
#[cfg(feature = "v4")]
MissingMandatoryMetricV4 {
metric_type: v4::MetricType,
},
#[cfg(feature = "v4")]
DuplicateMetricV4 {
metric_type: v4::MetricType,
},
#[cfg(feature = "v4")]
InvalidNomenclatureV4 {
nomenclature: String,
},
InvalidPrefix {
prefix: String,
},
InvalidSeverity {
name: String,
},
UnknownMetric {
name: String,
},
UnsupportedVersion {
version: String,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::InvalidComponent { component } => {
write!(f, "invalid CVSS metric group component: `{component}`")
}
Error::InvalidMetric { metric_type, value } => {
write!(
f,
"invalid CVSSv4 {} ({}) metric: `{}`",
metric_type.name(),
metric_type.description(),
value
)
}
#[cfg(feature = "v4")]
Error::InvalidMetricV4 { metric_type, value } => {
write!(
f,
"invalid CVSSv4 {} ({}) metric: `{}`",
metric_type.name(),
metric_type.description(),
value
)
}
#[cfg(feature = "v4")]
Error::DuplicateMetricV4 { metric_type } => {
write!(
f,
"duplicate CVSSv4 {} ({}) metric",
metric_type.name(),
metric_type.description(),
)
}
#[cfg(feature = "v4")]
Error::MissingMandatoryMetricV4 { metric_type } => {
write!(
f,
"missing mandatory CVSSv4 {} ({}) metric",
metric_type.name(),
metric_type.description(),
)
}
#[cfg(feature = "v4")]
Error::InvalidNomenclatureV4 { nomenclature } => {
write!(f, "invalid CVSSv4 nomenclature: `{}`", nomenclature)
}
Error::InvalidPrefix { prefix } => {
write!(f, "invalid CVSS string prefix: `{prefix}`")
}
Error::InvalidSeverity { name } => {
write!(f, "invalid CVSS Qualitative Severity Rating: `{name}`")
}
Error::UnknownMetric { name } => write!(f, "unknown CVSS metric name: `{name}`"),
Error::UnsupportedVersion { version } => {
write!(f, "unsupported CVSS version: {version}")
}
}
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for Error {}