Skip to main content

keyhog_core/
report.rs

1//! Reporting logic for scan results.
2
3mod json;
4mod sarif;
5mod text;
6
7pub mod banner;
8
9use std::io::Write;
10
11use crate::VerifiedFinding;
12
13pub use json::{JsonArrayReporter, JsonReporter, JsonlReporter};
14pub use sarif::SarifReporter;
15pub use text::TextReporter;
16
17/// Common error type used by all reporters.
18pub type ReportError = anyhow::Error;
19
20/// Common trait for all finding reporters.
21pub trait Reporter: Send {
22    /// Report a single finding.
23    fn report(&mut self, finding: &VerifiedFinding) -> Result<(), ReportError>;
24
25    /// Finalize the report and flush buffered bytes.
26    fn finish(&mut self) -> Result<(), ReportError>;
27}
28
29trait WriterBackedReporter {
30    type Writer: Write;
31
32    fn writer_mut(&mut self) -> &mut Self::Writer;
33
34    fn flush_writer(&mut self) -> Result<(), ReportError> {
35        self.writer_mut().flush()?;
36        Ok(())
37    }
38}
39
40trait BufferedFindingReporter {
41    fn findings_mut(&mut self) -> &mut Vec<VerifiedFinding>;
42
43    fn push_finding(&mut self, finding: &VerifiedFinding) {
44        self.findings_mut().push(finding.clone());
45    }
46}