CVRF: 处理 documentpublisher

Signed-off-by: Jia Chao <jiac13@chinaunicom.cn>
This commit is contained in:
Jia Chao 2024-06-03 16:59:07 +08:00
parent 1d176558bb
commit a4ea2dd8da
2 changed files with 44 additions and 0 deletions

View File

@ -122,6 +122,7 @@ impl CVRF {
Ok(XmlEvent::StartElement { ref name, .. }) => match name.local_name.as_str() {
"DocumentTitle" => self.documenttitle = xmlreader.next_characters(),
"DocumentType" => self.documenttype = xmlreader.next_characters(),
"DocumentPublisher" => self.handle_publisher(&mut xmlreader),
_ => {}
},
Err(e) => {
@ -134,6 +135,10 @@ impl CVRF {
Ok(())
}
fn handle_publisher(&mut self, xmlreader: &mut XmlReader) {
self.documentpublisher.load_from_xmlreader(xmlreader);
}
}
// depth = 2
@ -157,6 +162,39 @@ impl Publisher {
issuingauthority: String::new(),
}
}
#[instrument(skip(self, xmlreader))]
fn load_from_xmlreader(&mut self, xmlreader: &mut XmlReader) {
let mut key = String::new();
loop {
match xmlreader.next() {
Ok(XmlEvent::StartElement { name, .. }) => {
key = name.local_name.clone();
debug!("Find StartElement named: {}", key);
}
Ok(XmlEvent::EndElement { .. }) => {
// DocumentPublisher 读取完毕
if xmlreader.depth < 2 {
trace!("DocumentPublisher read to end.");
break;
}
}
Err(e) => {
error!("XmlReader Error: {e}");
break;
}
_ => {}
}
match key.as_str() {
"ContactDetails" => self.contactdetails = xmlreader.next_characters(),
"IssuingAuthority" => self.issuingauthority = xmlreader.next_characters(),
_ => {},
}
key.clear();
}
}
}
// depth = 2

View File

@ -9,4 +9,10 @@ fn cvrf_works() {
let d_type = "Security Advisory";
assert_eq!(cvrf.documenttitle, d_title);
assert_eq!(cvrf.documenttype, d_type);
// publisher
let contactdetails = "openeuler-security@openeuler.org";
let issuingauthority = "openEuler security committee";
assert_eq!(cvrf.documentpublisher.contactdetails, contactdetails);
assert_eq!(cvrf.documentpublisher.issuingauthority, issuingauthority);
}