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
40// `BufferedFindingReporter` was the legacy buffer-everything trait. The
41// SARIF reporter now streams results directly to its writer (audit
42// legendary-2026-04-26), so the trait has no callers and is removed. Other
43// reporters that still buffer (text, JSON-array) keep their state inline.