CVRF: 处理 documentreferences
Signed-off-by: Jia Chao <jiac13@chinaunicom.cn>
This commit is contained in:
parent
d0f9a3f288
commit
b70a48ce3c
36
src/lib.rs
36
src/lib.rs
|
@ -161,6 +161,7 @@ impl CVRF {
|
||||||
"DocumentPublisher" => self.documentpublisher.load_from_xmlreader(xmlreader),
|
"DocumentPublisher" => self.documentpublisher.load_from_xmlreader(xmlreader),
|
||||||
"DocumentTracking" => self.documenttracking.load_from_xmlreader(xmlreader),
|
"DocumentTracking" => self.documenttracking.load_from_xmlreader(xmlreader),
|
||||||
"DocumentNotes" => self.handle_notes(xmlreader),
|
"DocumentNotes" => self.handle_notes(xmlreader),
|
||||||
|
"DocumentReferences" => self.handle_references(xmlreader),
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -185,6 +186,18 @@ impl CVRF {
|
||||||
self.documentnotes.push(note);
|
self.documentnotes.push(note);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_references(&mut self, xmlreader: &mut XmlReader) {
|
||||||
|
loop {
|
||||||
|
let mut reference = Reference::new();
|
||||||
|
reference.load_from_xmlreader(xmlreader);
|
||||||
|
|
||||||
|
if xmlreader.depth < 2 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
self.documentreferences.push(reference);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// depth = 2
|
// depth = 2
|
||||||
|
@ -506,6 +519,29 @@ impl Reference {
|
||||||
url: String::new(),
|
url: String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(self, xmlreader))]
|
||||||
|
fn load_from_xmlreader(&mut self, xmlreader: &mut XmlReader) {
|
||||||
|
loop {
|
||||||
|
match xmlreader.next() {
|
||||||
|
Ok(XmlEvent::StartElement { attributes, .. }) => {
|
||||||
|
self.r#type = attributes[0].value.clone();
|
||||||
|
self.url = xmlreader.next_characters();
|
||||||
|
}
|
||||||
|
Ok(XmlEvent::EndElement { .. }) => {
|
||||||
|
if xmlreader.depth < 3 {
|
||||||
|
trace!("Reference read end.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("XmlReader Error: {e}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// depth = 2
|
// depth = 2
|
||||||
|
|
|
@ -48,4 +48,11 @@ fn cvrf_works() {
|
||||||
assert_eq!(cvrf.documentnotes[0].r#type, note_type);
|
assert_eq!(cvrf.documentnotes[0].r#type, note_type);
|
||||||
assert_eq!(cvrf.documentnotes[0].ordinal, note_ordinal);
|
assert_eq!(cvrf.documentnotes[0].ordinal, note_ordinal);
|
||||||
assert_eq!(cvrf.documentnotes[1].content, note_content);
|
assert_eq!(cvrf.documentnotes[1].content, note_content);
|
||||||
|
|
||||||
|
// references
|
||||||
|
let reference_type = "openEuler CVE";
|
||||||
|
let reference_url = "https://www.openeuler.org/en/security/cve/detail.html?id=CVE-2023-45288";
|
||||||
|
assert_eq!(cvrf.documentreferences.len(), 3);
|
||||||
|
assert_eq!(cvrf.documentreferences[1].r#type, reference_type);
|
||||||
|
assert_eq!(cvrf.documentreferences[1].r#url, reference_url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user