@@ -72,9 +72,7 @@ pub mod google_scanning;
7272#[ macro_use]
7373extern crate clap;
7474
75- use base64;
7675use clap:: ArgMatches ;
77- use hex;
7876use log:: { self , error, info, debug} ;
7977use regex:: bytes:: { Matches , Regex , RegexBuilder , Match } ;
8078use serde:: Serialize ;
@@ -85,7 +83,7 @@ use simple_logger::init_with_level;
8583use std:: collections:: { BTreeMap , HashMap , HashSet } ;
8684use std:: fs:: File ;
8785use std:: hash:: { Hash , Hasher } ;
88- use std:: io:: { BufReader , Read } ;
86+ use std:: io:: { BufReader } ;
8987use std:: iter:: FromIterator ;
9088use std:: { fmt, fs, str} ;
9189use std:: path:: Path ;
@@ -329,7 +327,7 @@ impl<'t> RustyHogMatch<'t> {
329327 /// Creates a new match from the given haystack and byte offsets.
330328 #[ inline]
331329 fn new ( haystack : & ' t [ u8 ] , start : usize , end : usize ) -> RustyHogMatch < ' t > {
332- RustyHogMatch { text : haystack, start : start , end : end }
330+ RustyHogMatch { text : haystack, start, end }
333331 }
334332}
335333
@@ -464,7 +462,7 @@ impl SecretScannerBuilder {
464462 let allowlist_map = match & self . allowlist_json_path {
465463 Some ( p) => {
466464 let json_string_result = std:: fs:: read_to_string ( p) ;
467- let mut json_string: String = match json_string_result {
465+ let json_string: String = match json_string_result {
468466 Ok ( s) => s,
469467 Err ( e) => {
470468 error ! ( "Error reading allowlist JSON file, falling back to default allowlist rules: {:?}" , e) ;
@@ -490,7 +488,7 @@ impl SecretScannerBuilder {
490488 regex_map,
491489 pretty_print : self . pretty_print ,
492490 output_path,
493- allowlist_map : allowlist_map ,
491+ allowlist_map,
494492 entropy_min_word_len : self . entropy_min_word_len ,
495493 entropy_max_word_len : self . entropy_max_word_len ,
496494 add_entropy_findings : self . add_entropy_findings ,
@@ -554,7 +552,7 @@ impl SecretScannerBuilder {
554552 regex_builder. case_insensitive ( true ) ;
555553 } ;
556554 ( k, EntropyRegex {
557- pattern : regex_builder. build ( ) . expect ( format ! ( "Error parsing regex string: {:?}" , p) . as_str ( ) ) ,
555+ pattern : regex_builder. build ( ) . unwrap_or_else ( |_| panic ! ( "Error parsing regex string: {:?}" , p) ) ,
558556 entropy_threshold : None ,
559557 keyspace : None ,
560558 make_ascii_lowercase : false
@@ -588,7 +586,7 @@ impl SecretScannerBuilder {
588586 None => false
589587 } ;
590588 ( k, EntropyRegex {
591- pattern : regex_builder. build ( ) . expect ( format ! ( "Error parsing regex string: {:?}" , pattern) . as_str ( ) ) ,
589+ pattern : regex_builder. build ( ) . unwrap_or_else ( |_| panic ! ( "Error parsing regex string: {:?}" , pattern) ) ,
592590 entropy_threshold : entropy,
593591 keyspace : keyspace_processed,
594592 make_ascii_lowercase : make_ascii_lowercase_processed
@@ -664,7 +662,7 @@ impl SecretScanner {
664662 let matches_filtered: Vec < RustyHogMatch > = matches
665663 . filter ( |m| self . check_entropy ( x. 0 , & line[ m. start ( ) ..m. end ( ) ] ) )
666664 . filter ( |m| !self . is_allowlisted ( x. 0 , & line[ m. start ( ) ..m. end ( ) ] ) )
667- . map ( |m| RustyHogMatch :: from ( m ) )
665+ . map ( RustyHogMatch :: from)
668666 . inspect ( |x| debug ! ( "RustyHogMatch: {:?}" , x) )
669667 . collect ( ) ;
670668 ( x. 0 . clone ( ) , matches_filtered)
@@ -704,7 +702,7 @@ impl SecretScanner {
704702 // if make_ascii_lowercase is set to false
705703 if make_ascii_lowercase {
706704 for & b in bytes {
707- let mut c = b. clone ( ) ;
705+ let mut c = b;
708706 c. make_ascii_lowercase ( ) ;
709707 counts. insert ( c, counts. get ( & c) . unwrap_or ( & 0 ) + 1 ) ;
710708 }
@@ -738,9 +736,7 @@ impl SecretScanner {
738736 None => SecretScanner :: guess_keyspace ( bytes)
739737 } ;
740738 let raw_entropy = SecretScanner :: calc_shannon_entropy ( bytes, processed_lowercase) ;
741- let output = raw_entropy / ( ( processed_keyspace as f32 ) . log2 ( ) ) ;
742- // println!("calc_normalized_entropy({:?},{:?},{:?}) -> {:?}", bytes, keyspace, make_ascii_lowercase, output);
743- output
739+ raw_entropy / ( ( processed_keyspace as f32 ) . log2 ( ) )
744740 }
745741
746742 /// Scan a byte array for arbitrary hex sequences and base64 sequences. Will return a list of
@@ -780,7 +776,7 @@ impl SecretScanner {
780776 . map ( hex:: encode)
781777 . collect ( ) ;
782778 //dedup first to prevent some strings from getting detected twice
783- if b64_words. len ( ) > 0 || hex_words. len ( ) > 0 {
779+ if ! b64_words. is_empty ( ) || ! hex_words. is_empty ( ) {
784780 debug ! ( "b64_words: {:?}" , b64_words) ;
785781 debug ! ( "hex_words: {:?}" , hex_words) ;
786782 }
@@ -794,7 +790,7 @@ impl SecretScanner {
794790 let mut output = Vec :: new ( ) ;
795791 for word in output_hashset {
796792 // There should be a better way to do this. This seems expensive
797- let vec_line = String :: from_utf8 ( Vec :: from ( line) ) . unwrap_or ( String :: from ( "" ) ) ;
793+ let vec_line = String :: from_utf8 ( Vec :: from ( line) ) . unwrap_or_else ( |_| String :: from ( "" ) ) ;
798794 let index = vec_line. find ( & word) . unwrap_or ( 0 ) ;
799795 if index > line. len ( ) {
800796 error ! ( "index error" ) ;
@@ -803,7 +799,7 @@ impl SecretScanner {
803799 output. push ( m) ;
804800 }
805801 }
806- if output. len ( ) > 0 {
802+ if ! output. is_empty ( ) {
807803 debug ! ( "entropy_findings output: {:?}" , output) ;
808804 }
809805 output
@@ -860,9 +856,7 @@ impl SecretScanner {
860856 } ,
861857 None => true ,
862858 }
863- } else {
864- if pattern == "Entropy" { true } else { false }
865- }
859+ } else { pattern == "Entropy" }
866860 }
867861
868862 /// Helper function that takes a HashSet of serializable structs and outputs them as JSON
0 commit comments