use crate::types::*;
use keyhog_core::{Chunk, MatchLocation, RawMatch};
use std::collections::HashMap;
pub fn build_raw_match(
detector: &keyhog_core::DetectorSpec,
chunk: &Chunk,
credential: &str,
companions: HashMap<String, String>,
offset: usize,
line: usize,
ent: f64,
confidence: f64,
scan_state: &mut ScanState,
) -> RawMatch {
let severity = if chunk.metadata.source_type == "git/history" {
detector.severity.downgrade_one()
} else {
detector.severity
};
RawMatch {
detector_id: scan_state.intern_metadata(&detector.id),
detector_name: scan_state.intern_metadata(&detector.name),
service: scan_state.intern_metadata(&detector.service),
severity,
credential_hash: crate::sha256_hash(credential),
credential: scan_state.intern_credential(credential),
companions,
location: MatchLocation {
source: scan_state.intern_metadata(&chunk.metadata.source_type),
file_path: chunk
.metadata
.path
.as_ref()
.map(|p| scan_state.intern_metadata(p)),
line: Some(line),
offset: offset + chunk.metadata.base_offset,
commit: chunk
.metadata
.commit
.as_ref()
.map(|c| scan_state.intern_metadata(c)),
author: chunk
.metadata
.author
.as_ref()
.map(|a| scan_state.intern_metadata(a)),
date: chunk
.metadata
.date
.as_ref()
.map(|d| scan_state.intern_metadata(d)),
},
entropy: Some(ent),
confidence: Some(confidence),
}
}