Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspustina committed Mar 11, 2024
1 parent c498365 commit cf6964c
Show file tree
Hide file tree
Showing 35 changed files with 129 additions and 180 deletions.
4 changes: 2 additions & 2 deletions src/app/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ impl TryFrom<&ArgMatches<'_>> for AppConfig {
system_nameservers: args
.values_of("system nameservers")
.map(|xs| xs.map(ToString::to_string).collect()),
resolvers_mode: args.value_of("resolvers-mode").map(|x| Mode::from_str(x)).unwrap()?, // Safe unwrap, because clap's validation
output_config: output_config(output, &args)?,
resolvers_mode: args.value_of("resolvers-mode").map(Mode::from_str).unwrap()?, // Safe unwrap, because clap's validation
output_config: output_config(output, args)?,
output,
max_worker_threads: args
.value_of("max-worker-threads")
Expand Down
14 changes: 2 additions & 12 deletions src/app/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::services::server_lists::ServerListSpec;
use crate::services::whois;
use crate::statistics::Statistics;

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ConsoleOpts {
quiet: bool,
show_errors: bool,
Expand All @@ -41,16 +41,6 @@ impl ConsoleOpts {
}
}

impl Default for ConsoleOpts {
fn default() -> ConsoleOpts {
ConsoleOpts {
quiet: false,
show_errors: false,
partial_results: false,
}
}
}

impl From<&AppConfig> for ConsoleOpts {
fn from(app_config: &AppConfig) -> Self {
ConsoleOpts {
Expand Down Expand Up @@ -160,7 +150,7 @@ impl Console {
pub fn print_partial_headers(&self, caption: &str, resolvers: &ResolverGroup, query: &MultiQuery) {
if self.show_partial_headers() {
self.caption(caption);
self.print_lookup_estimates(resolvers, &query);
self.print_lookup_estimates(resolvers, query);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/check/lints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Check {
let app_resolver = AppResolver::create_resolvers(app_config).await?;

env.console
.print_resolver_opts(app_resolver.resolver_group_opts(), &app_resolver.resolver_opts());
.print_resolver_opts(app_resolver.resolver_group_opts(), app_resolver.resolver_opts());

Ok(LookupAllThereIs {
env,
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'a> LookupAllThereIs<'a> {

self.env.console.print_partial_headers(
"Running DNS lookups for all available records.",
&self.app_resolver.resolvers(),
self.app_resolver.resolvers(),
&query,
);

Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/check/lints/soa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<'a> Soa<'a> {
.into_iter()
.map(|ip| NameServerConfig::udp((ip, 53)))
.map(ResolverConfig::new);
let resolvers = AppResolver::from_configs(authoritative_name_servers, &self.env.app_config).await?;
let resolvers = AppResolver::from_configs(authoritative_name_servers, self.env.app_config).await?;
let query = MultiQuery::single(self.env.mod_config.domain_name.as_str(), RecordType::SOA)?;

let lookups = intermediate_lookups!(
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/check/lints/spf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<'a> Spf<'a> {
// Check, if Txt records can be parsed into SPF records
let mut parsed_spfs = Vec::new();
for str in spfs {
if let Ok(spf) = parsed_txt::Spf::from_str(&str) {
if let Ok(spf) = parsed_txt::Spf::from_str(str) {
results.push(CheckResult::Ok("Successfully parsed SPF record".to_string()));
parsed_spfs.push(spf)
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/app/modules/discover/discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ impl Discover {

// Showing partial results only makes sense, if the queried domain name is shown for every response,
// because this modules generates domain names, e.g., wildcard resolution, word lists
let partial_output_config = Discover::create_partial_output_config(&env.app_config);
let partial_output_config = Discover::create_partial_output_config(env.app_config);

env.console
.print_resolver_opts(app_resolver.resolver_group_opts(), &app_resolver.resolver_opts());
.print_resolver_opts(app_resolver.resolver_group_opts(), app_resolver.resolver_opts());

Ok(RequestAll {
env,
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<'a> RequestAll<'a> {

self.env
.console
.print_partial_headers("Requesting all record types.", &self.app_resolver.resolvers(), &query);
.print_partial_headers("Requesting all record types.", self.app_resolver.resolvers(), &query);

info!("Requesting all record types.");
let (lookups, run_time) = time(self.app_resolver.lookup(query)).await?;
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<'a> WildcardCheck<'a> {

self.env
.console
.print_partial_headers("Checking wildcard resolution.", &self.app_resolver.resolvers(), &query);
.print_partial_headers("Checking wildcard resolution.", self.app_resolver.resolvers(), &query);

info!("Checking wildcard resolution.");
let (lookups, run_time) = time(self.app_resolver.lookup(query)).await?;
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<'a> WordlistLookups<'a> {

self.env
.console
.print_partial_headers("Wordlist lookups.", &self.app_resolver.resolvers(), &query);
.print_partial_headers("Wordlist lookups.", self.app_resolver.resolvers(), &query);

info!("Wordlist lookups.");
let (lookups, run_time) = time(self.app_resolver.lookup(query)).await?;
Expand Down Expand Up @@ -261,7 +261,7 @@ impl<'a> WordlistLookups<'a> {
Wordlist::default()?
}
.into_iter()
.map(|x| x.append_domain(&append_domain_name))
.map(|x| x.append_domain(append_domain_name))
.collect();
debug!("Loaded wordlist with {} words", wordlist.len());

Expand Down Expand Up @@ -374,7 +374,7 @@ impl<'a> OutputDiscoverResult<'a> {
}

fn print_fancy_name_by_domain(&self, name: &Name, domain_name: &Name) {
if domain_name.zone_of(&name) {
if domain_name.zone_of(name) {
let domain_len = domain_name.num_labels();
let sub_domain = Name::from_labels(name.iter().take((name.num_labels() - domain_len) as usize)).unwrap();
self.env
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/discover/wordlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Wordlist {
let mut words = Vec::new();

for line in data.lines() {
if Wordlist::is_comment(&line) {
if Wordlist::is_comment(line) {
continue;
}
trace!("Parsing wordlist item '{}'.", line);
Expand Down Expand Up @@ -217,7 +217,7 @@ mod tests {
#[test]
fn read_from_string() {
crate::utils::tests::logging::init();
let wordlist = Wordlist::from_str(&DEFAULT_WORD_LIST);
let wordlist = Wordlist::from_str(DEFAULT_WORD_LIST);

asserting("Wordlist with 5000 elements loaded from string")
.that(&wordlist)
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/get_server_lists/get_server_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ impl<'a> FileWriter<'a> {
let mut file = File::create(path).await?;

for config in response.nameserver_configs() {
let str = format!("{}\n", config.to_string());
file.write(str.as_bytes()).await?;
let str = format!("{}\n", config);
file.write_all(str.as_bytes()).await?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/lookup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl TryFrom<&ArgMatches<'_>> for LookupConfig {
.value_of("domain name")
.context("No domain name to lookup specified")?
.to_string(),
record_types: record_types(&args)?,
record_types: record_types(args)?,
whois: args.is_present("whois"),
parse_as_service: args.is_present("parse-as-service"),
};
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/lookup/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Lookup {
let app_resolver = AppResolver::create_resolvers(app_config).await?;

env.console
.print_resolver_opts(app_resolver.resolver_group_opts(), &app_resolver.resolver_opts());
.print_resolver_opts(app_resolver.resolver_group_opts(), app_resolver.resolver_opts());

Ok(DnsLookups {
env,
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'a> DnsLookups<'a> {
pub async fn lookups(self) -> PartialResult<Whois<'a>> {
self.env
.console
.print_partial_headers("Running lookups.", &self.app_resolver.resolvers(), &self.query);
.print_partial_headers("Running lookups.", self.app_resolver.resolvers(), &self.query);

info!("Running lookups");
let (lookups, run_time) = time(self.app_resolver.lookup(self.query)).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/lookup/service_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod test {
let str = "smtp:tcp:example.com";
let expected = ServiceSpec::new("smtp", "tcp", "example.com");

let spec = ServiceSpec::from_str(&str);
let spec = ServiceSpec::from_str(str);

assert_that(&spec).is_ok().is_equal_to(&expected);
}
Expand All @@ -74,7 +74,7 @@ mod test {
let str = "smtp::example.com";
let expected = ServiceSpec::new("smtp", "tcp", "example.com");

let spec = ServiceSpec::from_str(&str);
let spec = ServiceSpec::from_str(str);

assert_that(&spec).is_ok().is_equal_to(&expected);
}
Expand Down
18 changes: 2 additions & 16 deletions src/app/output/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ use nom::lib::std::collections::HashSet;
use super::*;
use serde::Serialize;

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct JsonOptions {
/// Pretty formatting
pretty: bool,
}

impl Default for JsonOptions {
fn default() -> Self {
JsonOptions { pretty: false }
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct JsonFormat {
opts: JsonOptions,
}
Expand All @@ -33,14 +27,6 @@ impl JsonFormat {
}
}

impl Default for JsonFormat {
fn default() -> Self {
JsonFormat {
opts: Default::default(),
}
}
}

impl<'a> TryFrom<Vec<&'a str>> for JsonOptions {
type Error = Error;

Expand Down
3 changes: 2 additions & 1 deletion src/app/output/summary/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ fn output_records<W: Write>(writer: &mut W, records: Vec<&Record>, opts: &Summar
Ok(())
}

//noinspection RsExternalLinter
fn summarize_records(records: Vec<&Record>) -> HashMap<&Record, Vec<&Record>> {
let mut records_set: HashMap<&Record, Vec<&Record>> = HashMap::new();
for r in records {
let set = records_set.entry(r).or_insert_with(Vec::new);
let set = records_set.entry(r).or_default();
set.push(r)
}
records_set
Expand Down
10 changes: 1 addition & 9 deletions src/app/output/summary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a> TryFrom<Vec<&'a str>> for SummaryOptions {
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct SummaryFormat {
opts: SummaryOptions,
}
Expand All @@ -84,14 +84,6 @@ impl SummaryFormat {
}
}

impl Default for SummaryFormat {
fn default() -> Self {
SummaryFormat {
opts: SummaryOptions::default(),
}
}
}

pub trait SummaryFormatter {
fn output<W: Write>(&self, writer: &mut W, opts: &SummaryOptions) -> Result<()>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/output/summary/whois.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ipnetwork::IpNetwork;

impl SummaryFormatter for WhoisResponses {
fn output<W: Write>(&self, writer: &mut W, opts: &SummaryOptions) -> Result<()> {
let mut responses_by_ip_network = responses_by_ip_network(&self);
let mut responses_by_ip_network = responses_by_ip_network(self);
let mut tw = TabWriter::new(vec![]);

for (ip_network, mut responses) in responses_by_ip_network.drain() {
Expand All @@ -38,7 +38,7 @@ impl SummaryFormatter for WhoisResponses {
fn output_responses<W: Write>(
writer: &mut W,
ip_network: &IpNetwork,
responses: &mut Vec<&WhoisResponse>,
responses: &mut [&WhoisResponse],
opts: &SummaryOptions,
) -> Result<()> {
responses.sort_by(order_by_ordinal);
Expand Down
22 changes: 10 additions & 12 deletions src/app/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ impl NameBuilderOpts {
.context("failed to get local hostname")?
.to_string_lossy()
.to_string();
let name = Name::from_str(&hostname)
.context("failed to parse local hostname")?;
let name = Name::from_str(&hostname).context("failed to parse local hostname")?;
let search_domain = name.base_name();
NameBuilderOpts::new(ndots, search_domain)
}
Expand Down Expand Up @@ -99,8 +98,8 @@ impl AppResolver {
configs: T,
app_config: &AppConfig,
) -> Result<AppResolver> {
let resolver_group_opts = load_resolver_group_opts(&app_config)?;
let resolver_opts = load_resolver_opts(&app_config)?;
let resolver_group_opts = load_resolver_group_opts(app_config)?;
let resolver_opts = load_resolver_opts(app_config)?;

let resolvers = ResolverGroup::from_configs(configs, resolver_opts, resolver_group_opts).await?;
if resolvers.is_empty() {
Expand All @@ -112,8 +111,8 @@ impl AppResolver {
}

pub async fn create_resolvers(app_config: &AppConfig) -> Result<AppResolver> {
let resolver_group_opts = load_resolver_group_opts(&app_config)?;
let resolver_opts = load_resolver_opts(&app_config)?;
let resolver_group_opts = load_resolver_group_opts(app_config)?;
let resolver_opts = load_resolver_opts(app_config)?;

let system_resolver_group: ResolverConfigGroup = load_system_nameservers(app_config)?.into();
let mut system_resolvers = ResolverGroup::from_configs(
Expand Down Expand Up @@ -153,11 +152,11 @@ impl AppResolver {
}

pub fn resolver_group_opts(&self) -> &ResolverGroupOpts {
&self.resolvers.opts()
self.resolvers.opts()
}

pub fn resolver_opts(&self) -> &ResolverOpts {
&self.resolvers.resolvers()[0].opts.as_ref() // Safe, because we created resolver
self.resolvers.resolvers()[0].opts.as_ref() // Safe, because we created resolver
}
}

Expand All @@ -166,7 +165,7 @@ async fn load_nameservers(config: &AppConfig, system_resolvers: &mut ResolverGro
if let Some(configs) = &config.nameservers {
let configs: Vec<_> = configs
.iter()
.map(|str| NameServerConfig::from_str_with_resolution(&system_resolvers, str))
.map(|str| NameServerConfig::from_str_with_resolution(system_resolvers, str))
.collect();
let configs: crate::Result<Vec<_>> = join_all(configs).await.into_iter().collect();
let nameservers: Vec<_> = configs.context("Failed to parse IP address for nameserver")?;
Expand All @@ -180,8 +179,7 @@ async fn load_nameservers(config: &AppConfig, system_resolvers: &mut ResolverGro
.as_ref()
.unwrap() // safe unwrap, because set by default by clap
.iter()
.map(|x| Protocol::from_str(x.as_str()))
.flatten()
.flat_map(|x| Protocol::from_str(x.as_str()))
.collect();
let nameservers: Vec<_> = predefined::nameserver_configs()
.into_iter()
Expand All @@ -192,7 +190,7 @@ async fn load_nameservers(config: &AppConfig, system_resolvers: &mut ResolverGro
nameservers_group.merge(nameservers);
}
if let Some(path) = config.nameserver_file_path.as_ref() {
let nameservers = NameServerConfigGroup::from_file(&system_resolvers, path)
let nameservers = NameServerConfigGroup::from_file(system_resolvers, path)
.await
.context("Failed to load nameservers from file")?;
info!("Loaded {} nameservers from file.", nameservers.len());
Expand Down

0 comments on commit cf6964c

Please sign in to comment.