From 87d43c7a32fa8cd3634b83d2207da091f765feae Mon Sep 17 00:00:00 2001 From: Steffen Eiden Date: Thu, 23 May 2024 14:35:30 +0200 Subject: [PATCH] rust/pv_*: Add more deny lints to pv and pv_core Denies compiling if one of the following lints find something in pv or pv_core: missing_docs, missing_debug_implementations, trivial_numeric_casts, unstable_features, unused_import_braces, unused_qualifications Those lint force developers to avoid unnecessary code and providing debuggability & documentation for each public symbol. Fix the compile time error introduced with those lints. Signed-off-by: Marc Hartmayer Signed-off-by: Steffen Eiden --- rust/pv/src/brcb.rs | 1 + rust/pv/src/lib.rs | 9 ++++++++- rust/pv/src/openssl_extensions/stackable_crl.rs | 2 +- rust/pv/src/req.rs | 5 +++-- rust/pv/src/test_utils.rs | 2 +- rust/pv/src/verify/helper.rs | 2 +- rust/pv_core/src/lib.rs | 9 ++++++++- rust/pv_core/src/utils.rs | 4 ++-- rust/pv_core/src/uvdevice.rs | 1 + rust/pv_core/src/uvdevice/secret.rs | 3 +++ rust/pv_core/src/uvdevice/secret_list.rs | 2 +- rust/pv_core/src/uvdevice/test.rs | 2 +- 12 files changed, 31 insertions(+), 11 deletions(-) diff --git a/rust/pv/src/brcb.rs b/rust/pv/src/brcb.rs index 2e42208b..84b02106 100644 --- a/rust/pv/src/brcb.rs +++ b/rust/pv/src/brcb.rs @@ -46,6 +46,7 @@ impl TryFrom> for BootHdrTags { } /// Magic value for a SE-(boot)header +#[derive(Debug)] pub struct BootHdrMagic; impl MagicValue<8> for BootHdrMagic { const MAGIC: [u8; 8] = [0x49, 0x42, 0x4d, 0x53, 0x65, 0x63, 0x45, 0x78]; diff --git a/rust/pv/src/lib.rs b/rust/pv/src/lib.rs index fad7b292..9a647617 100644 --- a/rust/pv/src/lib.rs +++ b/rust/pv/src/lib.rs @@ -2,7 +2,14 @@ // // Copyright IBM Corp. 2023, 2024 -#![deny(missing_docs)] +#![deny( + missing_docs, + missing_debug_implementations, + trivial_numeric_casts, + unstable_features, + unused_import_braces, + unused_qualifications +)] #![doc = include_str!("../README.md")] //! # Manage guest secret store //! diff --git a/rust/pv/src/openssl_extensions/stackable_crl.rs b/rust/pv/src/openssl_extensions/stackable_crl.rs index 0ad4bff6..0658bb97 100644 --- a/rust/pv/src/openssl_extensions/stackable_crl.rs +++ b/rust/pv/src/openssl_extensions/stackable_crl.rs @@ -111,7 +111,7 @@ impl StackableX509Crl { ); if r.is_null() { let err = openssl_sys::ERR_peek_last_error(); - if openssl_sys::ERR_GET_LIB(err) as c_int == openssl_sys::ERR_LIB_PEM + if openssl_sys::ERR_GET_LIB(err) == openssl_sys::ERR_LIB_PEM && openssl_sys::ERR_GET_REASON(err) == openssl_sys::PEM_R_NO_START_LINE { openssl_sys::ERR_clear_error(); diff --git a/rust/pv/src/req.rs b/rust/pv/src/req.rs index f21060a7..a0a1eb61 100644 --- a/rust/pv/src/req.rs +++ b/rust/pv/src/req.rs @@ -54,6 +54,7 @@ pub trait Encrypt { } /// Types of Authenticated Data +#[allow(missing_debug_implementations)] pub enum Aad<'a> { /// Authenticated Keyslot Ks(&'a Keyslot), @@ -207,7 +208,7 @@ impl ReqEncrCtx { let mut auth_data: Vec = Vec::with_capacity(2048); // reserve space for the request header - auth_data.resize(std::mem::size_of::(), 0); + auth_data.resize(size_of::(), 0); for a in aad { match a { @@ -229,7 +230,7 @@ impl ReqEncrCtx { let req_hdr = RequestHdr::new(version, rql, self.iv, nks, sea, magic); // copy request header to the start of the request - auth_data[..std::mem::size_of::()].copy_from_slice(req_hdr.as_bytes()); + auth_data[..size_of::()].copy_from_slice(req_hdr.as_bytes()); Ok(auth_data) } diff --git a/rust/pv/src/test_utils.rs b/rust/pv/src/test_utils.rs index 141afdca..ec43d227 100644 --- a/rust/pv/src/test_utils.rs +++ b/rust/pv/src/test_utils.rs @@ -30,7 +30,7 @@ macro_rules! get_test_asset { } pub fn get_cert_asset_path>(path: P) -> PathBuf { - let mut p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR")); p.push("tests"); p.push("assets"); p.push("cert"); diff --git a/rust/pv/src/verify/helper.rs b/rust/pv/src/verify/helper.rs index 2bda7087..1f25bd00 100644 --- a/rust/pv/src/verify/helper.rs +++ b/rust/pv/src/verify/helper.rs @@ -261,7 +261,7 @@ fn load_crl_to_store( x509_store: &mut X509StoreBuilder, path: &Path, err_out_empty_crl: bool, -) -> std::result::Result<(), openssl::error::ErrorStack> { +) -> std::result::Result<(), ErrorStack> { let lu = x509_store.add_lookup(X509Lookup::::file())?; // Try to load cert as PEM file if lu.load_crl_file(path, SslFiletype::PEM).is_err() { diff --git a/rust/pv_core/src/lib.rs b/rust/pv_core/src/lib.rs index 4df3f04d..1356c1b7 100644 --- a/rust/pv_core/src/lib.rs +++ b/rust/pv_core/src/lib.rs @@ -1,7 +1,14 @@ // SPDX-License-Identifier: MIT // // Copyright IBM Corp. 2023, 2024 -#![deny(missing_docs)] +#![deny( + missing_docs, + missing_debug_implementations, + trivial_numeric_casts, + unstable_features, + unused_import_braces, + unused_qualifications +)] #![doc = include_str!("../README.md")] mod error; mod macros; diff --git a/rust/pv_core/src/utils.rs b/rust/pv_core/src/utils.rs index 3f67ff17..26afe758 100644 --- a/rust/pv_core/src/utils.rs +++ b/rust/pv_core/src/utils.rs @@ -224,8 +224,8 @@ pub fn read_exact_file, const COUNT: usize>( path: P, ctx: &str, ) -> Result<[u8; COUNT]> { - let mut f = std::fs::File::open(&path).map_err(|e| Error::FileAccess { - ty: crate::FileAccessErrorType::Open, + let mut f = File::open(&path).map_err(|e| Error::FileAccess { + ty: FileAccessErrorType::Open, path: path_to_str!(path).to_string(), source: e, })?; diff --git a/rust/pv_core/src/uvdevice.rs b/rust/pv_core/src/uvdevice.rs index de04b878..b7b7cbea 100644 --- a/rust/pv_core/src/uvdevice.rs +++ b/rust/pv_core/src/uvdevice.rs @@ -187,6 +187,7 @@ pub enum UvcSuccess { /// /// /// ``` +#[derive(Debug)] pub struct UvDevice(File); impl UvDevice { diff --git a/rust/pv_core/src/uvdevice/secret.rs b/rust/pv_core/src/uvdevice/secret.rs index 227b87ae..b31b0bf5 100644 --- a/rust/pv_core/src/uvdevice/secret.rs +++ b/rust/pv_core/src/uvdevice/secret.rs @@ -10,6 +10,7 @@ use std::io::Read; /// /// The List Secrets Ultravisor call is used to list the /// secrets that are in the secret store for the current SE-guest. +#[derive(Debug)] pub struct ListCmd(Vec); impl ListCmd { fn with_size(size: usize) -> Self { @@ -44,6 +45,7 @@ impl UvCmd for ListCmd { /// /// The Add Secret Ultravisor-call is used to add a secret /// to the secret store for the current SE-guest. +#[derive(Debug)] pub struct AddCmd(Vec); impl AddCmd { @@ -101,6 +103,7 @@ impl UvCmd for AddCmd { /// all changes to the secret store. Upon successful /// completion of a Lock Secret Store Ultravisor-call, any /// request to modify the secret store will fail. +#[derive(Debug)] pub struct LockCmd; impl UvCmd for LockCmd { const UV_IOCTL_NR: u8 = ffi::UVIO_IOCTL_LOCK_SECRETS_NR; diff --git a/rust/pv_core/src/uvdevice/secret_list.rs b/rust/pv_core/src/uvdevice/secret_list.rs index dbfba321..5729fd0f 100644 --- a/rust/pv_core/src/uvdevice/secret_list.rs +++ b/rust/pv_core/src/uvdevice/secret_list.rs @@ -278,7 +278,7 @@ fn ser_u16(v: &U16, ser: S) -> Result /// Secret types that can appear in a [`SecretList`] #[non_exhaustive] -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq, Debug)] pub enum ListableSecretType { /// Association Secret Association, diff --git a/rust/pv_core/src/uvdevice/test.rs b/rust/pv_core/src/uvdevice/test.rs index 69e20406..95bed700 100644 --- a/rust/pv_core/src/uvdevice/test.rs +++ b/rust/pv_core/src/uvdevice/test.rs @@ -126,7 +126,7 @@ impl UvCmd for TestCmd { impl UvDevice { ///use some random fd for `uvdevice` its OK, as the ioctl is mocked and never touches the passed file fn test_dev() -> Self { - UvDevice(unsafe { std::fs::File::from_raw_fd(17) }) + UvDevice(unsafe { File::from_raw_fd(17) }) } }