Skip to content

Commit

Permalink
page
Browse files Browse the repository at this point in the history
  • Loading branch information
cn-kali-team committed Nov 21, 2023
1 parent da34e7b commit 151cb33
Show file tree
Hide file tree
Showing 44 changed files with 284 additions and 315 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ Cargo.lock
*.xml.zip
/helper/examples/nvdcve/data-feeds.html
/.env
/nvd-api/nvd-er.mwb.bak
/nvd-api/dist/
/nvd-server/nvd-er.mwb.bak
/nvd-server/dist/
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]
members = ["cpe", "cve", "cvss", "cwe", "helper", "nvd-api", "nvd-yew"]
default-members = ["nvd-api"]
members = ["cpe", "cve", "cvss", "cwe", "helper", "nvd-server", "nvd-yew"]
default-members = ["nvd-server"]

#https://github.com/johnthagen/min-sized-rust
[profile.release]
Expand Down
1 change: 0 additions & 1 deletion cvss/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ edition = "2021"

[dependencies]
serde = { version = "1", features = ["derive"] }
phf = { version = "0.11", features = ["macros"] }
thiserror = "1.0"
6 changes: 3 additions & 3 deletions cvss/src/metric/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ mod v2;
mod v3;
mod v4;

use std::fmt::{Debug, Display};
use std::str::FromStr;
pub use crate::metric::v2::MetricTypeV2;
pub use crate::metric::v3::MetricTypeV3;
pub use crate::metric::v4::MetricTypeV4;
use std::fmt::{Debug, Display};
use std::str::FromStr;

#[derive(Debug, Clone)]
pub struct Help {
Expand Down Expand Up @@ -82,5 +82,5 @@ pub trait Metric: Clone + Debug + FromStr + Display {
pub enum MetricType {
V2(MetricTypeV2),
V3(MetricTypeV3),
V4(MetricTypeV4)
V4(MetricTypeV4),
}
74 changes: 37 additions & 37 deletions cvss/src/metric/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,56 @@ use std::str::FromStr;

#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum MetricTypeV2 {
/// Attack Complexity (AC)
AC,
/// Attack Complexity (AC)
AC,

/// Attack Vector (AV)
AV,
/// Attack Vector (AV)
AV,

/// Authentication(Au)
Au,
/// Authentication(Au)
Au,

/// Confidentiality Impact (C)
C,
/// Confidentiality Impact (C)
C,

/// Integrity Impact (I)
I,
/// Availability Impact (A)
A,
/// Integrity Impact (I)
I,
/// Availability Impact (A)
A,
}

impl MetricTypeV2 {
/// Get the name of this metric (i.e. acronym)
pub fn name(self) -> &'static str {
match self {
Self::A => "A",
Self::AC => "AC",
Self::AV => "AV",
Self::C => "C",
Self::I => "I",
Self::Au => "Au",
}
/// Get the name of this metric (i.e. acronym)
pub fn name(self) -> &'static str {
match self {
Self::A => "A",
Self::AC => "AC",
Self::AV => "AV",
Self::C => "C",
Self::I => "I",
Self::Au => "Au",
}
}
}

impl Display for MetricTypeV2 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.name())
}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.name())
}
}

impl FromStr for MetricTypeV2 {
type Err = CVSSError;

fn from_str(s: &str) -> Result<Self> {
match s {
"A" => Ok(Self::A),
"AC" => Ok(Self::AC),
"AV" => Ok(Self::AV),
"C" => Ok(Self::C),
"I" => Ok(Self::I),
"Au" => Ok(Self::Au),
_ => Err(CVSSError::UnknownMetric { name: s.to_owned() }),
}
type Err = CVSSError;

fn from_str(s: &str) -> Result<Self> {
match s {
"A" => Ok(Self::A),
"AC" => Ok(Self::AC),
"AV" => Ok(Self::AV),
"C" => Ok(Self::C),
"I" => Ok(Self::I),
"Au" => Ok(Self::Au),
_ => Err(CVSSError::UnknownMetric { name: s.to_owned() }),
}
}
}
14 changes: 7 additions & 7 deletions cvss/src/v2/access_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ impl FromStr for AccessVectorType {
let name = Self::name();
let s = s.to_uppercase();
let (_name, v) = s
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
let c = v.chars().next();
match c {
Some('N') => Ok(Self::Network),
Some('A') => Ok(Self::AdjacentNetwork),
Some('L') => Ok(Self::Local),
_ => Err(CVSSError::InvalidCVSS {
key: name.to_string(),
value:format!("{:?}", c),
value: format!("{:?}", c),
expected: "N,A,L".to_string(),
}),
}
Expand Down
14 changes: 7 additions & 7 deletions cvss/src/v2/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ impl FromStr for AuthenticationType {
let name = Self::name();
let s = s.to_uppercase();
let (_name, v) = s
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
let c = v.chars().next();
match c {
Some('M') => Ok(Self::Multiple),
Some('S') => Ok(Self::Single),
Some('N') => Ok(Self::None),
_ => Err(CVSSError::InvalidCVSS {
key: name.to_string(),
value:format!("{:?}", c),
value: format!("{:?}", c),
expected: "M,S,N".to_string(),
}),
}
Expand Down
14 changes: 7 additions & 7 deletions cvss/src/v3/attack_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ impl FromStr for AttackComplexityType {
let name = Self::name();
let s = s.to_uppercase();
let (_name, v) = s
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
let c = v.chars().next();
match c {
Some('L') => Ok(Self::Low),
Some('H') => Ok(Self::High),
_ => Err(CVSSError::InvalidCVSS {
key: name.to_string(),
value:format!("{:?}", c),
value: format!("{:?}", c),
expected: "L,H".to_string(),
}),
}
Expand Down
14 changes: 7 additions & 7 deletions cvss/src/v3/attack_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ impl FromStr for AttackVectorType {
let name = Self::name();
let s = s.to_uppercase();
let (_name, v) = s
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
let c = v.chars().next();
match c {
Some('N') => Ok(Self::Network),
Expand All @@ -111,7 +111,7 @@ impl FromStr for AttackVectorType {
Some('P') => Ok(Self::Physical),
_ => Err(CVSSError::InvalidCVSS {
key: name.to_string(),
value:format!("{:?}", c),
value: format!("{:?}", c),
expected: "N,A,L,P".to_string(),
}),
}
Expand Down
42 changes: 21 additions & 21 deletions cvss/src/v3/impact_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ impl FromStr for ConfidentialityImpactType {
let name = Self::name();
let s = s.to_uppercase();
let (_name, v) = s
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
let c = v.chars().next();
match c {
Some('N') => Ok(Self::None),
Some('L') => Ok(Self::Low),
Some('H') => Ok(Self::High),
_ => Err(CVSSError::InvalidCVSS {
key: name.to_string(),
value:format!("{:?}", c),
value: format!("{:?}", c),
expected: "N,L,H".to_string(),
}),
}
Expand All @@ -120,20 +120,20 @@ impl FromStr for IntegrityImpactType {
let name = Self::name();
let s = s.to_uppercase();
let (_name, v) = s
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
let c = v.chars().next();
match c {
Some('N') => Ok(Self::None),
Some('L') => Ok(Self::Low),
Some('H') => Ok(Self::High),
_ => Err(CVSSError::InvalidCVSS {
key: name.to_string(),
value:format!("{:?}", c),
value: format!("{:?}", c),
expected: "N,L,H".to_string(),
}),
}
Expand All @@ -146,20 +146,20 @@ impl FromStr for AvailabilityImpactType {
let name = Self::name();
let s = s.to_uppercase();
let (_name, v) = s
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
let c = v.chars().next();
match c {
Some('N') => Ok(Self::None),
Some('L') => Ok(Self::Low),
Some('H') => Ok(Self::High),
_ => Err(CVSSError::InvalidCVSS {
key: name.to_string(),
value:format!("{:?}", c),
value: format!("{:?}", c),
expected: "N,L,H".to_string(),
}),
}
Expand Down
4 changes: 3 additions & 1 deletion cvss/src/v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use crate::metric::Metric;
use crate::severity::SeverityType;
use crate::v3::attack_complexity::AttackComplexityType;
use crate::v3::attack_vector::AttackVectorType;
use crate::v3::impact_metrics::{AvailabilityImpactType, ConfidentialityImpactType, Impact, IntegrityImpactType};
use crate::v3::impact_metrics::{
AvailabilityImpactType, ConfidentialityImpactType, Impact, IntegrityImpactType,
};
use crate::v3::privileges_required::PrivilegesRequiredType;
use crate::v3::scope::ScopeType;
use crate::v3::user_interaction::UserInteractionType;
Expand Down
14 changes: 7 additions & 7 deletions cvss/src/v3/privileges_required.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@ impl FromStr for PrivilegesRequiredType {
let name = Self::name();
let s = s.to_uppercase();
let (_name, v) = s
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
.split_once(&format!("{}:", name))
.ok_or(CVSSError::InvalidCVSS {
key: name.to_string(),
value: s.to_string(),
expected: name.to_string(),
})?;
let c = v.chars().next();
match c {
Some('N') => Ok(Self::None),
Some('L') => Ok(Self::Low),
Some('H') => Ok(Self::High),
_ => Err(CVSSError::InvalidCVSS {
key: name.to_string(),
value:format!("{:?}", c),
value: format!("{:?}", c),
expected: "N,L,H".to_string(),
}),
}
Expand Down
Loading

0 comments on commit 151cb33

Please sign in to comment.