mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust: Apply suggested fixes from clippy
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
///
|
||||
|
||||
@@ -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(),);
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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"))
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<bool> {
|
||||
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 }
|
||||
}
|
||||
|
||||
@@ -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<SymKey>;
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
|
||||
@@ -41,11 +41,11 @@ pub fn docstring(attr: &str) -> Option<String> {
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user