Skip to content

Commit

Permalink
Apply various clippy fixes (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Isona authored Dec 27, 2023
1 parent 8ac454f commit ed0fb75
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 102 deletions.
39 changes: 9 additions & 30 deletions src/arg_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl fmt::Debug for LengthRange {
}
}

#[derive(Clone)]
#[derive(Clone, Default)]
pub struct LengthRanges {
pub ranges: Vec<LengthRange>,
}
Expand All @@ -109,12 +109,6 @@ impl LengthRanges {
}
}

impl Default for LengthRanges {
fn default() -> Self {
Self { ranges: Vec::new() }
}
}

impl fmt::Display for LengthRanges {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut ranges = self.ranges.clone();
Expand Down Expand Up @@ -734,23 +728,11 @@ set to 0 to disable")
0
},
max_recursion_depth,
user_agent: if let Some(user_agent) = args.value_of("user_agent") {
Some(String::from(user_agent))
} else {
None
},
user_agent: args.value_of("user_agent").map(String::from),
// Dependency between username and password is handled by Clap
username: if let Some(username) = args.value_of("username") {
Some(String::from(username))
} else {
None
},
username: args.value_of("username").map(String::from),
// Dependency between username and password is handled by Clap
password: if let Some(password) = args.value_of("password") {
Some(String::from(password))
} else {
None
},
password: args.value_of("password").map(String::from),
output_file: filename_from_args(&args, FileTypes::Txt),
json_file: filename_from_args(&args, FileTypes::Json),
xml_file: filename_from_args(&args, FileTypes::Xml),
Expand Down Expand Up @@ -824,11 +806,8 @@ fn filename_from_args(
}
}

if let Some(output_all_prefix) = args.value_of("output_all") {
Some(format!("{}.{}", output_all_prefix, extension))
} else {
None
}
args.value_of("output_all")
.map(|output_all_prefix| format!("{}.{}", output_all_prefix, extension))
}

#[inline]
Expand Down Expand Up @@ -884,16 +863,16 @@ pub fn get_version_string() -> &'static str {
if cfg!(feature = "release_version_string")
|| env!("VERGEN_SHA_SHORT") == "UNKNOWN"
{
return crate_version!();
crate_version!()
} else {
return concat!(
concat!(
crate_version!(),
" (commit ",
env!("VERGEN_SHA_SHORT"),
", build ",
env!("VERGEN_BUILD_DATE"),
")"
);
)
}
}

Expand Down
60 changes: 29 additions & 31 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,45 +237,43 @@ fn main() {

// Ignore any errors - this happens if the message queue is
// empty, that's okay
if let Ok(dir_info_opt) = to_scan {
if let Some(dir_info) = dir_info_opt {
// If a thread has sent end, then we can reduce the
// threads in use count
if dir_info.url.as_str() == "data:END" {
threads_in_use -= 1;
}
// Check the validator to see if the directory should
// be scanned
else {
match &dir_info.validator {
Some(validator) => {
if validator.scan_folder(&global_opts.scan_opts) {
add_dir_to_scan_queue(
&mut scan_queue,
&global_opts,
&dir_info,
&wordlist,
false,
);
} else {
info!(
"Skipping {}{}",
dir_info.url,
&validator.print_alert()
)
}
}
// If there is no validator, then scan the folder
None => {
if let Ok(Some(dir_info)) = to_scan {
// If a thread has sent end, then we can reduce the
// threads in use count
if dir_info.url.as_str() == "data:END" {
threads_in_use -= 1;
}
// Check the validator to see if the directory should
// be scanned
else {
match &dir_info.validator {
Some(validator) => {
if validator.scan_folder(&global_opts.scan_opts) {
add_dir_to_scan_queue(
&mut scan_queue,
&global_opts,
&dir_info,
&wordlist,
false,
);
} else {
info!(
"Skipping {}{}",
dir_info.url,
&validator.print_alert()
)
}
}
// If there is no validator, then scan the folder
None => {
add_dir_to_scan_queue(
&mut scan_queue,
&global_opts,
&dir_info,
&wordlist,
false,
);
}
}
}
};
Expand Down Expand Up @@ -333,7 +331,7 @@ fn add_dir_to_scan_queue(
// improve performance of the initial discovery phase.
let num_hosts = global_opts.hostnames.len() as u32;
let wordlist_split;
if first_run
if first_run
&& global_opts.max_threads >= 3
&& (global_opts.wordlist_split * num_hosts)
< (global_opts.max_threads - 2)
Expand Down
47 changes: 24 additions & 23 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ pub fn print_response(

let mut output = String::new();
output += &output_format::output_indentation(
&response,
response,
print_newlines,
indentation,
);

output += &output_format::output_letter(&response);
output += &output_format::output_letter(response);

output += &output_format::output_url(&response);
output += &output_format::output_url(response);

output += &output_format::output_suffix(&response, colour);
output += &output_format::output_suffix(response, colour);

Some(output)
}
Expand All @@ -68,9 +68,9 @@ pub fn print_report(
global_opts: Arc<GlobalOpts>,
file_handles: FileHandles,
) {
for mut response_list in &mut responses {
for response_list in &mut responses {
//*response_list =
sort_responses(&mut response_list);
sort_responses(response_list);
}

// If stdout is a terminal then write a report to it
Expand All @@ -82,7 +82,7 @@ pub fn print_report(
);
for response in response_list {
if let Some(line) = print_response(
&response,
response,
global_opts.clone(),
true,
true,
Expand All @@ -104,7 +104,7 @@ pub fn print_report(
write_file(&mut handle, report_string);
for response in response_list {
if let Some(line) = print_response(
&response,
response,
global_opts.clone(),
true,
false,
Expand Down Expand Up @@ -170,10 +170,10 @@ fn write_file(file_writer: &mut LineWriter<File>, line: String) {

// Sorts responses so that files in a directory come first, followed by
// the subdirs
pub fn sort_responses(responses: &mut Vec<RequestResponse>) {
pub fn sort_responses(responses: &mut [RequestResponse]) {
responses.sort_by(|a, b| {
directory_name(&a)
.cmp(&directory_name(&b))
directory_name(a)
.cmp(&directory_name(b))
.then(a.url.cmp(&b.url))
});
}
Expand Down Expand Up @@ -223,7 +223,7 @@ pub fn create_files(global_opts: Arc<GlobalOpts>) -> FileHandles {
#[inline]
fn generate_handle(filename: &str) -> Option<LineWriter<File>> {
let path = Path::new(&filename);
match File::create(&path) {
match File::create(path) {
Err(why) => panic!("couldn't create {}: {}", path.display(), why),
Ok(file) => Some(LineWriter::new(file)),
}
Expand Down Expand Up @@ -259,19 +259,20 @@ pub fn startup_text(
format!("{}Wordlist: {}\n", text, wordlist_file)
};

let text =
if global_opts.prefixes.len() == 1 && global_opts.prefixes[0] == "" {
format!("{}No Prefixes\n", text)
} else {
format!(
"{}Prefixes: {}\n",
text,
global_opts.prefixes.clone()[1..].join(" ")
)
};
let text = if global_opts.prefixes.len() == 1
&& global_opts.prefixes[0].is_empty()
{
format!("{}No Prefixes\n", text)
} else {
format!(
"{}Prefixes: {}\n",
text,
global_opts.prefixes.clone()[1..].join(" ")
)
};

let text = if global_opts.extensions.len() == 1
&& global_opts.extensions[0] == ""
&& global_opts.extensions[0].is_empty()
{
format!("{}No Extensions\n", text)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/output_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn output_suffix(response: &RequestResponse, color: bool) -> String {

#[inline]
pub fn output_xml(response: &RequestResponse) -> String {
format!("{}\n", XMLElement::from(response).to_string())
format!("{}\n", XMLElement::from(response))
}

#[inline]
Expand Down
13 changes: 5 additions & 8 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,14 @@ impl RequestResponse {
// This function takes an instance of "Easy2", a base URL and a suffix
// It then makes the request, if the response was not a 404
// then it will return a RequestResponse struct
pub fn make_request(
mut easy: &mut Easy2<Collector>,
url: Url,
) -> RequestResponse {
pub fn make_request(easy: &mut Easy2<Collector>, url: Url) -> RequestResponse {
trace!("Requesting {}", url);
// Set the url in the Easy2 instance
easy.url(&url.as_str()).unwrap();
easy.url(url.as_str()).unwrap();

// Perform the request and check if it's empty
// If it's empty then return a RequestResponse struct
match perform(&mut easy) {
match perform(easy) {
Ok(_v) => {}
Err(e) => {
println!("Curl error after requesting {} : {}", url, e);
Expand Down Expand Up @@ -195,7 +192,7 @@ pub fn listable_check(
dir_url += "/";
}
let mut response =
make_request(easy, Url::parse(&dir_url.as_str()).unwrap());
make_request(easy, Url::parse(dir_url.as_str()).unwrap());
let content = get_content(easy).to_lowercase();
let mut output_list: Vec<RequestResponse> = Vec::new();

Expand Down Expand Up @@ -262,7 +259,7 @@ pub fn listable_check(
depth -= 1;
}

depth -= parent_depth as i32;
depth -= parent_depth;

// If we've exceeded the max depth, add the url to the
// values to be returned
Expand Down
4 changes: 2 additions & 2 deletions src/request_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn send_response(
output_tx.send(response).unwrap();
return;
}
if should_send_response(&global_opts, &response, &validator_opt) {
if should_send_response(global_opts, &response, validator_opt) {
output_tx.send(response).unwrap();
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ pub fn should_send_response(
return false;
}
if let Some(validator) = validator_opt {
if validator.is_not_found(&response) {
if validator.is_not_found(response) {
trace!("[{}]: matches Not Found condition", response.url);
return false;
}
Expand Down
13 changes: 6 additions & 7 deletions src/validator_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl TargetValidator {
// This branch should never happen because this function should
// only be used if scan_folder returned false
else {
format!("")
String::new()
}
}
}
Expand All @@ -180,22 +180,21 @@ pub enum ValidatorAlert {
impl fmt::Display for ValidatorAlert {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ValidatorAlert::Code401 =>{
ValidatorAlert::Code401 => {
write!(f,
"\n Scanning of directories returning 401 is disabled.\n \
Use the --scan-401 flag to scan this directory,\n \
or provide a valid session token or credentials.")
},
}
ValidatorAlert::Code403 => {
write!(f,
"\n Scanning of directories returning 403 is disabled.\n \
Use the --scan-403 flag to scan this directory,\n \
or provide valid session token or credentials.")
},
}
// Placeholder branch
ValidatorAlert::RedirectToHTTPS => {
write!(f,
"The directory redirected to HTTPS")
write!(f, "The directory redirected to HTTPS")
}
}
}
Expand Down Expand Up @@ -385,7 +384,7 @@ fn determine_not_found(
}

let mut diff_response_size = None;
if response_size == None {
if response_size.is_none() {
let diff_0 = ((responses[0].content_len as i32)
- responses[0].url.as_str().len() as i32)
.abs();
Expand Down

0 comments on commit ed0fb75

Please sign in to comment.