From c403208332f1e86fe3e878dc0532f27372e184ee Mon Sep 17 00:00:00 2001 From: Steffen Eiden Date: Mon, 1 Dec 2025 15:28:38 +0100 Subject: [PATCH] rust: Apply suggested fixes from clippy Signed-off-by: Steffen Eiden --- rust/pv/src/brcb.rs | 11 +++++------ rust/pv/src/uvattest/arcb.rs | 2 +- rust/pv/src/verify.rs | 3 +-- rust/pv/src/verify/helper.rs | 6 +++--- rust/pv_core/src/uvdevice/secret_list.rs | 1 + rust/pvattest/src/cmd/check/host_key.rs | 3 +-- rust/pvimg/src/cmd/test.rs | 4 ++-- rust/pvimg/src/pv_utils/se_hdr/brb.rs | 1 + rust/pvimg/src/pv_utils/uv_keys.rs | 1 + rust/pvsecret/src/main.rs | 5 ++++- rust/utils/src/exit_code.rs | 6 +++--- 11 files changed, 23 insertions(+), 20 deletions(-) diff --git a/rust/pv/src/brcb.rs b/rust/pv/src/brcb.rs index e69e4c82..b1459cef 100644 --- a/rust/pv/src/brcb.rs +++ b/rust/pv/src/brcb.rs @@ -48,7 +48,7 @@ impl TryFrom> for BootHdrTags { /// Struct representing the Secure Execution boot image metadata #[allow(unused)] -#[repr(packed)] +#[repr(C, packed)] #[derive(Debug, Clone, FromBytes, IntoBytes, PartialEq, Eq, Immutable, KnownLayout)] pub struct SeImgMetaData { /// Magic value @@ -140,15 +140,14 @@ pub fn seek_se_hdr_start(img: &mut R) -> Result where R: Read + Seek, { - let max_iter: usize; const BUF_SIZE: i64 = 8; static_assert!(BootHdrMagic::MAGIC.len() == BUF_SIZE as usize); let old_position = img.stream_position()?; - if !SeImgMetaData::seek_start(img)? { + let max_iter: usize = if !SeImgMetaData::seek_start(img)? { // Search from the previous position. img.seek(std::io::SeekFrom::Start(old_position))?; - max_iter = 0x15; + 0x15 } else { let mut img_metadata_bytes = vec![0u8; size_of::()]; // read in the header @@ -161,8 +160,8 @@ where } img.seek(std::io::SeekFrom::Start(img_metadata.hdr_off.into()))?; - max_iter = 1; - } + 1 + }; let mut buf = [0; BUF_SIZE as usize]; for _ in 0..max_iter { diff --git a/rust/pv/src/uvattest/arcb.rs b/rust/pv/src/uvattest/arcb.rs index 37db0e53..853f2232 100644 --- a/rust/pv/src/uvattest/arcb.rs +++ b/rust/pv/src/uvattest/arcb.rs @@ -142,7 +142,7 @@ impl AttestationRequest { } /// Checks for magic and returns [`BinReqValues`] - fn bin_values(arcb: &[u8]) -> Result { + fn bin_values(arcb: &[u8]) -> Result> { if !AttestationMagic::starts_with_magic(arcb) { return Err(Error::NoArcb); } diff --git a/rust/pv/src/verify.rs b/rust/pv/src/verify.rs index 05da3d9f..c5e0c4ba 100644 --- a/rust/pv/src/verify.rs +++ b/rust/pv/src/verify.rs @@ -167,8 +167,7 @@ impl CertVerifier { /// * `cert_paths` - Paths to certificates for the chain of trust /// * `crl_paths` - Paths to certificate revocation lists for the chain of trust /// * `root_ca_path` - Path to the root of trust - /// * `offline` - if set to true the verification process will not try to download CRLs from the - /// internet. + /// * `offline` - if set to true the verification process will not try to download CRLs from the internet. /// /// # Errors /// diff --git a/rust/pv/src/verify/helper.rs b/rust/pv/src/verify/helper.rs index 6318bf29..6ff8e292 100644 --- a/rust/pv/src/verify/helper.rs +++ b/rust/pv/src/verify/helper.rs @@ -443,17 +443,17 @@ mod test { let ibm_wrong_subj = load_gen_cert("ibm_wrong_subject.crt"); let no_sign_crt = load_gen_cert("inter_ca.crt"); - assert!(super::get_ibm_z_sign_key(&[ibm_crt.clone()]).is_ok()); + assert!(super::get_ibm_z_sign_key(std::slice::from_ref(&ibm_crt)).is_ok()); assert!(matches!( super::get_ibm_z_sign_key(&[ibm_crt.clone(), ibm_crt.clone()]), Err(Error::HkdVerify(ManyIbmSignKeys)) )); assert!(matches!( - super::get_ibm_z_sign_key(&[ibm_wrong_subj]), + super::get_ibm_z_sign_key(std::slice::from_ref(&ibm_wrong_subj)), Err(Error::HkdVerify(NoIbmSignKey)) )); assert!(matches!( - super::get_ibm_z_sign_key(&[no_sign_crt.clone()]), + super::get_ibm_z_sign_key(std::slice::from_ref(&no_sign_crt)), Err(Error::HkdVerify(NoIbmSignKey)) )); assert!(super::get_ibm_z_sign_key(&[ibm_crt, no_sign_crt]).is_ok(),); diff --git a/rust/pv_core/src/uvdevice/secret_list.rs b/rust/pv_core/src/uvdevice/secret_list.rs index 708016e6..07a72a3d 100644 --- a/rust/pv_core/src/uvdevice/secret_list.rs +++ b/rust/pv_core/src/uvdevice/secret_list.rs @@ -245,6 +245,7 @@ assert_size!(SecretListHdr, 16); /// The list should ONLY be created from an UV-Call result using either: /// - [`TryInto::try_into`] from [`ListCmd`] /// - [`SecretList::decode`] +/// /// Any other ways can create invalid lists that do not represent the UV secret store. /// The list must not hold more than [`u32::MAX`] elements #[derive(Debug, PartialEq, Eq, Serialize, Default)] diff --git a/rust/pvattest/src/cmd/check/host_key.rs b/rust/pvattest/src/cmd/check/host_key.rs index c4c32b5d..0233e4ff 100644 --- a/rust/pvattest/src/cmd/check/host_key.rs +++ b/rust/pvattest/src/cmd/check/host_key.rs @@ -134,7 +134,6 @@ pub fn host_key_check<'a, 'b>( #[cfg(test)] mod test { - use std::path::PathBuf; use super::*; @@ -169,7 +168,7 @@ mod test { let res = contains_phkh(&hash, &HexSlice::from(&hash[0].1), HkCheck::Image, true); assert!(matches!( res, - CheckState::Data(s) if s.hash.unwrap() == PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/assets/host.pem.crt")) + CheckState::Data(s) if s.hash.unwrap() == Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/assets/host.pem.crt")) )) } } diff --git a/rust/pvimg/src/cmd/test.rs b/rust/pvimg/src/cmd/test.rs index 806eecd1..4cb1a0b5 100644 --- a/rust/pvimg/src/cmd/test.rs +++ b/rust/pvimg/src/cmd/test.rs @@ -2,7 +2,7 @@ // // Copyright IBM Corp. 2024 -use std::path::{Path, PathBuf}; +use std::path::Path; use anyhow::Result; use log::{info, warn}; @@ -27,7 +27,7 @@ fn hdr_test_target_hashes(hdr: &SeHdr, key_hashes: &Path) -> Result { ref source, } if matches!(ty, FileAccessErrorType::Open) && source.kind() == std::io::ErrorKind::NotFound - && *path == PathBuf::from(UvKeyHashesV1::SYS_UV_KEYS_ALL) => + && path == Path::new(UvKeyHashesV1::SYS_UV_KEYS_ALL) => { Error::UnavailableQueryUvKeyHashesSupport { source: err } } diff --git a/rust/pvimg/src/pv_utils/se_hdr/brb.rs b/rust/pvimg/src/pv_utils/se_hdr/brb.rs index 2fbbb596..9401c953 100644 --- a/rust/pvimg/src/pv_utils/se_hdr/brb.rs +++ b/rust/pvimg/src/pv_utils/se_hdr/brb.rs @@ -140,6 +140,7 @@ pub trait SeHdrPubBuilderTrait { fn set_pcf(&mut self, pcf: &PlaintextControlFlagsV1) -> Result<()>; } +#[allow(dead_code)] #[enum_dispatch(SeHdrData)] pub trait SeHdrConfBuilderTrait { fn generate_cck(&self) -> Result; diff --git a/rust/pvimg/src/pv_utils/uv_keys.rs b/rust/pvimg/src/pv_utils/uv_keys.rs index e83c8e1e..8d785e91 100644 --- a/rust/pvimg/src/pv_utils/uv_keys.rs +++ b/rust/pvimg/src/pv_utils/uv_keys.rs @@ -18,6 +18,7 @@ trait UvKeyHashTrait: AsRef<[u8]> {} #[derive(Debug, PartialEq, Eq)] pub struct UvKeyHashV1([u8; 32]); +#[allow(dead_code)] #[non_exhaustive] #[enum_dispatch] #[derive(PartialEq, Eq, Debug)] diff --git a/rust/pvsecret/src/main.rs b/rust/pvsecret/src/main.rs index 883a3ee2..2338fb7e 100644 --- a/rust/pvsecret/src/main.rs +++ b/rust/pvsecret/src/main.rs @@ -43,7 +43,10 @@ fn main() -> ExitCode { Command::List(opt) => cmd::list(opt), Command::Lock => cmd::lock(), Command::Create(opt) => cmd::create(opt), - Command::Version => Ok(print_version!("2024", log_level; FEATURES.concat())), + Command::Version => { + print_version!("2024", log_level; FEATURES.concat()); + Ok(()) + } Command::Verify(opt) => cmd::verify(opt), Command::Retrieve(opt) => cmd::retr(opt), }; diff --git a/rust/utils/src/exit_code.rs b/rust/utils/src/exit_code.rs index d3cac9b5..450f6f2e 100644 --- a/rust/utils/src/exit_code.rs +++ b/rust/utils/src/exit_code.rs @@ -41,11 +41,11 @@ pub fn docstring(attr: &str) -> Option { let mut doc = attr .strip_prefix("doc = r\"") .unwrap() - .strip_suffix("\"") + .strip_suffix('\"') .unwrap() .to_string(); - if doc.starts_with(" ") { - doc = doc.strip_prefix(" ").unwrap().to_string(); + if doc.starts_with(' ') { + doc = doc.strip_prefix(' ').unwrap().to_string(); } Some(doc) }