use crate::csaf::traits::vulnerabilities_trait::collect_references;
use crate::csaf_traits::{DocumentTrait, ProductTreeTrait, VulnerabilityTrait};
use crate::schema::csaf2_0::schema::{
CommonSecurityAdvisoryFramework as CommonSecurityAdvisoryFramework20,
DocumentLevelMetaData as DocumentLevelMetaData20, ProductTree as ProductTree20, Vulnerability as Vulnerability20,
};
use crate::schema::csaf2_1::schema::{
CommonSecurityAdvisoryFramework as CommonSecurityAdvisoryFramework21,
DocumentLevelMetaData as DocumentLevelMetaData21, ProductTree as ProductTree21, Vulnerability as Vulnerability21,
};
pub trait CsafTrait {
type VulnerabilityType: VulnerabilityTrait;
type ProductTreeType: ProductTreeTrait;
type DocumentType: DocumentTrait;
fn get_product_tree(&self) -> Option<&Self::ProductTreeType>;
fn get_vulnerabilities(&self) -> &Vec<Self::VulnerabilityType>;
fn get_document(&self) -> &Self::DocumentType;
fn get_all_group_references(&self) -> Vec<(String, String)> {
let mut ids = self.get_document().get_all_group_references();
ids.extend(collect_references(self.get_vulnerabilities(), |v| {
v.get_all_group_references()
}));
ids
}
fn get_all_product_references(&self) -> Vec<(String, String)> {
let mut ids = self.get_document().get_all_product_references();
ids.extend(collect_references(self.get_vulnerabilities(), |v| {
v.get_all_product_references()
}));
if let Some(pt) = self.get_product_tree() {
ids.extend(pt.get_all_product_references());
}
ids
}
fn get_all_product_references_ids(&self) -> Vec<String> {
self.get_all_product_references()
.iter()
.map(|(id, _)| id.to_owned())
.collect()
}
}
impl CsafTrait for CommonSecurityAdvisoryFramework20 {
type VulnerabilityType = Vulnerability20;
type ProductTreeType = ProductTree20;
type DocumentType = DocumentLevelMetaData20;
fn get_product_tree(&self) -> Option<&Self::ProductTreeType> {
self.product_tree.as_ref()
}
fn get_vulnerabilities(&self) -> &Vec<Self::VulnerabilityType> {
&self.vulnerabilities
}
fn get_document(&self) -> &Self::DocumentType {
&self.document
}
}
impl CsafTrait for CommonSecurityAdvisoryFramework21 {
type VulnerabilityType = Vulnerability21;
type ProductTreeType = ProductTree21;
type DocumentType = DocumentLevelMetaData21;
fn get_product_tree(&self) -> Option<&Self::ProductTreeType> {
self.product_tree.as_ref()
}
fn get_vulnerabilities(&self) -> &Vec<Self::VulnerabilityType> {
&self.vulnerabilities
}
fn get_document(&self) -> &Self::DocumentType {
&self.document
}
}