Skip to content

Commit 0199043

Browse files
committed
fix format
1 parent e1f179b commit 0199043

File tree

8 files changed

+96
-34
lines changed

8 files changed

+96
-34
lines changed

cve/src/api/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct CVE {
1515
pub vuln_status: VulnStatus,
1616
pub descriptions: Vec<DescriptionData>,
1717
pub metrics: ImpactMetrics,
18+
#[serde(default)]
1819
pub weaknesses: Vec<ProblemTypeDataItem>,
1920
#[serde(default)]
2021
pub configurations: Vec<Node>,
@@ -27,6 +28,7 @@ pub enum VulnStatus {
2728
Analyzed,
2829
#[serde(rename = "Undergoing Analysis")]
2930
UndergoingAnalysis,
31+
Rejected,
3032
}
3133

3234
#[cfg(test)]

helper/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ serde_yaml = "0.9"
2222
flate2 = "1.0"
2323
zip = "0.6"
2424
cached = "0.44.0"
25+
tokio = { version = "1.34.0", features = ["full"] }
2526
[dev-dependencies]
2627
serde = { version = "1", features = ["derive"] }
2728
quick-xml = { version = "0.29.0", features = ["serde", "encoding_rs", "serialize"] }
2829
serde_yaml = "0.9"
2930
serde_json = "1.0"
3031
flate2 = "1.0"
3132
zip = "0.6"
32-
[[bin]]
33-
name = "cpe_to_db"
34-
path = "src/bin/cpe_to_db.rs"
33+
tokio = { version = "1.34.0", features = ["full"] }

helper/examples/cpe-api-example.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use nvd_api::v2::products::{CpeMatchParameters, CpeParameters};
2+
// https://cwe.mitre.org/data/downloads.html
3+
// curl -s -k https://cwe.mitre.org/data/downloads.html |grep -Eo '(/[^"]*\.xml.zip)'|xargs -I % wget -c https://cwe.mitre.org%
4+
#[tokio::main]
5+
async fn main() {
6+
let api = nvd_api::NVDApi::new(None, "2.0").unwrap();
7+
let cpe = api
8+
.cpe(CpeParameters{
9+
cpe_name_id: None,
10+
cpe_match_string: None,
11+
keyword: None,
12+
last_mod: None,
13+
match_criteria_id: None,
14+
limit_offset: None,
15+
})
16+
.await
17+
.unwrap();
18+
println!("{:?}", cpe.format);
19+
let cpe_match = api
20+
.cpe_match(CpeMatchParameters{
21+
cve_id: None,
22+
last_mod: None,
23+
match_criteria_id: None,
24+
keyword: None,
25+
limit_offset: None,
26+
})
27+
.await
28+
.unwrap();
29+
println!("{:?}", cpe_match.format);
30+
}

helper/examples/cve-api-example.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use nvd_api::v2::vulnerabilities::{CveHistoryParameters, CveParameters};
2+
// https://cwe.mitre.org/data/downloads.html
3+
// curl -s -k https://cwe.mitre.org/data/downloads.html |grep -Eo '(/[^"]*\.xml.zip)'|xargs -I % wget -c https://cwe.mitre.org%
4+
#[tokio::main]
5+
async fn main() {
6+
let api = nvd_api::NVDApi::new(None, "2.0").unwrap();
7+
let cve = api
8+
.cve(CveParameters {
9+
cpe_name: None,
10+
cve_id: None,
11+
cvss_v2_metrics: None,
12+
cvss_v2_severity: None,
13+
cvss_v3_metrics: None,
14+
cvss_v3_severity: None,
15+
cwe_id: None,
16+
has_cert_alerts: None,
17+
has_cert_notes: None,
18+
has_kev: None,
19+
has_oval: None,
20+
is_vulnerable: None,
21+
keyword: None,
22+
last_mod: None,
23+
no_rejected: None,
24+
pub_date: None,
25+
limit_offset: None,
26+
source_identifier: None,
27+
virtual_match: None,
28+
})
29+
.await
30+
.unwrap();
31+
println!("{:?}", cve.format);
32+
let cve_history = api
33+
.cve_history(CveHistoryParameters{
34+
cve_id: None,
35+
change_date: None,
36+
event_name: None,
37+
limit_offset: None,
38+
})
39+
.await
40+
.unwrap();
41+
println!("{:?}", cve_history.format);
42+
}

nvd-api/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::Error;
2-
use crate::pagination::Object;
2+
use crate::pagination::{ListResponse};
33
use reqwest::{ClientBuilder, RequestBuilder};
44

55
mod error;
@@ -37,7 +37,7 @@ impl NVDApi {
3737
}
3838

3939
impl NVDApi {
40-
pub async fn request(&self, request: RequestBuilder) -> Result<Object, Error> {
40+
pub async fn request(&self, request: RequestBuilder) -> Result<ListResponse, Error> {
4141
let request = request.build()?;
4242
let json = self
4343
.client
@@ -47,10 +47,8 @@ impl NVDApi {
4747
.text()
4848
.await
4949
.map_err(|source| Error::ResponseIo { source })?;
50+
// println!("{}", json);
5051
let result = serde_json::from_str(&json).map_err(|source| Error::JsonParse { source })?;
51-
match result {
52-
Object::Error { error } => Err(Error::Api { error }),
53-
response => Ok(response),
54-
}
52+
Ok(result)
5553
}
5654
}

nvd-api/src/pagination.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
use crate::error::ErrorResponse;
22
use crate::v2::products::{MatchStrings, Products};
3-
use crate::v2::vulnerabilities::{Change, Vulnerabilities};
3+
use crate::v2::vulnerabilities::{CveChanges, Vulnerabilities};
44
use chrono::NaiveDateTime;
55
use serde::{Deserialize, Serialize};
6-
7-
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone)]
8-
#[serde(transparent)]
9-
pub struct PagingCursor(String);
10-
11-
#[derive(Serialize, Debug, Eq, PartialEq, Default, Clone)]
12-
pub struct Paging {
13-
#[serde(skip_serializing_if = "Option::is_none")]
14-
pub start_cursor: Option<PagingCursor>,
15-
#[serde(skip_serializing_if = "Option::is_none")]
16-
pub page_size: Option<u8>,
17-
}
18-
19-
pub trait Pageable {
20-
fn start_from(self, starting_point: Option<PagingCursor>) -> Self;
21-
}
22-
236
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
247
#[serde(rename_all(deserialize = "camelCase"))]
258
pub struct ListResponse {
@@ -37,7 +20,7 @@ pub struct ListResponse {
3720
#[serde(rename_all = "camelCase")]
3821
pub enum Object {
3922
Vulnerabilities(Vec<Vulnerabilities>),
40-
CveChanges(Vec<Change>),
23+
CveChanges(Vec<CveChanges>),
4124
Products(Vec<Products>),
4225
MatchStrings(Vec<MatchStrings>),
4326
Error {

nvd-api/src/v2/api.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
use crate::pagination::Object;
1+
use crate::pagination::ListResponse;
22
use crate::v2::products::{CpeMatchParameters, CpeParameters};
3-
use crate::v2::vulnerabilities::CveParameters;
3+
use crate::v2::vulnerabilities::{CveHistoryParameters, CveParameters};
44
use crate::{Error, NVDApi};
55

66
impl NVDApi {
7-
pub async fn cve(&self, query: CveParameters) -> Result<Object, Error> {
7+
pub async fn cve(&self, query: CveParameters) -> Result<ListResponse, Error> {
88
let u = format!("{}/{}/{}", self.base_path, "cves", self.version);
99
self.request(self.client.get(u).query(&query)).await
1010
}
11-
pub async fn cve_history(&self, query: CveParameters) -> Result<Object, Error> {
11+
pub async fn cve_history(&self, query: CveHistoryParameters) -> Result<ListResponse, Error> {
1212
let u = format!("{}/{}/{}", self.base_path, "cvehistory", self.version);
1313
self.request(self.client.get(u).query(&query)).await
1414
}
15-
pub async fn cpe(&self, query: CpeParameters) -> Result<Object, Error> {
15+
pub async fn cpe(&self, query: CpeParameters) -> Result<ListResponse, Error> {
1616
let u = format!("{}/{}/{}", self.base_path, "cpes", self.version);
1717
self.request(self.client.get(u).query(&query)).await
1818
}
19-
pub async fn cpe_match(&self, query: CpeMatchParameters) -> Result<Object, Error> {
19+
pub async fn cpe_match(&self, query: CpeMatchParameters) -> Result<ListResponse, Error> {
2020
let u = format!("{}/{}/{}", self.base_path, "cpematch", self.version);
2121
self.request(self.client.get(u).query(&query)).await
2222
}

nvd-api/src/v2/products.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub struct Titles {
6060
#[serde(rename_all = "camelCase")]
6161
pub struct Refs {
6262
pub r#ref: String,
63+
#[serde(default)]
6364
pub r#type: RefType,
6465
}
6566
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
@@ -72,6 +73,13 @@ pub enum RefType {
7273
Vendor,
7374
Version,
7475
}
76+
77+
impl Default for RefType {
78+
fn default() -> Self {
79+
Self::ChangeLog
80+
}
81+
}
82+
7583
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq)]
7684
#[serde(rename_all = "camelCase")]
7785
pub struct DeprecatedBy {

0 commit comments

Comments
 (0)