From 9a56542e16f2aa1750d29fd521d704fbd0bb95f6 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sat, 21 Oct 2023 14:28:24 +0100 Subject: [PATCH] Clippy --- cargo-crev/src/deps/print_term.rs | 2 +- cargo-crev/src/shared.rs | 2 +- crev-data/src/digest.rs | 10 ---------- crev-data/src/id.rs | 4 ++-- crev-data/src/lib.rs | 2 ++ crev-data/src/proof/mod.rs | 1 + crev-lib/src/id.rs | 2 +- crev-lib/src/lib.rs | 21 +++++++++++---------- crev-lib/src/local.rs | 2 +- crev-lib/src/util/mod.rs | 2 +- crev-wot/src/lib.rs | 11 ++++++----- crevette/src/lib.rs | 18 +++++++----------- 12 files changed, 34 insertions(+), 43 deletions(-) diff --git a/cargo-crev/src/deps/print_term.rs b/cargo-crev/src/deps/print_term.rs index e856a102..309b6144 100644 --- a/cargo-crev/src/deps/print_term.rs +++ b/cargo-crev/src/deps/print_term.rs @@ -2,7 +2,7 @@ // terminal (not in the context of a real terminal application) use super::*; -use crate::term::{self, *}; +use crate::term::{self, Term}; use std::{io, io::Write, write, writeln}; const CRATE_VERIFY_CRATE_COLUMN_TITLE: &str = "crate"; diff --git a/cargo-crev/src/shared.rs b/cargo-crev/src/shared.rs index 55fc075e..a3490253 100644 --- a/cargo-crev/src/shared.rs +++ b/cargo-crev/src/shared.rs @@ -633,7 +633,7 @@ where }); } }; - let sel = sel.as_ref().unwrap_or(&args); + let sel = sel.as_ref().unwrap_or(args); sel.crate_.ensure_name_given()?; f(sel)?; } diff --git a/crev-data/src/digest.rs b/crev-data/src/digest.rs index f32188fa..e0b88678 100644 --- a/crev-data/src/digest.rs +++ b/crev-data/src/digest.rs @@ -16,16 +16,6 @@ impl Digest { &self.0 } - #[must_use] - pub fn from_vec(vec: Vec) -> Option { - if vec.len() == 32 { - let mut out = [0; 32]; - out.copy_from_slice(&vec); - Some(Self(out)) - } else { - None - } - } #[must_use] pub fn from_bytes(bytes: &[u8]) -> Option { if bytes.len() == 32 { diff --git a/crev-data/src/id.rs b/crev-data/src/id.rs index 093bb79e..5fc32440 100644 --- a/crev-data/src/id.rs +++ b/crev-data/src/id.rs @@ -209,8 +209,8 @@ impl AsRef for UnlockedId { impl UnlockedId { #[allow(clippy::new_ret_no_self)] - pub fn new(url: Option, sec_key: Vec) -> Result { - let sec_key = SecretKey::from_bytes(&sec_key) + pub fn new(url: Option, sec_key: &[u8]) -> Result { + let sec_key = SecretKey::from_bytes(sec_key) .map_err(|e| IdError::InvalidSecretKey(e.to_string().into()))?; let calculated_pub_key: PublicKey = PublicKey::from(&sec_key); diff --git a/crev-data/src/lib.rs b/crev-data/src/lib.rs index c98c1c5d..6910e123 100644 --- a/crev-data/src/lib.rs +++ b/crev-data/src/lib.rs @@ -1,6 +1,8 @@ //! This crate contains only code handling data types //! used by `crev`, without getting into details //! how actually `crev` works (where and how it manages data). +#![allow(clippy::default_trait_access)] +#![allow(clippy::items_after_statements)] #![allow(clippy::missing_errors_doc)] #![allow(clippy::missing_panics_doc)] #![allow(clippy::module_name_repetitions)] diff --git a/crev-data/src/proof/mod.rs b/crev-data/src/proof/mod.rs index ac1b5efe..512662cb 100644 --- a/crev-data/src/proof/mod.rs +++ b/crev-data/src/proof/mod.rs @@ -30,6 +30,7 @@ pub type DateUtc = chrono::DateTime; pub struct Digest(pub [u8; 32]); impl Digest { + #[must_use] pub fn to_base64(&self) -> String { crev_common::base64_encode(&self.0) } diff --git a/crev-lib/src/id.rs b/crev-lib/src/id.rs index 655391e4..eef23443 100644 --- a/crev-lib/src/id.rs +++ b/crev-lib/src/id.rs @@ -215,7 +215,7 @@ impl LockedId { assert!(!secret_key.is_empty()); - let result = UnlockedId::new(url.clone(), secret_key)?; + let result = UnlockedId::new(url.clone(), &secret_key)?; if public_key != &result.keypair.public.to_bytes() { return Err(Error::PubKeyMismatch); } diff --git a/crev-lib/src/lib.rs b/crev-lib/src/lib.rs index d995448d..e5896656 100644 --- a/crev-lib/src/lib.rs +++ b/crev-lib/src/lib.rs @@ -282,7 +282,7 @@ pub enum VerificationStatus { } impl VerificationStatus { - /// Is it VerificationStatus::Verified? + /// Is it `VerificationStatus::Verified`? #[must_use] pub fn is_verified(self) -> bool { self == VerificationStatus::Verified @@ -388,6 +388,7 @@ pub enum Warning { } impl Warning { + #[must_use] pub fn auto_log() -> LogOnDrop { LogOnDrop(Vec::new()) } @@ -425,7 +426,7 @@ impl std::ops::DerefMut for LogOnDrop { } } -/// Scan through known reviews of the crate (source is "https://crates.io") +/// Scan through known reviews of the crate (source is `"https://crates.io"`) /// and report semver you can safely use according to `requirements` /// /// See also `verify_package_digest` @@ -439,7 +440,7 @@ pub fn find_latest_trusted_version( db.get_pkg_reviews_for_name(source, name) .filter(|review| { verify_package_digest( - &Digest::from_vec(review.package.digest.clone()).unwrap(), + &Digest::from_bytes(&review.package.digest).unwrap(), trust_set, requirements, db, @@ -463,7 +464,7 @@ pub fn dir_or_git_repo_verify( let digest = if path.join(".git").exists() { get_recursive_digest_for_git_dir(path, ignore_list)? } else { - Digest::from_vec(util::get_recursive_digest_for_dir(path, ignore_list)?).unwrap() + Digest::from_bytes(&util::get_recursive_digest_for_dir(path, ignore_list)?).unwrap() }; Ok(verify_package_digest( @@ -484,7 +485,7 @@ pub fn dir_verify( trusted_set: &crev_wot::TrustSet, requirements: &VerificationRequirements, ) -> Result { - let digest = Digest::from_vec(util::get_recursive_digest_for_dir(path, ignore_list)?).unwrap(); + let digest = Digest::from_bytes(&util::get_recursive_digest_for_dir(path, ignore_list)?).unwrap(); Ok(verify_package_digest( &digest, trusted_set, @@ -495,10 +496,10 @@ pub fn dir_verify( /// Scan dir and hash everything in it, to get a unique identifier of the package's source code pub fn get_dir_digest(path: &Path, ignore_list: &fnv::FnvHashSet) -> Result { - Ok(Digest::from_vec(util::get_recursive_digest_for_dir(path, ignore_list)?).unwrap()) + Ok(Digest::from_bytes(&util::get_recursive_digest_for_dir(path, ignore_list)?).unwrap()) } -/// See get_dir_digest +/// See `get_dir_digest` pub fn get_recursive_digest_for_git_dir( root_path: &Path, ignore_list: &fnv::FnvHashSet, @@ -522,7 +523,7 @@ pub fn get_recursive_digest_for_git_dir( Ok(util::get_recursive_digest_for_paths(root_path, paths)?) } -/// See get_dir_digest +/// See `get_dir_digest` pub fn get_recursive_digest_for_paths( root_path: &Path, paths: fnv::FnvHashSet, @@ -530,12 +531,12 @@ pub fn get_recursive_digest_for_paths( Ok(util::get_recursive_digest_for_paths(root_path, paths)?) } -/// See get_dir_digest +/// See `get_dir_digest` pub fn get_recursive_digest_for_dir( root_path: &Path, rel_path_ignore_list: &fnv::FnvHashSet, ) -> Result { - Ok(Digest::from_vec(util::get_recursive_digest_for_dir( + Ok(Digest::from_bytes(&util::get_recursive_digest_for_dir( root_path, rel_path_ignore_list, )?) diff --git a/crev-lib/src/local.rs b/crev-lib/src/local.rs index 53a24089..414134c5 100644 --- a/crev-lib/src/local.rs +++ b/crev-lib/src/local.rs @@ -299,7 +299,7 @@ impl Local { pub fn get_current_user_public_ids(&self) -> Result> { let mut ids = vec![]; if let Some(ids_path) = self.user_ids_path_opt() { - for dir_entry in std::fs::read_dir(&ids_path)? { + for dir_entry in std::fs::read_dir(ids_path)? { let path = dir_entry?.path(); if path.extension().map_or(false, |ext| ext == "yaml") { let locked_id = LockedId::read_from_yaml_file(&path)?; diff --git a/crev-lib/src/util/mod.rs b/crev-lib/src/util/mod.rs index 530ea237..d10f125b 100644 --- a/crev-lib/src/util/mod.rs +++ b/crev-lib/src/util/mod.rs @@ -48,7 +48,7 @@ pub fn get_recursive_digest_for_paths( .build(); let digest_vec = h.get_digest_of(root_path)?; - Ok(crev_data::Digest::from_vec(digest_vec).unwrap()) + Ok(crev_data::Digest::from_bytes(&digest_vec).unwrap()) } pub fn get_recursive_digest_for_dir( diff --git a/crev-wot/src/lib.rs b/crev-wot/src/lib.rs index a333d9f8..dbdc60a2 100644 --- a/crev-wot/src/lib.rs +++ b/crev-wot/src/lib.rs @@ -12,6 +12,7 @@ //! //! `crev-wot` is just an initial, reference implementation, and might //! evolve, be replaced or become just one of many available implementations. +#![allow(clippy::default_trait_access)] #![allow(clippy::doc_markdown)] #![allow(clippy::if_not_else)] #![allow(clippy::missing_panics_doc)] @@ -424,10 +425,10 @@ impl ProofDB { .map(move |timestampted| ×tampted.value) } - pub fn get_pkg_flags<'s>( - &'s self, + pub fn get_pkg_flags( + &self, pkg_id: &proof::PackageId, - ) -> impl Iterator { + ) -> impl Iterator { self.package_flags .get(pkg_id) .into_iter() @@ -1084,7 +1085,7 @@ impl ProofDB { let fetch_matches = match fetched_from { FetchSource::LocalUser => true, FetchSource::Url(fetched_url) if **fetched_url == *url => true, - _ => false, + FetchSource::Url(_other) => false, }; self.url_by_id_self_reported .entry(from.id.clone()) @@ -1227,7 +1228,7 @@ impl<'a> UrlOfId<'a> { pub fn any_unverified(self) -> Option<&'a Url> { match self { Self::FromSelfVerified(url) | Self::FromSelf(url) | Self::FromOthers(url) => Some(url), - _ => None, + Self::None => None, } } } diff --git a/crevette/src/lib.rs b/crevette/src/lib.rs index ec4a3e1c..2b7816f9 100644 --- a/crevette/src/lib.rs +++ b/crevette/src/lib.rs @@ -39,7 +39,7 @@ impl Crevette { } /// Export reviews from the given db, if they meet minimum trust level, - /// based on the trust_params, from perspective of the given Id. + /// based on the `trust_params`, from perspective of the given Id. pub fn new_with_options( db: ProofDB, id: &Id, @@ -86,14 +86,10 @@ impl Crevette { format!("https://raw.githubusercontent.com/{rest}/HEAD/audits.toml"), rest.split('/').next().unwrap_or_default().into(), )) - } else if let Some(rest) = u.strip_prefix("https://gitlab.com/") { - Some(( + } else { u.strip_prefix("https://gitlab.com/").map(|rest| ( format!("https://gitlab.com/{rest}/-/raw/HEAD/audits.toml"), rest.split('/').next().unwrap_or_default().into(), - )) - } else { - None - } + )) } }) .unzip(); @@ -135,8 +131,8 @@ impl Crevette { for reviews_for_crate in all.values_mut() { reviews_for_crate.sort_by(|(a_trust, q_a, a), (b_trust, q_b, b)| { b.package.id.version.cmp(&a.package.id.version) - .then(b_trust.cmp(&a_trust)) - .then(q_b.cmp(&q_a)) + .then(b_trust.cmp(a_trust)) + .then(q_b.cmp(q_a)) .then(b.common.date.cmp(&a.common.date)) }); @@ -201,7 +197,7 @@ impl Crevette { None, Some(format!( "{} -> {}", - self.vet_version(&base), + self.vet_version(base), self.vet_version(&r.package) )), ) @@ -356,7 +352,7 @@ fn criteria_for_non_negative_review(trust: TrustLevel, r: &Package, review: &Rev criteria } -/// Result of convert_to_repo +/// Result of `convert_to_repo` pub struct RepoInfo { pub local_path: PathBuf, pub repo_git_url: Option,