Skip to content

Commit 494e32f

Browse files
addressing clippy concerns
1 parent 3f100a7 commit 494e32f

File tree

5 files changed

+26
-36
lines changed

5 files changed

+26
-36
lines changed

src/bin/berkshire_hog_lambda.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use s3::credentials::Credentials;
2525
use s3::region::Region;
2626
use serde_derive::{Deserialize, Serialize};
2727
use simple_error::SimpleError;
28-
use simple_logger;
2928
use std::env;
3029
use std::error::Error;
3130
use std::time::SystemTime;

src/bin/duroc_hog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn flat_dir_scan<C>(fspath: &Path, output_file: &Path, mut closure: C) where C:
171171
.filter(|e| e.file_type().unwrap().is_file())
172172
.map(|e| e.path())
173173
.inspect(|e| debug!("clean path: {:?}, output_file: {:?}", &e.clean(), output_file))
174-
.filter(|e| &e.clean() != output_file)
174+
.filter(|e| e.clean() != output_file)
175175
.collect();
176176
debug!("dir_contents: {:?}", dir_contents);
177177

src/bin/essex_hog.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,18 @@ fn get_page(client: &Client, auth_headers: &Headers, base_url: &str, page_id: &s
177177
let json_results = get_json(&client, &auth_headers, &comments_full_url);
178178
let comments = json_results.get("results").unwrap();
179179
let mut all_comments: String = String::new();
180-
match comments {
181-
Value::Array(comments) => {
182-
for comment in comments {
183-
let comment_body = comment.get("body").unwrap().get("storage").unwrap().get("value").unwrap().as_str().unwrap();
184-
all_comments.push_str(comment_body);
185-
}
186-
},
187-
_ => ()
180+
if let Value::Array(comments) = comments {
181+
for comment in comments {
182+
let comment_body = comment.get("body").unwrap().get("storage").unwrap().get("value").unwrap().as_str().unwrap();
183+
all_comments.push_str(comment_body);
184+
}
188185
};
189186

190-
return ConfluencePage {
191-
web_link: String::from(web_link),
187+
ConfluencePage {
188+
web_link,
192189
body: String::from(body),
193190
comments: all_comments
194-
};
191+
}
195192
}
196193

197194
/// Uses a hyper::client object to perform a GET on the full_url and return parsed serde JSON data
@@ -233,7 +230,7 @@ fn get_findings(secret_scanner: &SecretScanner, issue_id: &str, content: &[u8],
233230
secrets.push(ConfluenceFinding {
234231
strings_found: Vec::from_iter(secrets_for_reason.iter().cloned()),
235232
page_id: String::from(issue_id),
236-
reason: String::from(reason),
233+
reason,
237234
url: String::from(web_link)
238235
});
239236
}

src/bin/gottingen_hog.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
154154
Some(e) => e.as_bytes(),
155155
None => {
156156
info!("The JIRA ticket description was set to null!");
157-
"".as_bytes()
157+
b""
158158
}
159159
}
160160
None => {
161161
info!("The JIRA ticket description was not present!");
162-
"".as_bytes()
162+
b""
163163
}
164164
};
165165

@@ -245,7 +245,7 @@ fn get_findings(secret_scanner: &SecretScanner, base_url: &str, issue_id: &str,
245245
secrets.push(JiraFinding {
246246
strings_found: Vec::from_iter(secrets_for_reason.iter().cloned()),
247247
issue_id: String::from(issue_id),
248-
reason: String::from(reason),
248+
reason,
249249
url: web_link.clone(),
250250
location: location.clone(),
251251
});

src/lib.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ pub mod google_scanning;
7272
#[macro_use]
7373
extern crate clap;
7474

75-
use base64;
7675
use clap::ArgMatches;
77-
use hex;
7876
use log::{self, error, info, debug};
7977
use regex::bytes::{Matches, Regex, RegexBuilder, Match};
8078
use serde::Serialize;
@@ -85,7 +83,7 @@ use simple_logger::init_with_level;
8583
use std::collections::{BTreeMap, HashMap, HashSet};
8684
use std::fs::File;
8785
use std::hash::{Hash, Hasher};
88-
use std::io::{BufReader, Read};
86+
use std::io::{BufReader};
8987
use std::iter::FromIterator;
9088
use std::{fmt, fs, str};
9189
use 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

Comments
 (0)