From 6b1cda23258bfdb4494d7ec0d0c84ae0319422b1 Mon Sep 17 00:00:00 2001 From: Will Greenberg Date: Fri, 24 Jul 2026 13:36:18 -0700 Subject: [PATCH] appease clippy/fmt --- check/src/json.rs | 31 ++++++++++++++++++++++++------- check/src/main.rs | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/check/src/json.rs b/check/src/json.rs index d0968ad..5caf64d 100644 --- a/check/src/json.rs +++ b/check/src/json.rs @@ -1,5 +1,5 @@ use rayhunter::analysis::analyzer::ReportMetadata; -use tokio::{io::{AsyncWrite, AsyncWriteExt, BufWriter}}; +use tokio::io::{AsyncWrite, AsyncWriteExt, BufWriter}; use crate::Report; @@ -9,11 +9,18 @@ pub struct IncrementalJsonWriter { } impl IncrementalJsonWriter { - pub async fn new(file: T, check_path: &str, metadata: &ReportMetadata) -> std::io::Result { + pub async fn new( + file: T, + check_path: &str, + metadata: &ReportMetadata, + ) -> std::io::Result { let mut writer = BufWriter::new(file); let path_str = serde_json::to_string(check_path)?; let metadata_str = serde_json::to_string(metadata)?; - let s = format!(r#"{{ "path": {}, "metadata": {}, "reports": ["#, path_str, metadata_str); + let s = format!( + r#"{{ "path": {}, "metadata": {}, "reports": ["#, + path_str, metadata_str + ); writer.write_all(s.as_bytes()).await?; Ok(Self { writer, @@ -23,7 +30,7 @@ impl IncrementalJsonWriter { pub async fn write_report(&mut self, report: &Report) -> std::io::Result<()> { if self.reports_written > 0 { - self.writer.write_u8(',' as u8).await?; + self.writer.write_u8(b',').await?; } let report_str = serde_json::to_string(report)?; self.writer.write_all(report_str.as_bytes()).await?; @@ -40,7 +47,9 @@ impl IncrementalJsonWriter { #[cfg(test)] mod test { - use rayhunter::analysis::analyzer::{AnalyzerConfig, Event, EventType, Harness, ReportMetadata}; + use rayhunter::analysis::analyzer::{ + AnalyzerConfig, Event, EventType, Harness, ReportMetadata, + }; use serde::Deserialize; use tokio::io::{AsyncReadExt, DuplexStream, duplex}; @@ -58,7 +67,10 @@ mod test { report.skipped = 13; report.warnings = 12; report.events.push(EventWithTimestamp { - event: Event { event_type: EventType::High, message: "hi".into() }, + event: Event { + event_type: EventType::High, + message: "hi".into(), + }, timestamp: chrono::DateTime::default(), }); report @@ -67,7 +79,12 @@ mod test { async fn create_test_writer(path: &str) -> (IncrementalJsonWriter, DuplexStream) { let (writer, reader) = duplex(1_000_000); let harness = Harness::new_with_config(&AnalyzerConfig::default()); - (IncrementalJsonWriter::new(writer, path, &harness.get_metadata()).await.unwrap(), reader) + ( + IncrementalJsonWriter::new(writer, path, &harness.get_metadata()) + .await + .unwrap(), + reader, + ) } async fn parse_json(mut reader: DuplexStream) -> ExpectedJsonLayout { diff --git a/check/src/main.rs b/check/src/main.rs index 09277d5..d4f49a9 100644 --- a/check/src/main.rs +++ b/check/src/main.rs @@ -3,7 +3,10 @@ use clap::Parser; use log::{debug, error, info, warn}; use pcap_file_tokio::pcapng::{Block, PcapNgReader}; use rayhunter::{ - analysis::analyzer::{AnalysisRow, AnalyzerConfig, Event, EventType, Harness}, gsmtap::parser as gsmtap_parser, pcap::GsmtapPcapWriter, qmdl::QmdlMessageReader, + analysis::analyzer::{AnalysisRow, AnalyzerConfig, Event, EventType, Harness}, + gsmtap::parser as gsmtap_parser, + pcap::GsmtapPcapWriter, + qmdl::QmdlMessageReader, }; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, path::PathBuf}; @@ -102,7 +105,11 @@ impl Report { } } -async fn analyze_pcap(pcap_path: &str, show_skipped: bool, json_writer: Option<&mut IncrementalJsonWriter>) { +async fn analyze_pcap( + pcap_path: &str, + show_skipped: bool, + json_writer: Option<&mut IncrementalJsonWriter>, +) { let mut harness = Harness::new_with_config(&AnalyzerConfig::default()); let pcap_file = &mut File::open(&pcap_path).await.expect("failed to open file"); let mut pcap_reader = PcapNgReader::new(pcap_file) @@ -121,11 +128,18 @@ async fn analyze_pcap(pcap_path: &str, show_skipped: bool, json_writer: Option<& } report.print_summary(show_skipped); if let Some(writer) = json_writer { - writer.write_report(&report).await.expect("failed to write report to JSON"); + writer + .write_report(&report) + .await + .expect("failed to write report to JSON"); } } -async fn analyze_qmdl(qmdl_path: &str, show_skipped: bool, json_writer: Option<&mut IncrementalJsonWriter>) { +async fn analyze_qmdl( + qmdl_path: &str, + show_skipped: bool, + json_writer: Option<&mut IncrementalJsonWriter>, +) { let mut harness = Harness::new_with_config(&AnalyzerConfig::default()); let qmdl_file = &mut File::open(&qmdl_path).await.expect("failed to open file"); let mut qmdl_reader = QmdlMessageReader::new(qmdl_file) @@ -141,7 +155,10 @@ async fn analyze_qmdl(qmdl_path: &str, show_skipped: bool, json_writer: Option<& } report.print_summary(show_skipped); if let Some(writer) = json_writer { - writer.write_report(&report).await.expect("failed to write report to JSON"); + writer + .write_report(&report) + .await + .expect("failed to write report to JSON"); } } @@ -208,9 +225,11 @@ async fn main() { .await .expect("failed to create JSON output file"); let check_path_str = args.path.to_string_lossy(); - json_writer = Some(IncrementalJsonWriter::new(json_file, &check_path_str, &metadata) - .await - .expect("failed to create JSON writer")); + json_writer = Some( + IncrementalJsonWriter::new(json_file, &check_path_str, &metadata) + .await + .expect("failed to create JSON writer"), + ); } for maybe_entry in WalkDir::new(&args.path) { @@ -238,6 +257,9 @@ async fn main() { if let Some(writer) = json_writer { // if we have a json_writer, we also have args.json info!("Writing report to {:?}", args.json.unwrap()); - writer.finish().await.expect("failed to finish writing to JSON file"); + writer + .finish() + .await + .expect("failed to finish writing to JSON file"); } }