This commit was merged in pull request #399.
This commit is contained in:
1 parent
fdf22e99c0
commit
33394cc609
13 files changed
+261
-31
No files matched your search
+29
-7
@@ -41,6 +41,11 @@ pub struct ScanBinding {
|
||||
/// Optional specific rule ids this control keys on.
|
||||
#[serde(default)]
|
||||
pub rules: Vec<String>,
|
||||
/// What a finding of this binding means for the control, for the judge.
|
||||
/// The catalog's prose is written for the whole control ("SAST in the
|
||||
/// CI/CD pipeline"); a buffer overflow is judged against this instead.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub check: Option<String>,
|
||||
}
|
||||
|
||||
impl ScanBinding {
|
||||
@@ -128,15 +133,32 @@ impl ControlMap {
|
||||
cwe: Option<&str>,
|
||||
rule_id: Option<&str>,
|
||||
) -> Vec<&ControlEntry> {
|
||||
self.bindings_for_finding(tool, cwe, rule_id)
|
||||
.into_iter()
|
||||
.map(|(control, _)| control)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Like [`Self::controls_for_finding`], with the binding that matched each
|
||||
/// control (for its [`ScanBinding::check`] text).
|
||||
pub fn bindings_for_finding(
|
||||
&self,
|
||||
tool: &str,
|
||||
cwe: Option<&str>,
|
||||
rule_id: Option<&str>,
|
||||
) -> Vec<(&ControlEntry, &ScanBinding)> {
|
||||
self.controls
|
||||
.iter()
|
||||
.filter(|c| {
|
||||
c.scans.iter().any(|s| {
|
||||
s.tool == tool
|
||||
&& (cwe.is_some_and(|w| s.cwe.iter().any(|x| x == w))
|
||||
|| rule_id
|
||||
.is_some_and(|r| s.rules.iter().any(|b| rule_id_matches(b, r))))
|
||||
})
|
||||
.filter_map(|c| {
|
||||
c.scans
|
||||
.iter()
|
||||
.find(|s| {
|
||||
s.tool == tool
|
||||
&& (cwe.is_some_and(|w| s.cwe.iter().any(|x| x == w))
|
||||
|| rule_id
|
||||
.is_some_and(|r| s.rules.iter().any(|b| rule_id_matches(b, r))))
|
||||
})
|
||||
.map(|s| (c, s))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user