Skip to content

Commit cf5d3f5

Browse files
committed
Fix CI errors: formatting, unused mut, clippy warnings
1 parent 02d8abd commit cf5d3f5

File tree

4 files changed

+43
-44
lines changed

4 files changed

+43
-44
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tokio = { version = "1.35", features = ["full"] }
1414
futures = "0.3"
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = "1.0"
17-
chrono = "0.4"
17+
chrono = { version = "0.4", features = ["serde"] }
1818
thiserror = "1.0"
1919
regex = "1.10"
2020

examples/scan_network.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ async fn main() {
8484
timeout_ms: 500, // Faster timeout
8585
concurrent_scans: 200, // More concurrent scans
8686
detect_services: true,
87+
grab_banners: true,
8788
};
8889

8990
let fast_scanner = NetworkScanner::with_config(custom_config);
@@ -127,17 +128,15 @@ async fn main() {
127128
println!("\n5. Exporting Results as JSON");
128129

129130
match scanner.scan_common_ports(ip).await {
130-
Ok(result) => {
131-
match result.to_json() {
132-
Ok(json) => {
133-
println!(" JSON export successful:");
134-
println!("{}", json);
135-
}
136-
Err(e) => {
137-
eprintln!(" JSON export error: {}", e);
138-
}
131+
Ok(result) => match result.to_json() {
132+
Ok(json) => {
133+
println!(" JSON export successful:");
134+
println!("{}", json);
139135
}
140-
}
136+
Err(e) => {
137+
eprintln!(" JSON export error: {}", e);
138+
}
139+
},
141140
Err(e) => {
142141
eprintln!(" Scan error: {}", e);
143142
}

src/lib.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ impl ScanResult {
122122
pub fn get_high_risk_ports(&self) -> Vec<&PortScanResult> {
123123
self.open_ports
124124
.iter()
125-
.filter(|p| {
126-
matches!(p.risk_level, PortRiskLevel::Critical | PortRiskLevel::High)
127-
})
125+
.filter(|p| matches!(p.risk_level, PortRiskLevel::Critical | PortRiskLevel::High))
128126
.collect()
129127
}
130128

@@ -267,7 +265,7 @@ impl NetworkScanner {
267265
}
268266

269267
// Process remaining tasks
270-
let mut all_results = join_all(tasks).await;
268+
let all_results = join_all(tasks).await;
271269

272270
let scan_end = Utc::now();
273271

@@ -302,8 +300,8 @@ impl NetworkScanner {
302300
/// Scan common ports (top 20)
303301
pub async fn scan_common_ports(&self, ip: IpAddr) -> Result<ScanResult, ScanError> {
304302
let common_ports = vec![
305-
20, 21, 22, 23, 25, 53, 80, 110, 143, 443, 445, 993, 995, 3306, 3389, 5432, 5900,
306-
8080, 8443, 27017,
303+
20, 21, 22, 23, 25, 53, 80, 110, 143, 443, 445, 993, 995, 3306, 3389, 5432, 5900, 8080,
304+
8443, 27017,
307305
];
308306

309307
let scan_start = Utc::now();
@@ -376,26 +374,20 @@ impl NetworkScanner {
376374
/// Grab service banner from open port
377375
async fn grab_banner(stream: &mut TcpStream, port: u16) -> Result<String, ScanError> {
378376
// Send protocol-specific probes
379-
let probe = match port {
377+
let probe: &[u8] = match port {
380378
80 | 8080 => b"HEAD / HTTP/1.0\r\n\r\n",
381379
21 | 22 | 23 | 25 => b"", // These typically send banner on connect
382-
_ => b"", // Default: just read
380+
_ => b"", // Default: just read
383381
};
384382

385383
if !probe.is_empty() {
386-
let _ = timeout(
387-
Duration::from_millis(500),
388-
stream.write_all(probe),
389-
)
390-
.await;
384+
let _ = timeout(Duration::from_millis(500), stream.write_all(probe)).await;
391385
}
392386

393387
let mut buffer = vec![0u8; 1024];
394388
match timeout(Duration::from_millis(500), stream.read(&mut buffer)).await {
395389
Ok(Ok(n)) if n > 0 => {
396-
let banner = String::from_utf8_lossy(&buffer[..n])
397-
.trim()
398-
.to_string();
390+
let banner = String::from_utf8_lossy(&buffer[..n]).trim().to_string();
399391
if !banner.is_empty() {
400392
Ok(banner)
401393
} else {
@@ -545,17 +537,12 @@ mod tests {
545537

546538
assert!(result.port == 9999);
547539
// Status could be Closed or Filtered depending on system
548-
assert!(
549-
result.status == PortStatus::Closed || result.status == PortStatus::Filtered
550-
);
540+
assert!(result.status == PortStatus::Closed || result.status == PortStatus::Filtered);
551541
}
552542

553543
#[tokio::test]
554544
async fn test_service_detection() {
555-
assert_eq!(
556-
NetworkScanner::detect_service(80),
557-
Some("HTTP".to_string())
558-
);
545+
assert_eq!(NetworkScanner::detect_service(80), Some("HTTP".to_string()));
559546
assert_eq!(
560547
NetworkScanner::detect_service(443),
561548
Some("HTTPS".to_string())
@@ -596,7 +583,10 @@ mod tests {
596583
NetworkScanner::assess_port_risk(23),
597584
PortRiskLevel::Critical
598585
); // Telnet
599-
assert_eq!(NetworkScanner::assess_port_risk(21), PortRiskLevel::Critical); // FTP
586+
assert_eq!(
587+
NetworkScanner::assess_port_risk(21),
588+
PortRiskLevel::Critical
589+
); // FTP
600590

601591
// High risk
602592
assert_eq!(NetworkScanner::assess_port_risk(3389), PortRiskLevel::High); // RDP
@@ -699,7 +689,7 @@ mod tests {
699689
};
700690

701691
let duration = result.scan_duration_secs();
702-
assert!(duration >= 0.1 && duration < 1.0);
692+
assert!((0.1..1.0).contains(&duration));
703693
}
704694

705695
#[tokio::test]

src/service_detection.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ impl ServiceSignatures {
6767
fn extract_ssh_version(banner: &str) -> Option<String> {
6868
if let Some(start) = banner.find("SSH-") {
6969
let version_str = &banner[start..];
70-
if let Some(end) = version_str.find(|c: char| c.is_whitespace() || c == '\r' || c == '\n') {
70+
if let Some(end) =
71+
version_str.find(|c: char| c.is_whitespace() || c == '\r' || c == '\n')
72+
{
7173
return Some(version_str[..end].to_string());
7274
}
7375
}
@@ -183,7 +185,11 @@ impl BannerGrabber {
183185
}
184186

185187
/// Grab banner with HTTP probe
186-
pub async fn grab_http_banner(host: &str, port: u16, timeout_ms: u64) -> Result<String, String> {
188+
pub async fn grab_http_banner(
189+
host: &str,
190+
port: u16,
191+
timeout_ms: u64,
192+
) -> Result<String, String> {
187193
let addr = format!("{}:{}", host, port);
188194
let connect_timeout = Duration::from_millis(timeout_ms);
189195

@@ -200,10 +206,13 @@ impl BannerGrabber {
200206
host
201207
);
202208

203-
timeout(Duration::from_millis(timeout_ms), stream.write_all(request.as_bytes()))
204-
.await
205-
.map_err(|_| "Write timeout".to_string())?
206-
.map_err(|e| format!("Write failed: {}", e))?;
209+
timeout(
210+
Duration::from_millis(timeout_ms),
211+
stream.write_all(request.as_bytes()),
212+
)
213+
.await
214+
.map_err(|_| "Write timeout".to_string())?
215+
.map_err(|e| format!("Write failed: {}", e))?;
207216

208217
// Read response
209218
let mut buffer = vec![0u8; 4096];
@@ -239,8 +248,9 @@ mod tests {
239248

240249
#[test]
241250
fn test_mysql_detection() {
242-
let banner = "5.7.32-0ubuntu0.18.04.1";
243-
let service = ServiceSignatures::detect_from_banner("mysql 5.7.32-0ubuntu0.18.04.1").unwrap();
251+
let _banner = "5.7.32-0ubuntu0.18.04.1";
252+
let service =
253+
ServiceSignatures::detect_from_banner("mysql 5.7.32-0ubuntu0.18.04.1").unwrap();
244254
assert_eq!(service.name, "MySQL");
245255
}
246256

0 commit comments

Comments
 (0)