csaf_walker/verification/check/
mod.rs1use crate::verification::check::{
2 base::{check_csaf_base, check_csaf_document_tracking_revision_history},
3 informational_advisory::check_vulnerabilities_not_exits,
4 security_incident_response::{check_csaf_document_notes, check_csaf_document_references},
5 vex::{
6 check_all_products_v11ies_exits_in_product_tree,
7 check_branches_relationships_product_match, check_csaf_vex, check_history,
8 check_vulnerabilities_cve_ids, check_vulnerabilities_product_status,
9 check_vulnerabilities_size,
10 },
11};
12use async_trait::async_trait;
13use csaf::Csaf;
14use std::borrow::Cow;
15
16pub mod base;
17pub mod informational_advisory;
18pub mod security_advisory;
19pub mod security_incident_response;
20pub mod vex;
21
22#[cfg(feature = "csaf-validator-lib")]
23pub mod csaf_validator_lib;
24
25pub type CheckError = Cow<'static, str>;
26
27#[async_trait(?Send)]
28pub trait Check {
29 async fn check(&self, csaf: &Csaf) -> anyhow::Result<Vec<CheckError>>;
31}
32
33#[async_trait(?Send)]
35impl<F> Check for F
36where
37 F: Fn(&Csaf) -> Vec<CheckError>,
38{
39 async fn check(&self, csaf: &Csaf) -> anyhow::Result<Vec<CheckError>> {
40 Ok((self)(csaf))
41 }
42}
43
44#[derive(Debug, Default)]
45pub struct Checking {
46 results: Vec<CheckError>,
47}
48
49impl Checking {
50 pub fn new() -> Self {
51 Default::default()
52 }
53
54 pub fn require(mut self, msg: impl Into<CheckError>, ok: bool) -> Self {
55 if !ok {
56 self.results.push(msg.into());
57 }
58 self
59 }
60
61 pub fn done(self) -> Vec<CheckError> {
62 self.results
63 }
64}
65
66pub fn init_verifying_visitor() -> Vec<(&'static str, Box<dyn Check>)> {
67 vec![
68 (
69 "check_vulnerabilities_not_exits",
70 Box::new(check_vulnerabilities_not_exits),
71 ),
72 (
73 "check_csaf_document_notes",
74 Box::new(check_csaf_document_notes),
75 ),
76 (
77 "check_csaf_document_references",
78 Box::new(check_csaf_document_references),
79 ),
80 ("check_csaf_base", Box::new(check_csaf_base)),
81 (
82 "check_csaf_document_tracking_revision_history",
83 Box::new(check_csaf_document_tracking_revision_history),
84 ),
85 (
86 "check_vulnerabilities_size",
87 Box::new(check_vulnerabilities_size),
88 ),
89 (
90 "check_vulnerabilities_product_status",
91 Box::new(check_vulnerabilities_product_status),
92 ),
93 (
94 "check_vulnerabilities_cve_ids",
95 Box::new(check_vulnerabilities_cve_ids),
96 ),
97 (
98 "check_all_products_v11ies_exits_in_product_tree",
99 Box::new(check_all_products_v11ies_exits_in_product_tree),
100 ),
101 ("check_history", Box::new(check_history)),
102 ("check_csaf_vex", Box::new(check_csaf_vex)),
103 (
104 "check_branches_relationships_product_match",
105 Box::new(check_branches_relationships_product_match),
106 ),
107 ]
108}