Crates.io | nvd |
lib.rs | nvd |
version | 0.1.14 |
source | src |
created_at | 2022-12-27 03:07:58.346498 |
updated_at | 2023-01-06 15:35:37.309578 |
description | Some functions about CPE and CVE |
homepage | |
repository | https://github.com/zgj0315/nvd/ |
max_upload_size | |
id | 746047 |
size | 95,226 |
Some functions about CPE and CVE
Add this to your Cargo.toml:
[dependencies]
nvd = "0.1"
use std::{env, process};
use nvd::{
cpe::{download_cpe, make_cpe_dictionary, make_cpe_title},
cve::{
cpe23_uri_list_to_string, cpe_match, init_dir, load_db, make_db, sync_cve, Cpe23Uri,
DATA_DIR,
},
log::log_init,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
log_init();
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
log::error!("arguments error!");
log::error!("eg: {} [cve|cpe]", args[0]);
process::exit(1);
}
if "cve".eq(&args[1]) {
cve().await?;
} else if "cpe".eq(&args[1]) {
cpe().await?;
} else {
log::error!("arguments error!");
log::error!("eg: {} [cve|cpe]", args[0]);
}
Ok(())
}
async fn cve() -> Result<(), Box<dyn std::error::Error>> {
let path_dir = init_dir(DATA_DIR).await?;
let _ = sync_cve(&path_dir).await?;
let _ = make_db(&path_dir).await?;
let db_list = load_db(&path_dir).await?;
log::info!("db_list len: {}", db_list.len());
let mut cpe23_uri_vec = Vec::new();
let line = "cpe:2.3:a:vmware:rabbitmq:3.9.10:*:*:*:*:*:*:*";
let cpe23_uri = Cpe23Uri::new(line);
cpe23_uri_vec.push(cpe23_uri);
log::info!("cpe23_uri: {}", cpe23_uri_list_to_string(&cpe23_uri_vec));
cpe_match(&cpe23_uri_vec, &db_list).await?;
Ok(())
}
async fn cpe() -> Result<(), Box<dyn std::error::Error>> {
download_cpe().await?;
make_cpe_dictionary().await?;
make_cpe_title().await?;
Ok(())
}