commit d92d0c2c498071e38b0e2f2eee813e11344e070d Author: Jia Chao Date: Tue Jul 23 14:19:50 2024 +0800 init CUSA Signed-off-by: Jia Chao diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..526132d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,65 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cusa" +version = "0.1.0" +dependencies = [ + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.204" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.204" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..15b975e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "cusa" +version = "0.1.0" +edition = "2021" +description = "cusa" + +[dependencies] +serde = { version = "1", features = ["serde_derive"] } diff --git a/README.md b/README.md new file mode 100644 index 0000000..baad9e2 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +CUSA: CULinux SA Info diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..128c9f4 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,86 @@ +use std::fmt; +use std::str::FromStr; + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub struct CUSA { + // sa id + pub id: String, + + // sa's url + pub url: String, + + // sa title + pub title: String, + + // the major severity + pub severity: Severity, + + pub description: String, + + // 包含的 cve 列表 + pub cves: Vec, +} + +#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum Severity { + None, + Low, + Medium, // Moderate + High, // Important + Critical, +} + +impl Severity { + pub fn new() -> Self { + Severity::None + } +} + +// 为枚举 Severity 实现 FromStr trait +impl FromStr for Severity { + type Err = ParseSeverityError; + + // bug fix: 华为不干人事儿,单词都能拼错,现在只取首字母 + fn from_str(s: &str) -> Result { + match s.to_lowercase().chars().next() { + Some('n') => Ok(Severity::None), + Some('l') => Ok(Severity::Low), + Some('m') => Ok(Severity::Medium), + Some('i') | Some('h') => Ok(Severity::High), + Some('c') => Ok(Severity::Critical), + _ => Err(ParseSeverityError::InvalidSeverity), + } + } +} + +// 定义 ParseSeverityError 枚举类型来表示解析错误 +#[derive(Debug, Clone)] +pub enum ParseSeverityError { + InvalidSeverity, +} + +// 为 ParseSeverityError 实现 Display trait,以便更好地显示错误信息 +impl fmt::Display for ParseSeverityError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + ParseSeverityError::InvalidSeverity => write!(f, "Invalid severity level"), + } + } +} + +// 为 ParseSeverityError 实现 std::error::Error trait +impl std::error::Error for ParseSeverityError {} + +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub struct CVE { + // cve id + pub id: String, + + // cve 官网地址 + pub url: String, + + // 严重级别 + pub severity: Severity, +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}