rust: Apply suggested fixes from clippy

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Steffen Eiden
2025-12-01 15:28:38 +01:00
parent 2a99007a6e
commit c403208332
11 changed files with 23 additions and 20 deletions
+5 -6
View File
@@ -48,7 +48,7 @@ impl TryFrom<Vec<u8>> 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<R>(img: &mut R) -> Result<bool>
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::<SeImgMetaData>()];
// 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 {
+1 -1
View File
@@ -142,7 +142,7 @@ impl AttestationRequest {
}
/// Checks for magic and returns [`BinReqValues`]
fn bin_values(arcb: &[u8]) -> Result<BinReqValues> {
fn bin_values(arcb: &[u8]) -> Result<BinReqValues<'_>> {
if !AttestationMagic::starts_with_magic(arcb) {
return Err(Error::NoArcb);
}
+1 -2
View File
@@ -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
///
+3 -3
View File
@@ -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(),);