Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Oct 21, 2023
1 parent 638c804 commit 9a56542
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cargo-crev/src/deps/print_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion cargo-crev/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
10 changes: 0 additions & 10 deletions crev-data/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ impl Digest {
&self.0
}

#[must_use]
pub fn from_vec(vec: Vec<u8>) -> Option<Self> {
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<Self> {
if bytes.len() == 32 {
Expand Down
4 changes: 2 additions & 2 deletions crev-data/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ impl AsRef<PublicId> for UnlockedId {

impl UnlockedId {
#[allow(clippy::new_ret_no_self)]
pub fn new(url: Option<Url>, sec_key: Vec<u8>) -> Result<Self, IdError> {
let sec_key = SecretKey::from_bytes(&sec_key)
pub fn new(url: Option<Url>, sec_key: &[u8]) -> Result<Self, IdError> {
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);

Expand Down
2 changes: 2 additions & 0 deletions crev-data/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
1 change: 1 addition & 0 deletions crev-data/src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub type DateUtc = chrono::DateTime<Utc>;
pub struct Digest(pub [u8; 32]);

impl Digest {
#[must_use]
pub fn to_base64(&self) -> String {
crev_common::base64_encode(&self.0)
}
Expand Down
2 changes: 1 addition & 1 deletion crev-lib/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
21 changes: 11 additions & 10 deletions crev-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -388,6 +388,7 @@ pub enum Warning {
}

impl Warning {
#[must_use]
pub fn auto_log() -> LogOnDrop {
LogOnDrop(Vec::new())
}
Expand Down Expand Up @@ -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`
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -484,7 +485,7 @@ pub fn dir_verify(
trusted_set: &crev_wot::TrustSet,
requirements: &VerificationRequirements,
) -> Result<crate::VerificationStatus> {
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,
Expand All @@ -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<PathBuf>) -> Result<Digest> {
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<PathBuf>,
Expand All @@ -522,20 +523,20 @@ 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<PathBuf>,
) -> Result<crev_data::Digest> {
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<PathBuf>,
) -> Result<Digest> {
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,
)?)
Expand Down
2 changes: 1 addition & 1 deletion crev-lib/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl Local {
pub fn get_current_user_public_ids(&self) -> Result<Vec<PublicId>> {
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)?;
Expand Down
2 changes: 1 addition & 1 deletion crev-lib/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 6 additions & 5 deletions crev-wot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -424,10 +425,10 @@ impl ProofDB {
.map(move |timestampted| &timestampted.value)
}

pub fn get_pkg_flags<'s>(
&'s self,
pub fn get_pkg_flags(
&self,
pkg_id: &proof::PackageId,
) -> impl Iterator<Item = (&Id, &'s proof::Flags)> {
) -> impl Iterator<Item = (&Id, &proof::Flags)> {
self.package_flags
.get(pkg_id)
.into_iter()
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions crevette/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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))
});

Expand Down Expand Up @@ -201,7 +197,7 @@ impl Crevette {
None,
Some(format!(
"{} -> {}",
self.vet_version(&base),
self.vet_version(base),
self.vet_version(&r.package)
)),
)
Expand Down Expand Up @@ -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<String>,
Expand Down

0 comments on commit 9a56542

Please sign in to comment.