Skip to content

Commit aa80421

Browse files
clippy fixes
1 parent 0d2137f commit aa80421

File tree

9 files changed

+30
-39
lines changed

9 files changed

+30
-39
lines changed

src/bin/ankamali_hog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
7676
// Initialize some variables
7777
let oauthsecretfile = arg_matches
7878
.value_of("OAUTHSECRETFILE")
79-
.unwrap_or_else(|| "clientsecret.json");
79+
.unwrap_or("clientsecret.json");
8080
let oauthtokenfile = arg_matches
8181
.value_of("OAUTHTOKENFILE")
82-
.unwrap_or_else(|| "temp_token");
82+
.unwrap_or("temp_token");
8383
let file_id = arg_matches.value_of("GDRIVEID").unwrap();
8484
let secret_scanner = SecretScannerBuilder::new().conf_argm(arg_matches).build();
8585
let gdrive_scanner = GDriveScanner::new_from_scanner(secret_scanner);

src/bin/berkshire_hog.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use url::Url;
4141
use rusty_hogs::aws_scanning::{S3Finding, S3Scanner};
4242
use rusty_hogs::{SecretScanner, SecretScannerBuilder};
4343
use std::collections::HashSet;
44-
use std::iter::FromIterator;
4544

4645
/// Main entry function that uses the [clap crate](https://docs.rs/clap/2.33.0/clap/)
4746
fn main() {
@@ -159,7 +158,7 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
159158
}
160159

161160
// Output the results
162-
let findings: HashSet<S3Finding> = HashSet::from_iter(findings.into_iter());
161+
let findings: HashSet<S3Finding> = findings.into_iter().collect();
163162
info!("Found {} secrets", findings.len());
164163
match s3scanner.secret_scanner.output_findings(&findings) {
165164
Ok(_) => Ok(()),

src/bin/berkshire_hog_lambda.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use s3::region::Region;
2626
use serde_derive::{Deserialize, Serialize};
2727
use simple_error::SimpleError;
2828
use std::env;
29-
use std::error::Error;
3029
use std::time::SystemTime;
3130
use simple_logger::SimpleLogger;
3231

@@ -106,10 +105,9 @@ struct Finding {
106105
reason: String,
107106
}
108107

109-
fn main() -> Result<(), Box<dyn Error>> {
108+
fn main() {
110109
SimpleLogger::new().with_level(LevelFilter::Debug).init().unwrap();
111110
lambda!(my_handler);
112-
Ok(())
113111
}
114112

115113
fn my_handler(e: CustomEvent, _c: Context) -> Result<CustomOutput, HandlerError> {

src/bin/duroc_hog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ where
171171
C: FnMut(&Path),
172172
{
173173
for entry in WalkDir::new(fspath).into_iter().filter_map(|e| e.ok()) {
174-
if entry.file_type().is_file() && &PathBuf::from(entry.path()).clean() != output_file {
174+
if entry.file_type().is_file() && PathBuf::from(entry.path()).clean() != output_file {
175175
closure(&entry.path());
176176
}
177177
}
@@ -214,7 +214,7 @@ fn scan_file<R: Read + io::Seek>(
214214
let path_string = String::from(Path::new(path_prefix).join(file_path).to_str().unwrap());
215215
info!("scan_file({:?})", path_string);
216216
let ext: String = match file_path.extension() {
217-
Some(osstr) => String::from(osstr.to_str().unwrap_or_else(|| "")).to_ascii_lowercase(),
217+
Some(osstr) => String::from(osstr.to_str().unwrap_or("")).to_ascii_lowercase(),
218218
None => String::from(""),
219219
};
220220

src/bin/essex_hog.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
//! ARGS:
2323
//! <PAGEID> The ID (e.g. 1234) of the confluence page you want to scan
2424
//! <URL> Base URL of Confluence instance (e.g. https://newrelic.atlassian.net/)
25-
//! From https://docs.atlassian.com/ConfluenceServer/rest/7.11.0/ Structure of the REST URIs section
26-
//! for details on declaring the base url with or without context
27-
//! With context: http://host:port/context/rest/api/resource-name
28-
//! Or without context: http://host:port/rest/api/resource-name
29-
//! Example with context: http://example.com:8080/confluence/rest/api/space/ds
30-
//! Example without context: http://confluence.myhost.com:8095/rest/api/space/ds
25+
//! From https://docs.atlassian.com/ConfluenceServer/rest/7.11.0/ Structure of the REST URIs section
26+
//! for details on declaring the base url with or without context
27+
//! With context: http://host:port/context/rest/api/resource-name
28+
//! Or without context: http://host:port/rest/api/resource-name
29+
//! Example with context: http://example.com:8080/confluence/rest/api/space/ds
30+
//! Example without context: http://confluence.myhost.com:8095/rest/api/space/ds
3131
3232
#[macro_use]
3333
extern crate clap;
@@ -50,7 +50,6 @@ use serde_json::{Map, Value};
5050
use simple_error::SimpleError;
5151
use std::collections::{BTreeMap, HashSet};
5252
use std::io::Read;
53-
use std::iter::FromIterator;
5453
use url::Url;
5554

5655
/// `serde_json` object that represents a single found secret - finding
@@ -112,7 +111,7 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
112111
let authtoken = arg_matches.value_of("BEARERTOKEN");
113112
let base_url_input = arg_matches
114113
.value_of("URL")
115-
.unwrap_or_else(|| "https://confluence.atlassian.com")
114+
.unwrap_or("https://confluence.atlassian.com")
116115
.trim_end_matches('/');
117116
let base_url_as_url = Url::parse(base_url_input).unwrap();
118117
let page_id = arg_matches
@@ -152,7 +151,7 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
152151
let secrets = get_findings(&secret_scanner, page_id, content.as_bytes(), &page.web_link);
153152

154153
// combine and output the results
155-
let findings: HashSet<ConfluenceFinding> = HashSet::from_iter(secrets.into_iter());
154+
let findings: HashSet<ConfluenceFinding> = secrets.into_iter().collect();
156155
info!("Found {} secrets", findings.len());
157156
match secret_scanner.output_findings(&findings) {
158157
Ok(_) => Ok(()),
@@ -273,7 +272,7 @@ fn get_findings(
273272
}
274273
if !secrets_for_reason.is_empty() {
275274
secrets.push(ConfluenceFinding {
276-
strings_found: Vec::from_iter(secrets_for_reason.iter().cloned()),
275+
strings_found: secrets_for_reason.iter().cloned().collect(),
277276
page_id: String::from(issue_id),
278277
reason,
279278
url: String::from(web_link),

src/bin/gottingen_hog.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use serde_json::{Map, Value};
4343
use simple_error::SimpleError;
4444
use std::collections::{BTreeMap, HashSet};
4545
use std::io::Read;
46-
use std::iter::FromIterator;
4746
use url::Url;
4847

4948
/// `serde_json` object that represents a single found secret - finding
@@ -98,7 +97,7 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
9897
let jiraauthtoken = arg_matches.value_of("BEARERTOKEN");
9998
let base_url_input = arg_matches
10099
.value_of("JIRAURL")
101-
.unwrap_or_else(|| "https://jira.atlassian.com/");
100+
.unwrap_or("https://jira.atlassian.com/");
102101
let base_url_as_url = Url::parse(base_url_input).unwrap();
103102
let issue_id = arg_matches
104103
.value_of("JIRAID") // TODO validate the format somehow
@@ -183,7 +182,7 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
183182
}
184183

185184
// combine and output the results
186-
let findings: HashSet<JiraFinding> = HashSet::from_iter(secrets.into_iter());
185+
let findings: HashSet<JiraFinding> = secrets.into_iter().collect();
187186
info!("Found {} secrets", findings.len());
188187
match secret_scanner.output_findings(&findings) {
189188
Ok(_) => Ok(()),
@@ -229,6 +228,7 @@ fn get_findings(
229228
let mut secrets: Vec<JiraFinding> = Vec::new();
230229
let web_link = format!("{}browse/{}", base_url, issue_id);
231230
for new_line in lines {
231+
debug!("{:?}", std::str::from_utf8(new_line));
232232
let matches_map: BTreeMap<String, Vec<RustyHogMatch>> =
233233
secret_scanner.matches_entropy(new_line);
234234
for (reason, match_iterator) in matches_map {
@@ -245,7 +245,7 @@ fn get_findings(
245245
}
246246
if !secrets_for_reason.is_empty() {
247247
secrets.push(JiraFinding {
248-
strings_found: Vec::from_iter(secrets_for_reason.iter().cloned()),
248+
strings_found: secrets_for_reason.iter().cloned().collect(),
249249
issue_id: String::from(issue_id),
250250
reason,
251251
url: web_link.clone(),

src/git_scanning.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl GitScanner {
123123
let repo_option = self.repo.as_ref(); //borrowing magic here!
124124
let repo = repo_option.unwrap();
125125
let mut revwalk = repo.revwalk().unwrap();
126-
revwalk.push_glob(glob.unwrap_or_else(|| "*")).unwrap(); //easy mode: iterate over all the commits
126+
revwalk.push_glob(glob.unwrap_or("*")).unwrap(); //easy mode: iterate over all the commits
127127

128128
// take our "--since_commit" input (hash id) and convert it to a date and time
129129
// and build our revwalk with a filter for commits >= that time. This isn't a perfect
@@ -207,8 +207,8 @@ impl GitScanner {
207207
}
208208
let old_file_id = delta.old_file().id();
209209
let new_file_id = delta.new_file().id();
210-
let old_line_num = line.old_lineno().unwrap_or_else(|| 0);
211-
let new_line_num = line.new_lineno().unwrap_or_else(|| 0);
210+
let old_line_num = line.old_lineno().unwrap_or(0);
211+
let new_line_num = line.new_lineno().unwrap_or(0);
212212

213213
for (reason, match_iterator) in matches_map {
214214
let mut secrets: Vec<String> = Vec::new();
@@ -462,7 +462,7 @@ impl fmt::Debug for GitScanner {
462462
Some(repo_obj) => repo_obj
463463
.path()
464464
.to_str()
465-
.unwrap_or_else(|| "<path unwrap error>"),
465+
.unwrap_or("<path unwrap error>"),
466466
};
467467
write!(
468468
f,
@@ -479,7 +479,7 @@ impl fmt::Display for GitScanner {
479479
Some(repo_obj) => repo_obj
480480
.path()
481481
.to_str()
482-
.unwrap_or_else(|| "<path unwrap error>"),
482+
.unwrap_or("<path unwrap error>"),
483483
};
484484
let scheme_string: String = match self.scheme.as_ref() {
485485
None => String::from("None"),

src/google_scanning.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ use serde_derive::{Deserialize, Serialize};
8585
use simple_error::SimpleError;
8686
use std::collections::HashSet;
8787
use std::io::Read;
88-
use std::iter::FromIterator;
8988
use yup_oauth2::{Authenticator, DefaultAuthenticatorDelegate, DiskTokenStorage};
9089

9190
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Default)]
@@ -286,7 +285,7 @@ impl GDriveScanner {
286285
}
287286
}
288287

289-
HashSet::from_iter(findings.into_iter())
288+
findings.into_iter().collect()
290289
}
291290
}
292291

src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ use std::collections::{BTreeMap, HashMap, HashSet};
8585
use std::fs::File;
8686
use std::hash::{Hash, Hasher};
8787
use std::io::BufReader;
88-
use std::iter::FromIterator;
8988
use std::ops::Range;
9089
use std::path::Path;
9190
use std::{fmt, fs, str};
@@ -626,10 +625,7 @@ impl SecretScannerBuilder {
626625
},
627626
None => None,
628627
};
629-
let make_ascii_lowercase_processed = match make_ascii_lowercase {
630-
Some(b) => b,
631-
None => false,
632-
};
628+
let make_ascii_lowercase_processed = make_ascii_lowercase.unwrap_or(false);
633629
(
634630
k,
635631
EntropyRegex {
@@ -743,14 +739,14 @@ impl SecretScanner {
743739

744740
/// Helper function to determine whether a byte array only contains valid Base64 characters.
745741
fn is_base64_string(string_in: &[u8]) -> bool {
746-
let hashset_string_in: HashSet<&u8> = HashSet::from_iter(string_in.iter());
747-
hashset_string_in.is_subset(&HashSet::from_iter(B64_ENCODE.iter()))
742+
let hashset_string_in: HashSet<&u8> = string_in.iter().collect();
743+
hashset_string_in.is_subset(&B64_ENCODE.iter().collect())
748744
}
749745

750746
/// Helper function to determine whether a byte array only contains valid hex characters.
751747
fn is_hex_string(string_in: &[u8]) -> bool {
752-
let hashset_string_in: HashSet<&u8> = HashSet::from_iter(string_in.iter());
753-
hashset_string_in.is_subset(&HashSet::from_iter(HEX_ENCODE.iter()))
748+
let hashset_string_in: HashSet<&u8> = string_in.iter().collect();
749+
hashset_string_in.is_subset(&HEX_ENCODE.iter().collect())
754750
}
755751

756752
/// Compute the Shannon entropy for a byte array (from https://docs.rs/crate/entropy/0.3.0/source/src/lib.rs)

0 commit comments

Comments
 (0)