From f8fb9ce32a0a1c64733693d41ecc1ed58063ad22 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Mon, 11 May 2026 14:43:53 +0200 Subject: [PATCH] rust: Run rustfmt with some experimental options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Sort and group the imports + Normalize and format comments (100 characters width) Command used: $ cargo +nightly fmt -- Acked-by: Steffen Eiden Signed-off-by: Marc Hartmayer Signed-off-by: Jan Höppner --- rust/cpacfinfo/src/main.rs | 6 +- rust/cpacfinfo/src/msa.rs | 4 +- rust/cpacfinfo/src/query.rs | 6 +- rust/pv/examples/hash_hkd/main.rs | 7 +- rust/pv/src/brcb.rs | 7 +- rust/pv/src/crypto.rs | 34 +++++---- rust/pv/src/lib.rs | 52 ++++++-------- rust/pv/src/openssl_extensions/akid.rs | 5 +- rust/pv/src/openssl_extensions/bio.rs | 6 +- rust/pv/src/openssl_extensions/crl.rs | 15 ++-- .../src/openssl_extensions/stackable_crl.rs | 14 ++-- rust/pv/src/pem_utils.rs | 19 ++--- rust/pv/src/req.rs | 33 ++++----- rust/pv/src/test_utils.rs | 20 +++--- rust/pv/src/utils.rs | 7 +- rust/pv/src/uvattest/additional.rs | 7 +- rust/pv/src/uvattest/arcb.rs | 34 ++++----- rust/pv/src/uvattest/attest.rs | 22 +++--- rust/pv/src/uvsecret/asrcb.rs | 31 ++++----- rust/pv/src/uvsecret/guest_secret.rs | 46 ++++++------- rust/pv/src/uvsecret/retr_secret.rs | 27 ++++---- rust/pv/src/uvsecret/user_data.rs | 21 +++--- rust/pv/src/verify.rs | 13 ++-- rust/pv/src/verify/helper.rs | 44 ++++++------ rust/pv/src/verify/test.rs | 11 ++- rust/pv/tests/add_secret_request.rs | 29 +++----- rust/pv/tests/cert_verifier.rs | 6 +- rust/pv_core/src/apdevice.rs | 12 ++-- rust/pv_core/src/confidential.rs | 3 +- rust/pv_core/src/lib.rs | 25 +++---- rust/pv_core/src/policy.rs | 16 ++--- rust/pv_core/src/utils.rs | 14 ++-- rust/pv_core/src/uvattest.rs | 7 +- rust/pv_core/src/uvdevice.rs | 14 ++-- rust/pv_core/src/uvdevice/attest.rs | 6 +- rust/pv_core/src/uvdevice/ffi.rs | 3 +- rust/pv_core/src/uvdevice/info.rs | 12 ++-- rust/pv_core/src/uvdevice/retr_secret.rs | 10 +-- rust/pv_core/src/uvdevice/secret.rs | 17 ++--- rust/pv_core/src/uvdevice/secret_list.rs | 30 ++++---- rust/pv_core/src/uvdevice/test.rs | 13 ++-- rust/pv_core/src/uvsecret.rs | 20 +++--- rust/pvapconfig/build.rs | 5 +- rust/pvapconfig/src/ap.rs | 11 +-- rust/pvapconfig/src/config.rs | 11 +-- rust/pvapconfig/src/helper.rs | 6 +- rust/pvapconfig/src/main.rs | 7 +- rust/pvattest/build.rs | 5 +- rust/pvattest/src/additional.rs | 6 +- rust/pvattest/src/cli.rs | 6 +- rust/pvattest/src/cmd/check.rs | 26 +++---- rust/pvattest/src/cmd/check/firmware.rs | 6 +- rust/pvattest/src/cmd/check/host_key.rs | 17 +++-- rust/pvattest/src/cmd/check/secret_store.rs | 9 +-- rust/pvattest/src/cmd/create.rs | 18 +++-- rust/pvattest/src/cmd/perform.rs | 16 ++--- rust/pvattest/src/cmd/verify.rs | 22 +++--- rust/pvattest/src/exchange.rs | 17 ++--- rust/pvattest/src/main.rs | 3 +- rust/pvebc/src/cli.rs | 7 +- rust/pvebc/src/ebc_utils.rs | 4 +- rust/pvebc/src/main.rs | 26 +++---- rust/pvimg/examples/create-sehdr/main.rs | 28 +++----- rust/pvimg/examples/tamper_pvimg/main.rs | 20 +++--- rust/pvimg/src/cli.rs | 11 +-- rust/pvimg/src/cmd/common.rs | 3 +- rust/pvimg/src/cmd/create.rs | 30 ++++---- rust/pvimg/src/cmd/info.rs | 12 ++-- rust/pvimg/src/cmd/test.rs | 15 ++-- rust/pvimg/src/main.rs | 3 +- rust/pvimg/src/pv_utils/error.rs | 3 +- rust/pvimg/src/pv_utils/layout.rs | 19 +++-- rust/pvimg/src/pv_utils/misc.rs | 6 +- rust/pvimg/src/pv_utils/psw.rs | 6 +- rust/pvimg/src/pv_utils/se_hdr/brb.rs | 43 +++++------- rust/pvimg/src/pv_utils/se_hdr/builder.rs | 37 +++++----- rust/pvimg/src/pv_utils/se_hdr/flags.rs | 4 +- rust/pvimg/src/pv_utils/se_hdr/hdr_v1.rs | 69 ++++++++----------- rust/pvimg/src/pv_utils/se_hdr/keys.rs | 22 +++--- rust/pvimg/src/pv_utils/secured_comp.rs | 31 ++++----- rust/pvimg/src/pv_utils/serializing.rs | 13 ++-- rust/pvimg/src/pv_utils/uv_keys.rs | 3 +- rust/pvimg/src/pv_utils/uvdata.rs | 11 ++- rust/pvimg/src/pv_utils/uvdata_builder.rs | 8 +-- rust/pvimg/src/se_img.rs | 40 ++++++----- rust/pvimg/src/se_img_comps.rs | 33 +++++---- rust/pvimg/src/se_img_comps/bootloader.rs | 35 +++++----- rust/pvimg/src/se_img_comps/bootloader/ipl.rs | 6 +- .../se_img_comps/bootloader/stage3a_defs.rs | 3 +- .../se_img_comps/bootloader/stage3b_defs.rs | 3 +- rust/pvimg/src/se_img_comps/ipib.rs | 3 +- rust/pvimg/src/se_img_comps/metadata.rs | 9 ++- rust/pvimg/src/se_img_comps/ramdisk.rs | 6 +- rust/pvimg/src/se_img_comps/sehdr.rs | 3 +- rust/pvimg/src/se_img_comps/shortpsw.rs | 3 +- rust/pvimg/src/se_img_comps/stage3a.rs | 3 +- rust/pvimg/src/se_img_comps/stage3b.rs | 3 +- rust/pvinfo/build.rs | 5 +- rust/pvinfo/src/handlers.rs | 11 +-- rust/pvinfo/src/io_utils.rs | 16 +++-- rust/pvinfo/src/main.rs | 6 +- rust/pvinfo/src/pvinfo.rs | 13 ++-- rust/pvinfo/src/se_status.rs | 9 +-- rust/pvsecret/build.rs | 3 +- rust/pvsecret/src/cli.rs | 4 +- rust/pvsecret/src/cmd.rs | 6 +- rust/pvsecret/src/cmd/add.rs | 13 ++-- rust/pvsecret/src/cmd/create.rs | 27 +++----- rust/pvsecret/src/cmd/list.rs | 3 +- rust/pvsecret/src/cmd/retr.rs | 12 ++-- rust/pvsecret/src/cmd/verify.rs | 9 ++- rust/pvsecret/src/main.rs | 3 +- rust/pvverify/build.rs | 5 +- rust/utils/src/cli.rs | 18 ++--- rust/utils/src/exit_code.rs | 3 +- rust/utils/src/file.rs | 15 ++-- rust/utils/src/hexslice.rs | 3 +- rust/utils/src/hostname.rs | 6 +- rust/utils/src/lib.rs | 24 +++---- rust/utils/src/tmpfile.rs | 8 +-- 120 files changed, 825 insertions(+), 900 deletions(-) diff --git a/rust/cpacfinfo/src/main.rs b/rust/cpacfinfo/src/main.rs index 5cdd50f8..33a21181 100644 --- a/rust/cpacfinfo/src/main.rs +++ b/rust/cpacfinfo/src/main.rs @@ -7,11 +7,11 @@ mod msa; mod query; mod stfle; -use anyhow::bail; -use anyhow::Result as anyhowRes; -use clap::Parser; use std::io::ErrorKind; use std::result::Result::Ok; + +use anyhow::{bail, Result as anyhowRes}; +use clap::Parser; use utils::print_version; use crate::cli::{Cli, Format}; diff --git a/rust/cpacfinfo/src/msa.rs b/rust/cpacfinfo/src/msa.rs index 8b9a7147..4dd3165d 100644 --- a/rust/cpacfinfo/src/msa.rs +++ b/rust/cpacfinfo/src/msa.rs @@ -2,11 +2,13 @@ // // Copyright IBM Corp. 2024 -use crate::cli::Cli; use core::fmt::{Display, Formatter, Result}; + use serde::{Serialize, Serializer}; use utils::HexSlice; +use crate::cli::Cli; + /// Number of total function codes (0 to 127) pub const NUMBER_FUNC_CODES: usize = 128; diff --git a/rust/cpacfinfo/src/query.rs b/rust/cpacfinfo/src/query.rs index f9855823..712e453e 100644 --- a/rust/cpacfinfo/src/query.rs +++ b/rust/cpacfinfo/src/query.rs @@ -3,15 +3,13 @@ // Copyright IBM Corp. 2024 use std::fs::File; -use std::io::Error; -use std::io::Read; +use std::io::{Error, Read}; use std::ops::Index; use std::result::Result; use zerocopy::FromBytes; -use crate::msa::InstructionKind; -use crate::msa::QueryAuthInfo; +use crate::msa::{InstructionKind, QueryAuthInfo}; /// Path to sysfs in which the query and qai informations are fetched from const SYSFS_PATH: &str = "/sys/devices/system/cpu/cpacf/"; diff --git a/rust/pv/examples/hash_hkd/main.rs b/rust/pv/examples/hash_hkd/main.rs index 49dcd9e4..ad618fe5 100644 --- a/rust/pv/examples/hash_hkd/main.rs +++ b/rust/pv/examples/hash_hkd/main.rs @@ -1,13 +1,12 @@ #![allow(missing_docs)] -use pv::request::EcPubKeyCoord; -use pv_core::misc::encode_hex; -use s390_pv as pv; - use std::env::args; use pv::misc::{read_certs, read_file}; +use pv::request::EcPubKeyCoord; use pv::{Error, Result}; +use pv_core::misc::encode_hex; +use s390_pv as pv; fn main() -> Result<()> { let hkd = args().nth(1).expect("Expect one Host-key document"); diff --git a/rust/pv/src/brcb.rs b/rust/pv/src/brcb.rs index b1459cef..4ae4a56d 100644 --- a/rust/pv/src/brcb.rs +++ b/rust/pv/src/brcb.rs @@ -2,10 +2,9 @@ // // Copyright IBM Corp. 2023, 2024 -use std::{ - io::{Read, Seek, SeekFrom::Current}, - mem::size_of, -}; +use std::io::SeekFrom::Current; +use std::io::{Read, Seek}; +use std::mem::size_of; use log::{debug, warn}; use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U32, U64}; diff --git a/rust/pv/src/crypto.rs b/rust/pv/src/crypto.rs index 27bd9786..3ad66a88 100644 --- a/rust/pv/src/crypto.rs +++ b/rust/pv/src/crypto.rs @@ -2,25 +2,28 @@ // // Copyright IBM Corp. 2023, 2024 -use std::{convert::TryInto, fmt::Display, ops::Range}; +use std::convert::TryInto; +use std::fmt::Display; +use std::ops::Range; use enum_dispatch::enum_dispatch; -use openssl::{ - derive::Deriver, - ec::{EcGroup, EcKey}, - hash::{DigestBytes, MessageDigest}, - md::MdRef, - nid::Nid, - pkey::{HasPublic, Id, PKey, PKeyRef, Private, Public}, - pkey_ctx::{HkdfMode, PkeyCtx}, - rand::rand_bytes, - rsa::Padding, - sign::{Signer, Verifier}, - symm::{decrypt_aead as openssl_decrypt_aead, encrypt_aead as openssl_encrypt_aead, Cipher}, +use openssl::derive::Deriver; +use openssl::ec::{EcGroup, EcKey}; +use openssl::hash::{DigestBytes, MessageDigest}; +use openssl::md::MdRef; +use openssl::nid::Nid; +use openssl::pkey::{HasPublic, Id, PKey, PKeyRef, Private, Public}; +use openssl::pkey_ctx::{HkdfMode, PkeyCtx}; +use openssl::rand::rand_bytes; +use openssl::rsa::Padding; +use openssl::sign::{Signer, Verifier}; +use openssl::symm::{ + decrypt_aead as openssl_decrypt_aead, encrypt_aead as openssl_encrypt_aead, Cipher, }; use pv_core::request::Confidential; -use crate::{error::Result, Error}; +use crate::error::Result; +use crate::Error; /// An AES256-GCM key that will purge itself out of the memory when going out of scope pub type Aes256GcmKey = Confidential<[u8; SymKeyType::AES_256_GCM_KEY_LEN]>; @@ -540,7 +543,8 @@ pub(crate) fn verify_signature( #[cfg(test)] mod tests { use super::*; - use crate::{get_test_asset, test_utils::*, PvCoreError}; + use crate::test_utils::*; + use crate::{get_test_asset, PvCoreError}; #[test] fn sign_ec() { diff --git a/rust/pv/src/lib.rs b/rust/pv/src/lib.rs index 77d15e05..c601bf6b 100644 --- a/rust/pv/src/lib.rs +++ b/rust/pv/src/lib.rs @@ -63,13 +63,11 @@ pub mod uv { pub mod attest { pub use pv_core::attest::*; - pub use crate::uvattest::{ - additional::AdditionalData, - arcb::{ - AttestationAuthenticated, AttestationFlags, AttestationRequest, AttestationVersion, - }, - attest::{AttestationItems, AttestationMeasurement}, + pub use crate::uvattest::additional::AdditionalData; + pub use crate::uvattest::arcb::{ + AttestationAuthenticated, AttestationFlags, AttestationRequest, AttestationVersion, }; + pub use crate::uvattest::attest::{AttestationItems, AttestationMeasurement}; } /// Definitions and functions to write objects in PEM format @@ -91,27 +89,22 @@ pub use crate::error::HkdVerifyErrorType; /// Functionalities to build UV requests pub mod request { - pub use crate::{ - brcb::{seek_se_hdr_start, BootHdrTags, SeImgMetaData}, - crypto::{ - decrypt_aead, derive_aes256_gcm_key, encrypt_aead, gen_ec_key, random_array, - AeadDecryptionResult, AeadEncryptionResult, Aes256GcmKey, Aes256XtsKey, SymKey, - SymKeyType, SHA_512_HASH_LEN, - }, - req::{EcPubKeyCoord, Encrypt, Keyslot, ReqEncrCtx, Request}, - verify::{CertVerifier, HkdVerifier, NoVerifyHkd}, + pub use crate::brcb::{seek_se_hdr_start, BootHdrTags, SeImgMetaData}; + pub use crate::crypto::{ + decrypt_aead, derive_aes256_gcm_key, encrypt_aead, gen_ec_key, random_array, + AeadDecryptionResult, AeadEncryptionResult, Aes256GcmKey, Aes256XtsKey, SymKey, SymKeyType, + SHA_512_HASH_LEN, }; + pub use crate::req::{EcPubKeyCoord, Encrypt, Keyslot, ReqEncrCtx, Request}; + pub use crate::verify::{CertVerifier, HkdVerifier, NoVerifyHkd}; /// Reexports some useful OpenSSL symbols pub mod openssl { - pub use openssl::{ - error::ErrorStack, - hash::DigestBytes, - nid::Nid, - pkey, - sha::{Sha256, Sha512}, - x509, - }; + pub use openssl::error::ErrorStack; + pub use openssl::hash::DigestBytes; + pub use openssl::nid::Nid; + pub use openssl::sha::{Sha256, Sha512}; + pub use openssl::{pkey, x509}; // rust-OpenSSL does not define these NIDs #[allow(missing_docs)] pub const NID_ED25519: Nid = Nid::from_raw(openssl_sys::NID_ED25519); @@ -120,7 +113,6 @@ pub mod request { } pub use pv_core::request::*; - pub use pv_core::PolicyReference; } @@ -128,11 +120,9 @@ pub mod request { pub mod secret { pub use pv_core::secret::*; - pub use crate::uvsecret::{ - asrcb::{AddSecretFlags, AddSecretRequest, AddSecretVersion}, - ext_secret::ExtSecret, - guest_secret::GuestSecret, - retr_secret::{IbmProtectedKey, RetrievedSecret}, - user_data::verify_asrcb_and_get_user_data, - }; + pub use crate::uvsecret::asrcb::{AddSecretFlags, AddSecretRequest, AddSecretVersion}; + pub use crate::uvsecret::ext_secret::ExtSecret; + pub use crate::uvsecret::guest_secret::GuestSecret; + pub use crate::uvsecret::retr_secret::{IbmProtectedKey, RetrievedSecret}; + pub use crate::uvsecret::user_data::verify_asrcb_and_get_user_data; } diff --git a/rust/pv/src/openssl_extensions/akid.rs b/rust/pv/src/openssl_extensions/akid.rs index 6038f766..ac9f800d 100644 --- a/rust/pv/src/openssl_extensions/akid.rs +++ b/rust/pv/src/openssl_extensions/akid.rs @@ -2,11 +2,11 @@ // // Copyright IBM Corp. 2023 +use std::ffi::c_int; use std::fmt; use foreign_types::{foreign_type, ForeignType, ForeignTypeRef}; use openssl::x509::{X509CrlRef, X509Ref}; -use std::ffi::c_int; mod ffi { extern "C" { @@ -99,9 +99,8 @@ impl AkidExtension for X509CrlRef { #[cfg(test)] mod test { - use crate::test_utils::load_gen_cert; - use super::*; + use crate::test_utils::load_gen_cert; #[test] fn akid() { diff --git a/rust/pv/src/openssl_extensions/bio.rs b/rust/pv/src/openssl_extensions/bio.rs index 73528eed..b63b857e 100644 --- a/rust/pv/src/openssl_extensions/bio.rs +++ b/rust/pv/src/openssl_extensions/bio.rs @@ -3,10 +3,12 @@ // Copyright IBM Corp. 2024 use core::slice; +use std::ffi::c_int; +use std::marker::PhantomData; +use std::ptr; + use openssl::error::ErrorStack; use openssl_sys::BIO_new_mem_buf; -use std::ffi::c_int; -use std::{marker::PhantomData, ptr}; pub struct BioMem(*mut openssl_sys::BIO); diff --git a/rust/pv/src/openssl_extensions/crl.rs b/rust/pv/src/openssl_extensions/crl.rs index 3affd68b..5f2ba9b0 100644 --- a/rust/pv/src/openssl_extensions/crl.rs +++ b/rust/pv/src/openssl_extensions/crl.rs @@ -1,16 +1,13 @@ // SPDX-License-Identifier: MIT // // Copyright IBM Corp. 2023 -pub use crate::openssl_extensions::stackable_crl::*; use foreign_types::{ForeignType, ForeignTypeRef}; -use openssl::{ - error::ErrorStack, - stack::{Stack, StackRef}, - x509::{ - store::{X509StoreBuilderRef, X509StoreRef}, - X509CrlRef, X509NameRef, X509Ref, X509StoreContextRef, X509, - }, -}; +use openssl::error::ErrorStack; +use openssl::stack::{Stack, StackRef}; +use openssl::x509::store::{X509StoreBuilderRef, X509StoreRef}; +use openssl::x509::{X509CrlRef, X509NameRef, X509Ref, X509StoreContextRef, X509}; + +pub use crate::openssl_extensions::stackable_crl::*; pub fn opt_to_ptr(o: Option<&T>) -> *mut T::CType { match o { diff --git a/rust/pv/src/openssl_extensions/stackable_crl.rs b/rust/pv/src/openssl_extensions/stackable_crl.rs index 12a9f9de..6fc0a0be 100644 --- a/rust/pv/src/openssl_extensions/stackable_crl.rs +++ b/rust/pv/src/openssl_extensions/stackable_crl.rs @@ -2,15 +2,15 @@ // // Copyright IBM Corp. 2023 -use crate::openssl_extensions::bio::BioMemSlice; -use foreign_types::{ForeignType, ForeignTypeRef}; -use openssl::{ - error::ErrorStack, - stack::Stackable, - x509::{X509Crl, X509CrlRef}, -}; use std::ptr; +use foreign_types::{ForeignType, ForeignTypeRef}; +use openssl::error::ErrorStack; +use openssl::stack::Stackable; +use openssl::x509::{X509Crl, X509CrlRef}; + +use crate::openssl_extensions::bio::BioMemSlice; + #[derive(Debug)] pub struct StackableX509Crl(*mut openssl_sys::X509_CRL); diff --git a/rust/pv/src/pem_utils.rs b/rust/pv/src/pem_utils.rs index 25c93667..fbca0a55 100644 --- a/rust/pv/src/pem_utils.rs +++ b/rust/pv/src/pem_utils.rs @@ -2,18 +2,19 @@ // // Copyright IBM Corp. 2024 -use crate::Result; -use crate::{openssl_extensions::BioMem, Error}; +use std::ffi::{c_char, CString}; +use std::fmt::Display; + use openssl::error::ErrorStack; use pv_core::request::Confidential; -use std::{ - ffi::{c_char, CString}, - fmt::Display, -}; + +use crate::openssl_extensions::BioMem; +use crate::{Error, Result}; mod ffi { - use openssl_sys::BIO; use std::ffi::{c_char, c_int, c_long, c_uchar}; + + use openssl_sys::BIO; extern "C" { pub fn PEM_write_bio( bio: *mut BIO, @@ -141,8 +142,8 @@ impl Pem { let inner_pem = InnerPem::new(name, header, data.as_ref())?; - // Create the PEM format eagerly so that to_string/display cannot fail because of ASCII or OpenSSL Errors - // Both error should be very unlikely + // Create the PEM format eagerly so that to_string/display cannot fail because of ASCII or + // OpenSSL Errors Both error should be very unlikely // OpenSSL should be able to create PEM if there is enough memory and produce a non-null // terminated ASCII-string // Unwrap succeeds it's all ASCII diff --git a/rust/pv/src/req.rs b/rust/pv/src/req.rs index d132ecc2..10fb8b31 100644 --- a/rust/pv/src/req.rs +++ b/rust/pv/src/req.rs @@ -3,27 +3,22 @@ // Copyright IBM Corp. 2023 use std::mem::size_of; -use openssl::{ - bn::{BigNum, BigNumContext}, - ec::{EcGroup, EcGroupRef, EcKey, EcPointRef}, - error::ErrorStack, - hash::{DigestBytes, MessageDigest}, - nid::Nid, - pkey::{PKey, PKeyRef, Private, Public}, -}; +use openssl::bn::{BigNum, BigNumContext}; +use openssl::ec::{EcGroup, EcGroupRef, EcKey, EcPointRef}; +use openssl::error::ErrorStack; +use openssl::hash::{DigestBytes, MessageDigest}; +use openssl::nid::Nid; +use openssl::pkey::{PKey, PKeyRef, Private, Public}; use pv_core::request::{RequestMagic, RequestVersion}; use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U32}; -use crate::{ - assert_size, - crypto::{ - decrypt_aead, derive_aes256_gcm_key, encrypt_aead, gen_ec_key, hash, random_array, - AeadEncryptionResult, SymKey, SymKeyType, - }, - misc::to_u32, - request::Confidential, - Error, Result, +use crate::crypto::{ + decrypt_aead, derive_aes256_gcm_key, encrypt_aead, gen_ec_key, hash, random_array, + AeadEncryptionResult, SymKey, SymKeyType, }; +use crate::misc::to_u32; +use crate::request::Confidential; +use crate::{assert_size, Error, Result}; /// Encrypt a _secret_ using self and a given private key. pub trait Encrypt { /// Encrypts `secret` using `self` and `priv_key` the encryption. @@ -520,7 +515,9 @@ impl<'a> BinReqValues<'a> { #[cfg(test)] mod tests { use super::*; - use crate::{get_test_asset, request::SymKey, test_utils::*}; + use crate::get_test_asset; + use crate::request::SymKey; + use crate::test_utils::*; static TEST_MAGIC: [u8; 8] = 0x12345689abcdef00u64.to_be_bytes(); diff --git a/rust/pv/src/test_utils.rs b/rust/pv/src/test_utils.rs index 072fe6d8..91caffc8 100644 --- a/rust/pv/src/test_utils.rs +++ b/rust/pv/src/test_utils.rs @@ -4,19 +4,15 @@ // DO NOT USE ANY OF THESE ITEMS IN PRODUCTION CODE // USED FOR INTERNAL UNIT AND FVT TESTING ONLY!!! -use std::{ - fs, - path::{Path, PathBuf}, -}; +use std::fs; +use std::path::{Path, PathBuf}; -use openssl::{ - bn::BigNum, - ec::{EcGroup, EcKey}, - error::ErrorStack, - nid::Nid, - pkey::{PKey, Private, Public}, - x509::{X509Crl, X509}, -}; +use openssl::bn::BigNum; +use openssl::ec::{EcGroup, EcKey}; +use openssl::error::ErrorStack; +use openssl::nid::Nid; +use openssl::pkey::{PKey, Private, Public}; +use openssl::x509::{X509Crl, X509}; /// TEST ONLY! Loads the specified asset into the binary at compile time. /// diff --git a/rust/pv/src/utils.rs b/rust/pv/src/utils.rs index 7d9e2e4b..3743c171 100644 --- a/rust/pv/src/utils.rs +++ b/rust/pv/src/utils.rs @@ -1,11 +1,10 @@ // SPDX-License-Identifier: MIT // // Copyright IBM Corp. 2023 +use openssl::error::ErrorStack; +use openssl::x509::{X509Crl, X509}; + use crate::{Error, Result}; -use openssl::{ - error::ErrorStack, - x509::{X509Crl, X509}, -}; /// Read all CRLs from the buffer and parse them into a vector. /// diff --git a/rust/pv/src/uvattest/additional.rs b/rust/pv/src/uvattest/additional.rs index 91dfc732..a056e096 100644 --- a/rust/pv/src/uvattest/additional.rs +++ b/rust/pv/src/uvattest/additional.rs @@ -2,14 +2,13 @@ // // Copyright IBM Corp. 2024 -use serde::Serialize; use std::fmt::Display; -use crate::req::Keyslot; -use crate::static_assert; -use crate::{Error, Result}; +use serde::Serialize; use super::arcb::AttestationFlags; +use crate::req::Keyslot; +use crate::{static_assert, Error, Result}; /// Hash for additional-data stuff used for parsing [`AdditionalData`] pub(super) const PHKH_SIZE: u32 = 0x20; diff --git a/rust/pv/src/uvattest/arcb.rs b/rust/pv/src/uvattest/arcb.rs index 853f2232..19ea4d93 100644 --- a/rust/pv/src/uvattest/arcb.rs +++ b/rust/pv/src/uvattest/arcb.rs @@ -2,27 +2,20 @@ // // Copyright IBM Corp. 2024 -use openssl::pkey::{PKey, Public}; use std::mem::size_of; + +use openssl::pkey::{PKey, Public}; use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U32}; -use crate::{ - assert_size, - attest::{AttestationMagic, AttestationMeasAlg}, - crypto::random_array, - misc::Flags, - req::{Aad, BinReqValues, Keyslot, ReqEncrCtx}, - request::{Confidential, MagicValue, Request, RequestVersion, SymKey, Zeroize}, - static_assert, - uv::UvFlags, - Error, Result, -}; - -use super::{ - additional::{FW_STATE_SIZE, PHKH_SIZE, SECRET_STORE_HASH_SIZE}, - AttNonce, -}; - +use super::additional::{FW_STATE_SIZE, PHKH_SIZE, SECRET_STORE_HASH_SIZE}; +use super::AttNonce; +use crate::attest::{AttestationMagic, AttestationMeasAlg}; +use crate::crypto::random_array; +use crate::misc::Flags; +use crate::req::{Aad, BinReqValues, Keyslot, ReqEncrCtx}; +use crate::request::{Confidential, MagicValue, Request, RequestVersion, SymKey, Zeroize}; +use crate::uv::UvFlags; +use crate::{assert_size, static_assert, Error, Result}; #[cfg(doc)] use crate::{ request::SymKeyType, @@ -419,8 +412,9 @@ impl Zeroize for ReqConfData { #[cfg(test)] mod test { use super::*; - - use crate::{get_test_asset, request::SymKey, test_utils::get_test_keys}; + use crate::get_test_asset; + use crate::request::SymKey; + use crate::test_utils::get_test_keys; const ARPK: [u8; 32] = [0x17; 32]; const NONCE: [u8; 16] = [0xab; 16]; diff --git a/rust/pv/src/uvattest/attest.rs b/rust/pv/src/uvattest/attest.rs index 52160794..d9443016 100644 --- a/rust/pv/src/uvattest/attest.rs +++ b/rust/pv/src/uvattest/attest.rs @@ -2,20 +2,21 @@ // // Copyright IBM Corp. 2024 -use super::AttNonce; -use crate::{ - attest::AttestationMeasAlg, brcb::BootHdrTags, crypto::calculate_hmac, request::Confidential, - uv::ConfigUid, Result, -}; -use openssl::{ - hash::MessageDigest, - pkey::{PKeyRef, Private}, -}; use std::mem::size_of; + +use openssl::hash::MessageDigest; +use openssl::pkey::{PKeyRef, Private}; use zerocopy::{BigEndian, IntoBytes, U16, U32}; +use super::AttNonce; +use crate::attest::AttestationMeasAlg; #[cfg(doc)] use crate::attest::AttestationRequest; +use crate::brcb::BootHdrTags; +use crate::crypto::calculate_hmac; +use crate::request::Confidential; +use crate::uv::ConfigUid; +use crate::Result; /// Holds the data to be measured. /// @@ -151,9 +152,10 @@ impl From> for AttestationMeasurement { #[cfg(test)] mod test { - use super::*; use openssl::pkey::PKey; + use super::*; + const M_KEY: [u8; 64] = [0x41; 64]; const BOOT_HDR_TAGS: BootHdrTags = BootHdrTags::new([1; 64], [2; 64], [3; 64], [4; 16]); const CUID: [u8; 16] = [5; 16]; diff --git a/rust/pv/src/uvsecret/asrcb.rs b/rust/pv/src/uvsecret/asrcb.rs index c7d4ce6d..e571aada 100644 --- a/rust/pv/src/uvsecret/asrcb.rs +++ b/rust/pv/src/uvsecret/asrcb.rs @@ -2,24 +2,23 @@ // // Copyright IBM Corp. 2023 -use super::{guest_secret::ListableSecretHdr, user_data::UserData}; -use crate::{ - assert_size, - crypto::{hkdf_rfc_5869, AeadEncryptionResult}, - misc::Flags, - req::{Aad, BinReqValues, Keyslot, ReqEncrCtx}, - request::{BootHdrTags, Confidential, Request}, - secret::{ExtSecret, GuestSecret}, - uv::{ConfigUid, UvFlags}, - Result, -}; -use openssl::{ - md::Md, - pkey::{PKey, Private, Public}, -}; -use pv_core::{request::RequestVersion, secret::AddSecretMagic, uv::SecretId}; +use openssl::md::Md; +use openssl::pkey::{PKey, Private, Public}; +use pv_core::request::RequestVersion; +use pv_core::secret::AddSecretMagic; +use pv_core::uv::SecretId; use zerocopy::{Immutable, IntoBytes}; +use super::guest_secret::ListableSecretHdr; +use super::user_data::UserData; +use crate::crypto::{hkdf_rfc_5869, AeadEncryptionResult}; +use crate::misc::Flags; +use crate::req::{Aad, BinReqValues, Keyslot, ReqEncrCtx}; +use crate::request::{BootHdrTags, Confidential, Request}; +use crate::secret::{ExtSecret, GuestSecret}; +use crate::uv::{ConfigUid, UvFlags}; +use crate::{assert_size, Result}; + /// Authenticated data w/o user data #[repr(C)] #[derive(Debug, Clone, Copy, IntoBytes, Immutable)] diff --git a/rust/pv/src/uvsecret/guest_secret.rs b/rust/pv/src/uvsecret/guest_secret.rs index a4c5e0e1..5b720e01 100644 --- a/rust/pv/src/uvsecret/guest_secret.rs +++ b/rust/pv/src/uvsecret/guest_secret.rs @@ -2,31 +2,25 @@ // // Copyright IBM Corp. 2023 -#[allow(unused_imports)] // used for more convenient docstring -use super::asrcb::AddSecretRequest; -use crate::{ - assert_size, - crypto::{hash, random_array, SymKeyType}, - request::{ - openssl::{NID_ED25519, NID_ED448}, - Confidential, - }, - uv::{ - AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListableSecretType, RetrievableSecret, - RetrieveCmd, SecretId, - }, - Error, Result, -}; -use openssl::{ - hash::MessageDigest, - nid::Nid, - pkey::{Id, PKey, PKeyRef, Private}, -}; +use std::fmt::Display; + +use openssl::hash::MessageDigest; +use openssl::nid::Nid; +use openssl::pkey::{Id, PKey, PKeyRef, Private}; use pv_core::static_assert; use serde::{Deserialize, Serialize}; -use std::fmt::Display; -use zerocopy::{BigEndian, KnownLayout}; -use zerocopy::{FromBytes, Immutable, IntoBytes, U16, U32}; +use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U16, U32}; + +#[allow(unused_imports)] // used for more convenient docstring +use super::asrcb::AddSecretRequest; +use crate::crypto::{hash, random_array, SymKeyType}; +use crate::request::openssl::{NID_ED25519, NID_ED448}; +use crate::request::Confidential; +use crate::uv::{ + AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListableSecretType, RetrievableSecret, + RetrieveCmd, SecretId, +}; +use crate::{assert_size, Error, Result}; const ASSOC_SECRET_SIZE: usize = 32; const CCK_SIZE: usize = 32; @@ -476,13 +470,13 @@ impl UpdateCckHdr { #[cfg(test)] mod test { - use super::HmacShaSizes as HmacSizes; - use super::RetrievableSecret::*; - use super::*; use openssl::ec::{EcGroup, EcKey}; use pv_core::uv::AesSizes; use serde_test::{assert_tokens, Token}; + use super::RetrievableSecret::*; + use super::{HmacShaSizes as HmacSizes, *}; + #[test] fn association() { let secret_value = [0x11; 32]; diff --git a/rust/pv/src/uvsecret/retr_secret.rs b/rust/pv/src/uvsecret/retr_secret.rs index 75599c20..7c78592a 100644 --- a/rust/pv/src/uvsecret/retr_secret.rs +++ b/rust/pv/src/uvsecret/retr_secret.rs @@ -2,15 +2,15 @@ // // Copyright IBM Corp. 2024 -use crate::{crypto::SymKeyType, pem::Pem, uvsecret::guest_secret::MAX_SIZE_PLAIN_PAYLOAD, Result}; - use log::warn; -use pv_core::{ - request::Confidential, - uv::{ListableSecretType, RetrievableSecret, RetrieveCmd}, -}; -use zerocopy::BigEndian; -use zerocopy::{FromBytes, U16}; +use pv_core::request::Confidential; +use pv_core::uv::{ListableSecretType, RetrievableSecret, RetrieveCmd}; +use zerocopy::{BigEndian, FromBytes, U16}; + +use crate::crypto::SymKeyType; +use crate::pem::Pem; +use crate::uvsecret::guest_secret::MAX_SIZE_PLAIN_PAYLOAD; +use crate::Result; /// An IBM Protected Key /// @@ -72,8 +72,8 @@ impl From for RetrievedSecret { match kind { ListableSecretType::Retrievable(RetrievableSecret::PlainText) => { - // Will not run into default, retrieve has a granularity of 16 bytes and 16 bytes is the - // minimum size + // Will not run into default, retrieve has a granularity of 16 bytes and 16 bytes is + // the minimum size let len = U16::::read_from_prefix(key.value()) .unwrap_or_default() .0 @@ -81,8 +81,8 @@ impl From for RetrievedSecret { // Test if the plain text secret has a size: // 1. len <= 8190 - // 2. first two bytes are max 15 less than buffer-size+2 i.e. smaller than the - // block length + // 2. first two bytes are max 15 less than buffer-size+2 i.e. smaller than the block + // length // 3. bytes after len + 2 are zero match len <= MAX_SIZE_PLAIN_PAYLOAD && key.value().len() - (len + 2) < SymKeyType::AES_256_GCM_BLOCK_LEN @@ -148,9 +148,10 @@ impl RetrievedSecret { #[cfg(test)] mod test { - use super::*; use pv_core::uv::*; + use super::*; + fn mk_retr(secret: &[u8]) -> RetrievedSecret { let entry = SecretEntry::new( 0, diff --git a/rust/pv/src/uvsecret/user_data.rs b/rust/pv/src/uvsecret/user_data.rs index 56944dad..686afb37 100644 --- a/rust/pv/src/uvsecret/user_data.rs +++ b/rust/pv/src/uvsecret/user_data.rs @@ -2,21 +2,17 @@ // // Copyright IBM Corp. 2024 -use crate::assert_size; -use crate::{ - crypto::{sign_msg, verify_signature}, - req::BinReqValues, - request::{ - openssl::pkey::{HasParams, HasPublic, Id, PKey, PKeyRef, Private, Public}, - RequestMagic, - }, - secret::{AddSecretMagic, AddSecretRequest, AddSecretVersion, UserDataType}, - Error, Result, -}; use openssl::hash::MessageDigest; use openssl::nid::Nid; use zerocopy::{BigEndian, FromBytes, IntoBytes, KnownLayout, U16}; +use crate::crypto::{sign_msg, verify_signature}; +use crate::req::BinReqValues; +use crate::request::openssl::pkey::{HasParams, HasPublic, Id, PKey, PKeyRef, Private, Public}; +use crate::request::RequestMagic; +use crate::secret::{AddSecretMagic, AddSecretRequest, AddSecretVersion, UserDataType}; +use crate::{assert_size, Error, Result}; + /// User data. /// /// User defined data can be: @@ -380,7 +376,8 @@ impl From for Vec { #[cfg(test)] mod test { use super::*; - use crate::{get_test_asset, test_utils::get_test_keys}; + use crate::get_test_asset; + use crate::test_utils::get_test_keys; #[test] fn sign_null() { diff --git a/rust/pv/src/verify.rs b/rust/pv/src/verify.rs index c5e0c4ba..a865e85c 100644 --- a/rust/pv/src/verify.rs +++ b/rust/pv/src/verify.rs @@ -2,22 +2,22 @@ // // Copyright IBM Corp. 2023 -use crate::openssl_extensions::{StackableX509Crl, X509StoreContextExtension, X509StoreExtension}; use core::slice; +use std::path::Path; + +#[cfg(not(test))] +use helper::download_first_crl_from_x509; use log::{debug, trace}; use openssl::error::ErrorStack; use openssl::stack::Stack; use openssl::x509::store::X509Store; use openssl::x509::{CrlStatus, X509NameRef, X509Ref, X509StoreContext, X509StoreContextRef, X509}; -use std::path::Path; - -#[cfg(not(test))] -use helper::download_first_crl_from_x509; #[cfg(test)] use test::download_first_crl_from_x509; use crate::error::bail_hkd_verify; use crate::misc::{read_certs, read_file}; +use crate::openssl_extensions::{StackableX509Crl, X509StoreContextExtension, X509StoreExtension}; use crate::Result; mod helper; @@ -167,7 +167,8 @@ 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 6ff8e292..26957670 100644 --- a/rust/pv/src/verify/helper.rs +++ b/rust/pv/src/verify/helper.rs @@ -2,27 +2,28 @@ // // Copyright IBM Corp. 2023 +use std::cmp::Ordering; +use std::ffi::c_int; +use std::path::Path; +use std::str::from_utf8; + +use log::debug; +use openssl::asn1::{Asn1Time, Asn1TimeRef}; +use openssl::error::ErrorStack; +use openssl::nid::Nid; +use openssl::ssl::SslFiletype; +use openssl::stack::Stack; +use openssl::x509::store::{File, X509Lookup, X509StoreBuilder, X509StoreRef}; +use openssl::x509::verify::{X509VerifyFlags, X509VerifyParam}; +use openssl::x509::{ + X509CrlRef, X509Name, X509NameRef, X509PurposeId, X509Ref, X509StoreContext, + X509StoreContextRef, X509VerifyResult, X509, +}; + use crate::error::bail_hkd_verify; use crate::openssl_extensions::{AkidCheckResult, AkidExtension}; use crate::HkdVerifyErrorType::*; use crate::{Error, Result}; -use log::debug; -use openssl::{ - asn1::{Asn1Time, Asn1TimeRef}, - error::ErrorStack, - nid::Nid, - ssl::SslFiletype, - stack::Stack, - x509::{ - store::{File, X509Lookup, X509StoreBuilder, X509StoreRef}, - verify::{X509VerifyFlags, X509VerifyParam}, - X509CrlRef, X509Name, X509NameRef, X509PurposeId, X509Ref, X509StoreContext, - X509StoreContextRef, X509VerifyResult, X509, - }, -}; -use std::path::Path; -use std::str::from_utf8; -use std::{cmp::Ordering, ffi::c_int}; /// Minimum security level for the keys/certificates used to establish a chain of /// trust (see @@ -306,9 +307,11 @@ pub fn x509_dist_points(cert: &X509Ref) -> Vec { /// CRL not available at all URIs and unexpected format at all URIs are mapped to Ok(None) #[cfg(not(test))] pub fn download_first_crl_from_x509(cert: &X509Ref) -> Result>> { - use crate::utils::read_crls; - use curl::easy::{Easy2, Handler, WriteError}; use std::time::Duration; + + use curl::easy::{Easy2, Handler, WriteError}; + + use crate::utils::read_crls; const CRL_TIMEOUT_MAX: Duration = Duration::from_secs(3); struct Buf(Vec); @@ -397,9 +400,10 @@ pub fn armonk_locality_fixup(subject: &X509NameRef) -> Option { /// tests for some private functions mod test { + use std::time::{Duration, SystemTime}; + use super::*; use crate::test_utils::*; - use std::time::{Duration, SystemTime}; fn sys_to_asn1_time(syst: SystemTime) -> Asn1Time { let secs = syst diff --git a/rust/pv/src/verify/test.rs b/rust/pv/src/verify/test.rs index 71495626..74c760f5 100644 --- a/rust/pv/src/verify/test.rs +++ b/rust/pv/src/verify/test.rs @@ -4,12 +4,17 @@ #![cfg(test)] -use super::{helper, helper::*, *}; -use crate::{utils::read_crls, Error, HkdVerifyErrorType::*}; -use openssl::{stack::Stack, x509::X509Crl}; use std::path::Path; +use openssl::stack::Stack; +use openssl::x509::X509Crl; + +use super::helper::*; +use super::{helper, *}; use crate::test_utils::*; +use crate::utils::read_crls; +use crate::Error; +use crate::HkdVerifyErrorType::*; // Mock function pub fn download_first_crl_from_x509(cert: &X509Ref) -> Result>> { diff --git a/rust/pv/tests/add_secret_request.rs b/rust/pv/tests/add_secret_request.rs index c576a7a3..9d2f9cc8 100644 --- a/rust/pv/tests/add_secret_request.rs +++ b/rust/pv/tests/add_secret_request.rs @@ -3,25 +3,18 @@ // Copyright IBM Corp. 2023 #![allow(missing_docs)] -use openssl::{ - ec::{EcGroup, EcKey}, - nid::Nid, - pkey::Private, -}; -use s390_pv::{ - get_test_asset, - request::{ - openssl::pkey::{PKey, Public}, - BootHdrTags, ReqEncrCtx, Request, SymKey, - }, - secret::{ - verify_asrcb_and_get_user_data, AddSecretFlags, AddSecretRequest, AddSecretVersion, - ExtSecret, GuestSecret, - }, - test_utils::get_test_keys, - uv::ConfigUid, - Result, +use openssl::ec::{EcGroup, EcKey}; +use openssl::nid::Nid; +use openssl::pkey::Private; +use s390_pv::request::openssl::pkey::{PKey, Public}; +use s390_pv::request::{BootHdrTags, ReqEncrCtx, Request, SymKey}; +use s390_pv::secret::{ + verify_asrcb_and_get_user_data, AddSecretFlags, AddSecretRequest, AddSecretVersion, ExtSecret, + GuestSecret, }; +use s390_pv::test_utils::get_test_keys; +use s390_pv::uv::ConfigUid; +use s390_pv::{get_test_asset, Result}; const TAGS: BootHdrTags = BootHdrTags::new([1; 64], [2; 64], [3; 64], [4; 16]); const CUID: ConfigUid = [0x42u8; 16]; diff --git a/rust/pv/tests/cert_verifier.rs b/rust/pv/tests/cert_verifier.rs index 04145748..56209e6b 100644 --- a/rust/pv/tests/cert_verifier.rs +++ b/rust/pv/tests/cert_verifier.rs @@ -3,10 +3,12 @@ // Copyright IBM Corp. 2023 #![allow(missing_docs)] +use std::ffi::c_int; + use s390_pv::request::CertVerifier; use s390_pv::test_utils::*; -use s390_pv::{Error, HkdVerifyErrorType::*}; -use std::ffi::c_int; +use s390_pv::Error; +use s390_pv::HkdVerifyErrorType::*; #[track_caller] fn verify_sign_error(exp_raw: c_int, obs: Error) { diff --git a/rust/pv_core/src/apdevice.rs b/rust/pv_core/src/apdevice.rs index 34b8e091..ac15d3e7 100644 --- a/rust/pv_core/src/apdevice.rs +++ b/rust/pv_core/src/apdevice.rs @@ -5,14 +5,12 @@ //! AP support functions // -use crate::{ - utils::{pv_guest_bit_set, read_file_string, write_file}, - Error, Result, -}; +use std::{fmt, thread, time}; + use regex::Regex; -use std::fmt; -use std::thread; -use std::time; + +use crate::utils::{pv_guest_bit_set, read_file_string, write_file}; +use crate::{Error, Result}; const PATH_SYS_DEVICES_AP: &str = "/sys/devices/ap"; diff --git a/rust/pv_core/src/confidential.rs b/rust/pv_core/src/confidential.rs index c9a04b19..203655ca 100644 --- a/rust/pv_core/src/confidential.rs +++ b/rust/pv_core/src/confidential.rs @@ -82,7 +82,8 @@ impl Zeroize for Vec { impl Zeroize for String { fn zeroize(&mut self) { - // SAFETY: The Vec zerorize function overwrites memory with the zero byte -> still valid UTF-8 + // SAFETY: The Vec zerorize function overwrites memory with the zero byte -> still valid + // UTF-8 unsafe { self.as_mut_vec().zeroize() }; } } diff --git a/rust/pv_core/src/lib.rs b/rust/pv_core/src/lib.rs index 2b272760..0d3134ef 100644 --- a/rust/pv_core/src/lib.rs +++ b/rust/pv_core/src/lib.rs @@ -13,7 +13,6 @@ mod uvdevice; mod uvsecret; pub use error::{Error, FileAccessErrorType, FileIoErrorType, Result}; - /// Early Boot Customization (EBC) utilities. /// /// This module provides types and functions for working with Early Boot @@ -28,13 +27,11 @@ pub mod attest { /// Miscellaneous functions and definitions pub mod misc { - pub use crate::utils::pv_guest_bit_set; - pub use crate::utils::{create_file, open_file}; - pub use crate::utils::{decode_hex, encode_hex, parse_hex}; - pub use crate::utils::{read, write}; - pub use crate::utils::{read_exact_file, read_file, read_file_string, write_file}; - pub use crate::utils::{to_u16, to_u32, try_parse_u128, try_parse_u64}; - pub use crate::utils::{Flags, Lsb0Flags64, Msb0Flags64}; + pub use crate::utils::{ + create_file, decode_hex, encode_hex, open_file, parse_hex, pv_guest_bit_set, read, + read_exact_file, read_file, read_file_string, to_u16, to_u32, try_parse_u128, + try_parse_u64, write, write_file, Flags, Lsb0Flags64, Msb0Flags64, + }; } /// Definitions and functions for interacting with the Ultravisor @@ -43,8 +40,9 @@ pub mod misc { /// [`crate::uv::UvCmd`] pub mod uv { pub use crate::uvdevice::attest::AttestationCmd; - pub use crate::uvdevice::retr_secret::RetrievableSecret; - pub use crate::uvdevice::retr_secret::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes}; + pub use crate::uvdevice::retr_secret::{ + AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, RetrievableSecret, + }; pub use crate::uvdevice::secret::{AddCmd, ListCmd, LockCmd, RetrieveCmd}; pub use crate::uvdevice::secret_list::{ListableSecretType, SecretEntry, SecretId, SecretList}; pub use crate::uvdevice::{ConfigUid, UvCmd, UvDevice, UvDeviceInfo, UvFlags, UvcSuccess}; @@ -77,15 +75,12 @@ pub mod request { /// Functionalities for reading add-secret requests pub mod secret { - pub use crate::uvsecret::AddSecretMagic; - pub use crate::uvsecret::UserDataType; + pub use crate::uvsecret::{AddSecretMagic, UserDataType}; } /// Functionalities for the AP bus pub mod ap { - pub use crate::apdevice::Apqn; - pub use crate::apdevice::RE_QUEUE_DIR; - pub use crate::apdevice::{get_apqn_bind_state, set_apqn_bind_state}; + pub use crate::apdevice::{get_apqn_bind_state, set_apqn_bind_state, Apqn, RE_QUEUE_DIR}; /// AP modes pub mod apqn_mode { pub use crate::apdevice::ApqnMode::{self, *}; diff --git a/rust/pv_core/src/policy.rs b/rust/pv_core/src/policy.rs index 26640459..28fe8204 100644 --- a/rust/pv_core/src/policy.rs +++ b/rust/pv_core/src/policy.rs @@ -2,17 +2,17 @@ // // Copyright IBM Corp. +use std::fmt::{Display, Formatter, Result as Resfmt}; +use std::fs::File; +use std::os::unix::ffi::OsStrExt; +use std::path::{Path, PathBuf}; +use std::str::from_utf8; + +use zerocopy::{FromBytes, Immutable, IntoBytes}; + use crate::misc::encode_hex; use crate::utils::open_file; use crate::{Error, Result}; -use std::{ - fmt::{Display, Formatter, Result as Resfmt}, - fs::File, - os::unix::ffi::OsStrExt, - path::{Path, PathBuf}, - str::from_utf8, -}; -use zerocopy::{FromBytes, Immutable, IntoBytes}; const HASH_LEN: usize = 32; // UserDataType::Unsigned.max() returns 512 diff --git a/rust/pv_core/src/utils.rs b/rust/pv_core/src/utils.rs index b1bf08fb..97f8bff4 100644 --- a/rust/pv_core/src/utils.rs +++ b/rust/pv_core/src/utils.rs @@ -1,18 +1,14 @@ // SPDX-License-Identifier: MIT // // Copyright IBM Corp. 2023 -use std::{ - fs::File, - io::{Read, Write}, - path::Path, -}; +use std::fs::File; +use std::io::{Read, Write}; +use std::path::Path; use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, U64}; -use crate::{ - macros::{bail_spec, file_error}, - Error, FileAccessErrorType, Result, -}; +use crate::macros::{bail_spec, file_error}; +use crate::{Error, FileAccessErrorType, Result}; /// Trait that describes bitflags, represented by `T`. pub trait Flags: From + for<'a> From<&'a T> { diff --git a/rust/pv_core/src/uvattest.rs b/rust/pv_core/src/uvattest.rs index dc93d5f6..b675b84c 100644 --- a/rust/pv_core/src/uvattest.rs +++ b/rust/pv_core/src/uvattest.rs @@ -2,9 +2,10 @@ // // Copyright IBM Corp. 2024 -use crate::{request::MagicValue, Error}; -use zerocopy::U32; -use zerocopy::{BigEndian, ByteOrder}; +use zerocopy::{BigEndian, ByteOrder, U32}; + +use crate::request::MagicValue; +use crate::Error; /// The magic value used to identify an attestation request /// diff --git a/rust/pv_core/src/uvdevice.rs b/rust/pv_core/src/uvdevice.rs index b8dcec23..3e6529a8 100644 --- a/rust/pv_core/src/uvdevice.rs +++ b/rust/pv_core/src/uvdevice.rs @@ -3,20 +3,18 @@ // Copyright IBM Corp. 2023 #![allow(non_camel_case_types)] -use crate::FileAccessErrorType; -use crate::{Error, Result}; -use log::debug; -use std::{ - convert::TryInto, - fs::File, - os::unix::prelude::{AsRawFd, RawFd}, -}; +use std::convert::TryInto; +use std::fs::File; +use std::os::unix::prelude::{AsRawFd, RawFd}; #[cfg(not(test))] use ::libc::ioctl; +use log::debug; #[cfg(test)] use test::mock_libc::ioctl; +use crate::{Error, FileAccessErrorType, Result}; + /// Contains the rust representation of asm/uvdevice.h /// from kernel version: 6.5 verify mod ffi; diff --git a/rust/pv_core/src/uvdevice/attest.rs b/rust/pv_core/src/uvdevice/attest.rs index 10e2cbb8..80779e6d 100644 --- a/rust/pv_core/src/uvdevice/attest.rs +++ b/rust/pv_core/src/uvdevice/attest.rs @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT // // Copyright IBM Corp. 2024 +use std::ptr; + +use zerocopy::{FromZeros, IntoBytes}; + use super::{ffi, AttestationUserData, ConfigUid, UvCmd}; use crate::{Error, Result}; -use std::ptr; -use zerocopy::{FromZeros, IntoBytes}; /// _Retrieve Attestation Measurement_ UVC /// diff --git a/rust/pv_core/src/uvdevice/ffi.rs b/rust/pv_core/src/uvdevice/ffi.rs index b14b842e..0f640117 100644 --- a/rust/pv_core/src/uvdevice/ffi.rs +++ b/rust/pv_core/src/uvdevice/ffi.rs @@ -11,9 +11,10 @@ use std::mem::size_of; -use crate::{assert_size, static_assert}; use zerocopy::{FromBytes, IntoBytes}; +use crate::{assert_size, static_assert}; + pub const UVIO_ATT_ARCB_MAX_LEN: usize = 0x100000; pub const UVIO_ATT_MEASUREMENT_MAX_LEN: usize = 0x8000; pub const UVIO_ATT_ADDITIONAL_MAX_LEN: usize = 0x8000; diff --git a/rust/pv_core/src/uvdevice/info.rs b/rust/pv_core/src/uvdevice/info.rs index 64c0685b..dbfd4d63 100644 --- a/rust/pv_core/src/uvdevice/info.rs +++ b/rust/pv_core/src/uvdevice/info.rs @@ -2,15 +2,15 @@ // // Copyright IBM Corp. 2023 -use super::ffi::{self, uvio_uvdev_info}; -use crate::{ - misc::{Flags, Lsb0Flags64}, - uv::{UvCmd, UvDevice}, - Result, -}; use std::fmt::Display; + use zerocopy::{FromZeros, IntoBytes}; +use super::ffi::{self, uvio_uvdev_info}; +use crate::misc::{Flags, Lsb0Flags64}; +use crate::uv::{UvCmd, UvDevice}; +use crate::Result; + /// Information of supported functions by the uvdevice /// /// * `supp_uvio_cmds` - supported IOCTLs by this device diff --git a/rust/pv_core/src/uvdevice/retr_secret.rs b/rust/pv_core/src/uvdevice/retr_secret.rs index 041fceac..775a30da 100644 --- a/rust/pv_core/src/uvdevice/retr_secret.rs +++ b/rust/pv_core/src/uvdevice/retr_secret.rs @@ -2,10 +2,12 @@ // // Copyright IBM Corp. 2024 -use crate::uv::{ListableSecretType, RetrieveCmd}; -use serde::{Deserialize, Serialize, Serializer}; use std::fmt::Display; +use serde::{Deserialize, Serialize, Serializer}; + +use crate::uv::{ListableSecretType, RetrieveCmd}; + /// Allowed sizes for AES keys #[non_exhaustive] #[derive(PartialEq, Eq, Debug)] @@ -335,8 +337,8 @@ mod test { assert_tokens(&retr, &[Token::Str("19 (EC-SECP521R1-PRIVATE-KEY)")]); } - // Ensure that the string representation of the retrievable types stay constant, or PEM will have - // different, incompatible types + // Ensure that the string representation of the retrievable types stay constant, or PEM will + // have different, incompatible types #[test] fn stable_type_names() { assert_eq!("PLAINTEXT", RetrievableSecret::PlainText.to_string()); diff --git a/rust/pv_core/src/uvdevice/secret.rs b/rust/pv_core/src/uvdevice/secret.rs index 932ae68d..d1ed8a69 100644 --- a/rust/pv_core/src/uvdevice/secret.rs +++ b/rust/pv_core/src/uvdevice/secret.rs @@ -2,17 +2,18 @@ // // Copyright IBM Corp. 2023 -use super::ffi; -use crate::{ - request::{Confidential, MagicValue}, - uv::{SecretEntry, UvCmd}, - uvsecret::AddSecretMagic, - Error, Result, PAGESIZE, -}; +use std::io::Read; +use std::mem::size_of_val; + use log::debug; -use std::{io::Read, mem::size_of_val}; use zerocopy::IntoBytes; +use super::ffi; +use crate::request::{Confidential, MagicValue}; +use crate::uv::{SecretEntry, UvCmd}; +use crate::uvsecret::AddSecretMagic; +use crate::{Error, Result, PAGESIZE}; + /// _List Secrets_ Ultravisor command. /// /// The List Secrets Ultravisor call is used to list the diff --git a/rust/pv_core/src/uvdevice/secret_list.rs b/rust/pv_core/src/uvdevice/secret_list.rs index 07a72a3d..b8eb839f 100644 --- a/rust/pv_core/src/uvdevice/secret_list.rs +++ b/rust/pv_core/src/uvdevice/secret_list.rs @@ -2,24 +2,20 @@ // // Copyright IBM Corp. 2024 -use crate::{ - assert_size, - uv::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListCmd, RetrievableSecret}, - uvdevice::UvCmd, - Error, Result, -}; +use std::cmp::min; +use std::ffi::CStr; +use std::fmt::{Debug, Display, LowerHex, UpperHex}; +use std::io::{Cursor, Read, Seek, Write}; +use std::mem::size_of; +use std::slice::Iter; +use std::vec::IntoIter; + use serde::{Deserialize, Serialize, Serializer}; -use std::{ - cmp::min, - ffi::CStr, - fmt::{Debug, Display, LowerHex, UpperHex}, - io::{Cursor, Read, Seek, Write}, - mem::size_of, - slice::Iter, - vec::IntoIter, -}; -use zerocopy::{BigEndian, ByteOrder}; -use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, U16, U32}; +use zerocopy::{BigEndian, ByteOrder, FromBytes, Immutable, IntoBytes, KnownLayout, U16, U32}; + +use crate::uv::{AesSizes, AesXtsSizes, EcCurves, HmacShaSizes, ListCmd, RetrievableSecret}; +use crate::uvdevice::UvCmd; +use crate::{assert_size, Error, Result}; /// The 32 byte long ID of an UV secret /// diff --git a/rust/pv_core/src/uvdevice/test.rs b/rust/pv_core/src/uvdevice/test.rs index e556d179..ffb7b560 100644 --- a/rust/pv_core/src/uvdevice/test.rs +++ b/rust/pv_core/src/uvdevice/test.rs @@ -4,13 +4,12 @@ #![cfg(test)] -use std::{ - ffi::{c_int, c_ulong}, - sync::{Mutex, MutexGuard}, -}; +use std::ffi::{c_int, c_ulong}; +use std::sync::{Mutex, MutexGuard}; + +use lazy_static::lazy_static; use super::*; -use lazy_static::lazy_static; lazy_static! { /// needed to serialize all tests as tests operate on static data required by the mock @@ -129,8 +128,8 @@ impl UvCmd for TestCmd { } impl UvDevice { - /// Use this file as backing file for `uvdevice`. This is OK, as the ioctl is mocked and never touches the - /// passed file + /// Use this file as backing file for `uvdevice`. This is OK, as the ioctl is mocked and never + /// touches the passed file fn test_dev() -> Self { Self(File::open(".").unwrap()) } diff --git a/rust/pv_core/src/uvsecret.rs b/rust/pv_core/src/uvsecret.rs index 4fab87ff..3232c0b7 100644 --- a/rust/pv_core/src/uvsecret.rs +++ b/rust/pv_core/src/uvsecret.rs @@ -2,15 +2,15 @@ // // Copyright IBM Corp. 2023 -use crate::assert_size; -use crate::{ - request::{MagicValue, RequestMagic}, - Error, Result, -}; +use std::fmt::Display; +use std::mem::size_of; + use byteorder::ByteOrder; -use std::{fmt::Display, mem::size_of}; use zerocopy::{BigEndian, Immutable, IntoBytes, U16}; +use crate::request::{MagicValue, RequestMagic}; +use crate::{assert_size, Error, Result}; + /// The magic value used to identify an `AddSecretRequest`. /// /// The magic value is ASCII: @@ -145,11 +145,9 @@ impl From for AddSecretMagic { #[cfg(test)] mod test { - use crate::{ - request::MagicValue, - secret::{AddSecretMagic, UserDataType}, - Error, - }; + use crate::request::MagicValue; + use crate::secret::{AddSecretMagic, UserDataType}; + use crate::Error; #[test] fn convert_user_data() { diff --git a/rust/pvapconfig/build.rs b/rust/pvapconfig/build.rs index b99f184b..52662a41 100644 --- a/rust/pvapconfig/build.rs +++ b/rust/pvapconfig/build.rs @@ -3,11 +3,12 @@ // Copyright IBM Corp. 2024 // it under the terms of the MIT license. See LICENSE for details. -use clap::{CommandFactory, ValueEnum}; -use clap_complete::{generate_to, Shell}; use std::env; use std::io::Error; +use clap::{CommandFactory, ValueEnum}; +use clap_complete::{generate_to, Shell}; + include!("src/cli.rs"); fn main() -> Result<(), Error> { diff --git a/rust/pvapconfig/src/ap.rs b/rust/pvapconfig/src/ap.rs index f9f5dffc..4ac2cd97 100644 --- a/rust/pvapconfig/src/ap.rs +++ b/rust/pvapconfig/src/ap.rs @@ -5,13 +5,14 @@ //! AP support functions for pvapconfig // -use crate::helper::*; -use pv_core::ap::*; -use pv_core::misc::read_file_string; use std::path::Path; use std::slice::Iter; -use std::thread; -use std::time; +use std::{thread, time}; + +use pv_core::ap::*; +use pv_core::misc::read_file_string; + +use crate::helper::*; const RE_CARD_DIR: &str = r"^card([[:xdigit:]]{2})$"; diff --git a/rust/pvapconfig/src/config.rs b/rust/pvapconfig/src/config.rs index a4e712a4..d3bec4ac 100644 --- a/rust/pvapconfig/src/config.rs +++ b/rust/pvapconfig/src/config.rs @@ -5,13 +5,14 @@ //! Functions around handling the pvapconfig configuration file // +use std::fs::File; +use std::slice::Iter; + use openssl::sha::sha256; use pv_core::misc::encode_hex; use regex::Regex; use serde::{Deserialize, Serialize}; use serde_yaml::{self}; -use std::fs::File; -use std::slice::Iter; pub const STR_MODE_EP11: &str = "ep11"; pub const STR_MODE_ACCEL: &str = "accel"; @@ -209,10 +210,10 @@ impl ApConfigList { #[cfg(test)] mod tests { - use super::*; - use std::env; - use std::fs; use std::io::Write; + use std::{env, fs}; + + use super::*; const GOOD_CONFIGS: [&str; 8] = [ "# good test 1 diff --git a/rust/pvapconfig/src/helper.rs b/rust/pvapconfig/src/helper.rs index 45789c8b..15a3849b 100644 --- a/rust/pvapconfig/src/helper.rs +++ b/rust/pvapconfig/src/helper.rs @@ -5,13 +5,14 @@ //! Collection of helper functions for pvapconfig // -use regex::Regex; use std::error::Error; use std::fs; use std::fs::OpenOptions; use std::io::Write; use std::path::PathBuf; +use regex::Regex; + pub const PATH_PVAPCONFIG_LOCK: &str = "/run/lock/pvapconfig.lock"; /// For a given (sysfs) directory construct a list of all subdirs @@ -129,9 +130,10 @@ impl Drop for LockFile { #[cfg(test)] mod tests { - use super::*; use utils::TemporaryDirectory; + use super::*; + // Only very simple tests #[test] diff --git a/rust/pvapconfig/src/main.rs b/rust/pvapconfig/src/main.rs index 7645e10b..f967e7b9 100644 --- a/rust/pvapconfig/src/main.rs +++ b/rust/pvapconfig/src/main.rs @@ -12,6 +12,8 @@ mod config; mod helper; mod uv; +use std::process::ExitCode; + use ap::ApqnList; use cli::ARGS; use config::{ApConfigEntry, ApConfigList}; @@ -19,7 +21,6 @@ use helper::{LockFile, PATH_PVAPCONFIG_LOCK}; use pv_core::ap::{self as pvap, Apqn}; use pv_core::misc::encode_hex; use pv_core::uv::{ListableSecretType, SecretList}; -use std::process::ExitCode; use utils::print_version; /// Simple macro for @@ -456,8 +457,10 @@ fn config_and_apqn_match(apc: &ApConfigEntry, apqn: &Apqn) -> bool { #[cfg(test)] mod tests { + use pv_core::misc::decode_hex; + use pv_core::uv::SecretEntry; + use super::*; - use pv_core::{misc::decode_hex, uv::SecretEntry}; // This is more or less only a test for the do_ap_config() function // However, this is THE main functionality of the whole application. diff --git a/rust/pvattest/build.rs b/rust/pvattest/build.rs index 91212adf..f2cba165 100644 --- a/rust/pvattest/build.rs +++ b/rust/pvattest/build.rs @@ -4,11 +4,12 @@ // it under the terms of the MIT license. See LICENSE for details. #![allow(missing_docs)] -use clap::CommandFactory; -use clap_complete::{generate_to, Shell}; use std::env; use std::io::Error; +use clap::CommandFactory; +use clap_complete::{generate_to, Shell}; + include!("src/cli.rs"); fn main() -> Result<(), Error> { diff --git a/rust/pvattest/src/additional.rs b/rust/pvattest/src/additional.rs index 7af6ace0..523b4c2b 100644 --- a/rust/pvattest/src/additional.rs +++ b/rust/pvattest/src/additional.rs @@ -2,13 +2,15 @@ // // Copyright IBM Corp. 2024 -use crate::exchange::ExchangeFormatResponse; +use std::fmt::Display; + use anyhow::Result; use pv::attest::{AdditionalData, AttestationFlags}; use serde::Serialize; -use std::fmt::Display; use utils::HexSlice; +use crate::exchange::ExchangeFormatResponse; + #[derive(Serialize)] pub struct AttestationResult<'a> { pub cuid: HexSlice<'a>, diff --git a/rust/pvattest/src/cli.rs b/rust/pvattest/src/cli.rs index cd939fa7..4f1a1fd1 100644 --- a/rust/pvattest/src/cli.rs +++ b/rust/pvattest/src/cli.rs @@ -58,7 +58,8 @@ pub enum Command { /// Check if the attestation result matches defined policies. /// - /// After the attestation verification, check whether the attestation result complies with user-defined policies. + /// After the attestation verification, check whether the attestation result complies with + /// user-defined policies. Check(CheckOpt), /// Print version information and exit. @@ -103,7 +104,8 @@ pub enum AttAddFlags { /// additional-data. PhkhAtt, - /// Request a hash over all successful Add-secret requests and the lock state as additional-data. + /// Request a hash over all successful Add-secret requests and the lock state as + /// additional-data. SecretStoreHash, /// Request the state of the firmware as additional-data. diff --git a/rust/pvattest/src/cmd/check.rs b/rust/pvattest/src/cmd/check.rs index dab8327c..0524b32d 100644 --- a/rust/pvattest/src/cmd/check.rs +++ b/rust/pvattest/src/cmd/check.rs @@ -6,28 +6,22 @@ mod firmware; mod host_key; mod secret_store; -use self::{ - firmware::firmware_check, - host_key::{host_key_check, HostKeyCheck}, - secret_store::secret_store_check, - secret_store::SecretStoreCheck, -}; -use crate::{ - additional::AttestationResult, - cli::{CheckOpt, CheckOptIO}, - exchange::ExchangeFormatResponse, -}; +use std::process::ExitCode; use anyhow::Result; use log::{debug, info, warn}; -use pv::{ - attest::AttestationRequest, - misc::{create_file, open_file, read_file}, -}; +use pv::attest::AttestationRequest; +use pv::misc::{create_file, open_file, read_file}; use serde::Serialize; -use std::process::ExitCode; use utils::HexSlice; +use self::firmware::firmware_check; +use self::host_key::{host_key_check, HostKeyCheck}; +use self::secret_store::{secret_store_check, SecretStoreCheck}; +use crate::additional::AttestationResult; +use crate::cli::{CheckOpt, CheckOptIO}; +use crate::exchange::ExchangeFormatResponse; + #[derive(Default, Debug)] enum CheckState { #[default] diff --git a/rust/pvattest/src/cmd/check/firmware.rs b/rust/pvattest/src/cmd/check/firmware.rs index 5f2eb55c..f0dda86d 100644 --- a/rust/pvattest/src/cmd/check/firmware.rs +++ b/rust/pvattest/src/cmd/check/firmware.rs @@ -2,7 +2,8 @@ // // Copyright IBM Corp. 2024 -use std::{fmt::Display, time::Duration}; +use std::fmt::Display; +use std::time::Duration; use anyhow::{bail, Result}; use base64::prelude::*; @@ -11,7 +12,8 @@ use log::{debug, info, log_enabled}; use serde::{Deserialize, Serialize}; use super::{bail_check, CheckState}; -use crate::{additional::AttestationResult, cli::CheckOpt}; +use crate::additional::AttestationResult; +use crate::cli::CheckOpt; const CHECK_DEFAULT_ENDP: &str = "https://esupport.ibm.com/eccedge/ent/z"; const VERIFY_API: &str = "hmrs/firmware/attestation/v1/verify"; diff --git a/rust/pvattest/src/cmd/check/host_key.rs b/rust/pvattest/src/cmd/check/host_key.rs index 0233e4ff..777219ef 100644 --- a/rust/pvattest/src/cmd/check/host_key.rs +++ b/rust/pvattest/src/cmd/check/host_key.rs @@ -2,21 +2,20 @@ // // Copyright IBM Corp. 2024 +use std::fmt::Display; +use std::path::Path; + use anyhow::Result; use log::{debug, info}; -use pv::{ - misc::{read_certs, read_file}, - request::{openssl::DigestBytes, EcPubKeyCoord}, -}; +use pv::misc::{read_certs, read_file}; +use pv::request::openssl::DigestBytes; +use pv::request::EcPubKeyCoord; use serde::Serialize; -use std::{fmt::Display, path::Path}; use utils::HexSlice; use super::CheckState; -use crate::{ - additional::AttestationResult, - cli::{CheckOpt, HostKeyCheckPolicy}, -}; +use crate::additional::AttestationResult; +use crate::cli::{CheckOpt, HostKeyCheckPolicy}; #[derive(Debug, Clone, Copy)] pub enum HkCheck { diff --git a/rust/pvattest/src/cmd/check/secret_store.rs b/rust/pvattest/src/cmd/check/secret_store.rs index 63519eab..0989df6c 100644 --- a/rust/pvattest/src/cmd/check/secret_store.rs +++ b/rust/pvattest/src/cmd/check/secret_store.rs @@ -6,13 +6,14 @@ use std::path::{Path, PathBuf}; use anyhow::Result; use log::info; -use openssl::hash::DigestBytes; -use openssl::hash::{hash, MessageDigest}; -use pv::{misc::read_file, secret::AddSecretRequest}; +use openssl::hash::{hash, DigestBytes, MessageDigest}; +use pv::misc::read_file; +use pv::secret::AddSecretRequest; use serde::Serialize; use super::{bail_check, CheckState}; -use crate::{additional::AttestationResult, cli::CheckOpt}; +use crate::additional::AttestationResult; +use crate::cli::CheckOpt; #[derive(Debug, Serialize)] pub struct SecretStoreCheck<'a> { diff --git a/rust/pvattest/src/cmd/create.rs b/rust/pvattest/src/cmd/create.rs index 4fa8ebde..7b5a0b6e 100644 --- a/rust/pvattest/src/cmd/create.rs +++ b/rust/pvattest/src/cmd/create.rs @@ -2,18 +2,16 @@ // // Copyright IBM Corp. 2024 -use crate::{ - cli::{AttAddFlags, CreateAttOpt}, - exchange::{ExchangeFormatRequest, ExchangeFormatVersion}, -}; +use std::process::ExitCode; + use anyhow::{bail, Context, Result}; use log::{debug, warn}; -use pv::{ - attest::{AttestationFlags, AttestationMeasAlg, AttestationRequest, AttestationVersion}, - misc::{create_file, write_file}, - request::{ReqEncrCtx, Request, SymKey, SymKeyType}, -}; -use std::process::ExitCode; +use pv::attest::{AttestationFlags, AttestationMeasAlg, AttestationRequest, AttestationVersion}; +use pv::misc::{create_file, write_file}; +use pv::request::{ReqEncrCtx, Request, SymKey, SymKeyType}; + +use crate::cli::{AttAddFlags, CreateAttOpt}; +use crate::exchange::{ExchangeFormatRequest, ExchangeFormatVersion}; fn flags(cli_flags: &[AttAddFlags]) -> AttestationFlags { let mut att_flags = AttestationFlags::default(); diff --git a/rust/pvattest/src/cmd/perform.rs b/rust/pvattest/src/cmd/perform.rs index be2b931c..cf1bba3a 100644 --- a/rust/pvattest/src/cmd/perform.rs +++ b/rust/pvattest/src/cmd/perform.rs @@ -2,17 +2,15 @@ // // Copyright IBM Corp. 2024 -use crate::{ - cli::PerformAttOptComb, - exchange::{ExchangeFormatRequest, ExchangeFormatResponse, ExchangeFormatVersion}, -}; -use anyhow::Result; -use pv::{ - misc::{create_file, open_file, read_file}, - uv::{AttestationCmd, UvDevice}, -}; use std::process::ExitCode; +use anyhow::Result; +use pv::misc::{create_file, open_file, read_file}; +use pv::uv::{AttestationCmd, UvDevice}; + +use crate::cli::PerformAttOptComb; +use crate::exchange::{ExchangeFormatRequest, ExchangeFormatResponse, ExchangeFormatVersion}; + pub fn perform<'a, P>(opt: P) -> Result where P: Into>, diff --git a/rust/pvattest/src/cmd/verify.rs b/rust/pvattest/src/cmd/verify.rs index 2a7469c6..fae4a545 100644 --- a/rust/pvattest/src/cmd/verify.rs +++ b/rust/pvattest/src/cmd/verify.rs @@ -2,22 +2,20 @@ // // Copyright IBM Corp. 2024 +use std::process::ExitCode; + use anyhow::Result; use log::{debug, warn}; -use pv::{ - attest::{AttestationItems, AttestationMeasurement, AttestationRequest}, - misc::{create_file, open_file, read_exact_file, write_file}, - request::{openssl::pkey::PKey, BootHdrTags, Confidential, SymKey}, -}; -use std::process::ExitCode; +use pv::attest::{AttestationItems, AttestationMeasurement, AttestationRequest}; +use pv::misc::{create_file, open_file, read_exact_file, write_file}; +use pv::request::openssl::pkey::PKey; +use pv::request::{BootHdrTags, Confidential, SymKey}; use utils::HexSlice; -use crate::{ - additional::AttestationResult, - cli::{OutputType, VerifyOpt}, - exchange::ExchangeFormatResponse, - EXIT_CODE_ATTESTATION_FAIL, -}; +use crate::additional::AttestationResult; +use crate::cli::{OutputType, VerifyOpt}; +use crate::exchange::ExchangeFormatResponse; +use crate::EXIT_CODE_ATTESTATION_FAIL; pub fn verify(opt: &VerifyOpt) -> Result { let mut input = open_file(&opt.input)?; diff --git a/rust/pvattest/src/exchange.rs b/rust/pvattest/src/exchange.rs index ac83bb83..f1080372 100644 --- a/rust/pvattest/src/exchange.rs +++ b/rust/pvattest/src/exchange.rs @@ -2,14 +2,14 @@ // // Copyright IBM Corp. 2024 #![allow(unused)] +use std::io::{ErrorKind, Read, Seek, SeekFrom, Write}; +use std::mem::size_of; + use anyhow::{anyhow, bail, Error, Result}; -use pv::{assert_size, request::MagicValue, uv::AttestationCmd, uv::ConfigUid}; -use std::{ - io::{ErrorKind, Read, Seek, SeekFrom, Write}, - mem::size_of, -}; -use zerocopy::ByteOrder; -use zerocopy::{BigEndian, FromBytes, Immutable, IntoBytes, KnownLayout, U32, U64}; +use pv::assert_size; +use pv::request::MagicValue; +use pv::uv::{AttestationCmd, ConfigUid}; +use zerocopy::{BigEndian, ByteOrder, FromBytes, Immutable, IntoBytes, KnownLayout, U32, U64}; const INV_EXCHANGE_FMT_ERROR_TEXT: &str = "The input has not the correct format:"; @@ -583,9 +583,10 @@ mod test { use std::io::Cursor; - use super::*; use pv::misc::read_file; + use super::*; + #[test] fn exchange_from_slice() { let val = &[0; 17]; diff --git a/rust/pvattest/src/main.rs b/rust/pvattest/src/main.rs index b69332bc..d6dd9f13 100644 --- a/rust/pvattest/src/main.rs +++ b/rust/pvattest/src/main.rs @@ -8,10 +8,11 @@ mod cli; mod cmd; mod exchange; +use std::process::ExitCode; + use clap::{CommandFactory, Parser}; use cli::{CliOptions, Command}; use log::trace; -use std::process::ExitCode; use utils::{print_cli_error, print_error, print_version, PvLogger}; use crate::cmd::{check, create, perform, verify, CMD_FN, UV_CMD_FN}; diff --git a/rust/pvebc/src/cli.rs b/rust/pvebc/src/cli.rs index 62c4eac5..ec7f3d57 100644 --- a/rust/pvebc/src/cli.rs +++ b/rust/pvebc/src/cli.rs @@ -2,7 +2,8 @@ // // Copyright IBM Corp. -use std::{path::PathBuf, sync::OnceLock}; +use std::path::PathBuf; +use std::sync::OnceLock; use clap::{ArgAction, Parser, ValueHint}; @@ -21,8 +22,8 @@ pub struct Cli { /// Specifies the toc.asr which is the root of the EBC resources /// /// Specify the add-secret request file toc.asr that serves as the root of the EBC resources. - /// Its user data must contain a reference to toc.pol as generated by pvsecret with the --policy - /// option. + /// Its user data must contain a reference to toc.pol as generated by pvsecret with the + /// --policy option. #[arg(short, long, value_name = "FILE", value_hint = ValueHint::FilePath)] pub toc: PathBuf, diff --git a/rust/pvebc/src/ebc_utils.rs b/rust/pvebc/src/ebc_utils.rs index 1912c6ba..8d5c89cb 100644 --- a/rust/pvebc/src/ebc_utils.rs +++ b/rust/pvebc/src/ebc_utils.rs @@ -2,9 +2,11 @@ // // Copyright IBM Corp. +use std::io::Read; +use std::path::Path; + use anyhow::{bail, Context, Result}; use pv_core::misc::open_file; -use std::{io::Read, path::Path}; /// Length of the MAC tag in bytes (last 16 bytes of AddSecretRequest files) pub const MAC_TAG_LEN: usize = 16; diff --git a/rust/pvebc/src/main.rs b/rust/pvebc/src/main.rs index 0de6c1c6..8449f9dc 100644 --- a/rust/pvebc/src/main.rs +++ b/rust/pvebc/src/main.rs @@ -20,27 +20,23 @@ mod cli; mod ebc_utils; -#[cfg(target_arch = "s390x")] -use pv_core::uv::{AddCmd, UvDevice}; -#[cfg(target_arch = "s390x")] -use utils::get_reader_from_cli_file_arg; +use std::fs::{self, File}; +use std::io::{BufRead, Read}; +use std::path::{Path, PathBuf}; +use std::process::ExitCode; +use std::str::from_utf8; use anyhow::{bail, Context, Error, Result}; use clap::Parser; -use pv_core::{ - misc::{decode_hex, encode_hex}, - PolicyReference, -}; -use std::{ - fs::{self, File}, - io::{BufRead, Read}, - path::{Path, PathBuf}, - process::ExitCode, - str::from_utf8, -}; +use pv_core::misc::{decode_hex, encode_hex}; +#[cfg(target_arch = "s390x")] +use pv_core::uv::{AddCmd, UvDevice}; +use pv_core::PolicyReference; // Don't use openssl here because this tool is intended to run in the initramfs // phase of the boot and there we don't want to dynamically link against a C lib use sha2::{self, Digest}; +#[cfg(target_arch = "s390x")] +use utils::get_reader_from_cli_file_arg; use zerocopy::TryFromBytes; use crate::cli::Cli; diff --git a/rust/pvimg/examples/create-sehdr/main.rs b/rust/pvimg/examples/create-sehdr/main.rs index 4a743809..6bb170a1 100644 --- a/rust/pvimg/examples/create-sehdr/main.rs +++ b/rust/pvimg/examples/create-sehdr/main.rs @@ -3,27 +3,21 @@ // Copyright IBM Corp. 2024 #![allow(missing_docs)] -use std::{ - fmt::Display, - fs::{File, OpenOptions}, - io::{BufReader, Read, Write}, - path::PathBuf, - str::FromStr, -}; +use std::fmt::Display; +use std::fs::{File, OpenOptions}; +use std::io::{BufReader, Read, Write}; +use std::path::PathBuf; +use std::str::FromStr; use anyhow::{anyhow, Context, Error}; use clap::{Parser, ValueHint}; use log::{info, warn}; -use pv::{ - misc::{decode_hex, open_file, read_certs, read_file, try_parse_u64}, - request::SymKeyType, - Error as PvError, Result, -}; -use pvimg::{ - misc::PSW, - secured_comp::{ComponentTrait, Layout, SecuredComponentBuilder}, - uvdata::{BuilderTrait, SeHdrBuilder, SeHdrVersion}, -}; +use pv::misc::{decode_hex, open_file, read_certs, read_file, try_parse_u64}; +use pv::request::SymKeyType; +use pv::{Error as PvError, Result}; +use pvimg::misc::PSW; +use pvimg::secured_comp::{ComponentTrait, Layout, SecuredComponentBuilder}; +use pvimg::uvdata::{BuilderTrait, SeHdrBuilder, SeHdrVersion}; use utils::{AtomicFile, AtomicFileOperation, HexSlice, PvLogger, VerbosityOptions}; /// Converts the hexstring into a byte vector. diff --git a/rust/pvimg/examples/tamper_pvimg/main.rs b/rust/pvimg/examples/tamper_pvimg/main.rs index 40f1bf61..cebf1dfa 100644 --- a/rust/pvimg/examples/tamper_pvimg/main.rs +++ b/rust/pvimg/examples/tamper_pvimg/main.rs @@ -1,20 +1,18 @@ #![allow(missing_docs)] -use std::{fs::File, io::Write, path::PathBuf}; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; use anyhow::Context; use clap::{Parser, ValueEnum, ValueHint}; use log::info; -use pv::{ - misc::{open_file, parse_hex, read_file}, - request::SymKey, -}; -use pvimg::{ - error::Result, - uvdata::{ - KeyExchangeTrait, SeHdr, SeHdrBinV1, SeHdrData, SeHdrDataV1, SeHdrVersioned, - UvDataPlainTrait, UvDataTrait, - }, +use pv::misc::{open_file, parse_hex, read_file}; +use pv::request::SymKey; +use pvimg::error::Result; +use pvimg::uvdata::{ + KeyExchangeTrait, SeHdr, SeHdrBinV1, SeHdrData, SeHdrDataV1, SeHdrVersioned, UvDataPlainTrait, + UvDataTrait, }; use utils::{PvLogger, VerbosityOptions}; diff --git a/rust/pvimg/src/cli.rs b/rust/pvimg/src/cli.rs index ac8bb822..25ac0b87 100644 --- a/rust/pvimg/src/cli.rs +++ b/rust/pvimg/src/cli.rs @@ -2,15 +2,16 @@ // // Copyright IBM Corp. 2024 +use std::env; +use std::ffi::OsStr; use std::fmt::Display; +use std::io::IsTerminal; +use std::path::PathBuf; use std::str::FromStr; use std::string::ToString; -use std::{env, ffi::OsStr, io::IsTerminal, path::PathBuf}; -use clap::{ - builder::{PossibleValue, TypedValueParser}, - Arg, ArgGroup, Args, Command, CommandFactory, Parser, ValueEnum, ValueHint, -}; +use clap::builder::{PossibleValue, TypedValueParser}; +use clap::{Arg, ArgGroup, Args, Command, CommandFactory, Parser, ValueEnum, ValueHint}; use log::warn; use utils::{CertificateOptions, DeprecatedVerbosityOptions}; diff --git a/rust/pvimg/src/cmd/common.rs b/rust/pvimg/src/cmd/common.rs index 8c473db7..676e85d0 100644 --- a/rust/pvimg/src/cmd/common.rs +++ b/rust/pvimg/src/cmd/common.rs @@ -6,7 +6,8 @@ use std::path::PathBuf; use anyhow::Result; use log::info; -use pv::{misc::read_file, request::Confidential}; +use pv::misc::read_file; +use pv::request::Confidential; use crate::cli::UserKeys; diff --git a/rust/pvimg/src/cmd/create.rs b/rust/pvimg/src/cmd/create.rs index 2e2f1614..d2f8d7c1 100644 --- a/rust/pvimg/src/cmd/create.rs +++ b/rust/pvimg/src/cmd/create.rs @@ -2,29 +2,27 @@ // // Copyright IBM Corp. 2024 -use std::{fs::OpenOptions, io::BufReader}; +use std::fs::OpenOptions; +use std::io::BufReader; use anyhow::{Context, Result}; use log::{debug, warn}; use pv::misc::{open_file, try_parse_u64}; -use pvimg::{ - error::OwnExitCode, - secured_comp::ComponentTrait, - uvdata::{ - ControlFlagTrait, ControlFlagsTrait, FlagData, PcfV1, PlaintextControlFlagsV1, ScfV1, - SeHdrDataV1, SecretControlFlagsV1, - }, +use pvimg::error::OwnExitCode; +use pvimg::secured_comp::ComponentTrait; +use pvimg::uvdata::{ + ControlFlagTrait, ControlFlagsTrait, FlagData, PcfV1, PlaintextControlFlagsV1, ScfV1, + SeHdrDataV1, SecretControlFlagsV1, }; use utils::{AtomicFile, AtomicFileOperation}; -use crate::{ - cli::{ComponentPaths, CreateBootImageArgs}, - cmd::common::read_user_provided_keys, - se_img::{SeHdrArgs, SeImgBuilder}, - se_img_comps::{ - check_components, cmdline::Cmdline, kernel::S390Kernel, ramdisk::Ramdisk, Component, - }, -}; +use crate::cli::{ComponentPaths, CreateBootImageArgs}; +use crate::cmd::common::read_user_provided_keys; +use crate::se_img::{SeHdrArgs, SeImgBuilder}; +use crate::se_img_comps::cmdline::Cmdline; +use crate::se_img_comps::kernel::S390Kernel; +use crate::se_img_comps::ramdisk::Ramdisk; +use crate::se_img_comps::{check_components, Component}; /// The returned vector is sorted by the occurrence in the memory layout: /// First the kernel, then the ramdisk and then the kernel cmdline. diff --git a/rust/pvimg/src/cmd/info.rs b/rust/pvimg/src/cmd/info.rs index 7af664e3..80601786 100644 --- a/rust/pvimg/src/cmd/info.rs +++ b/rust/pvimg/src/cmd/info.rs @@ -6,14 +6,10 @@ use std::io::Write; use anyhow::{Context, Result}; use log::{info, warn}; -use pv::{ - misc::{open_file, read_file}, - request::SymKey, -}; -use pvimg::{ - error::{Error, OwnExitCode}, - uvdata::{EnvelopeSeHdrV1, KeyExchangeTrait, SeH, SeHdr, UvDataTrait}, -}; +use pv::misc::{open_file, read_file}; +use pv::request::SymKey; +use pvimg::error::{Error, OwnExitCode}; +use pvimg::uvdata::{EnvelopeSeHdrV1, KeyExchangeTrait, SeH, SeHdr, UvDataTrait}; use crate::cli::{InfoArgs, OutputFormatKind, OutputFormatSpec, OutputFormatVariant}; diff --git a/rust/pvimg/src/cmd/test.rs b/rust/pvimg/src/cmd/test.rs index 4cb1a0b5..4a1b114d 100644 --- a/rust/pvimg/src/cmd/test.rs +++ b/rust/pvimg/src/cmd/test.rs @@ -6,17 +6,14 @@ use std::path::Path; use anyhow::Result; use log::{info, warn}; -use pv::{ - misc::{open_file, read_certs, read_file}, - FileAccessErrorType, PvCoreError, -}; -use pvimg::{ - error::{Error, OwnExitCode, PvError}, - uvdata::{KeyExchangeTrait, SeHdr, UvKeyHashesV1}, -}; +use pv::misc::{open_file, read_certs, read_file}; +use pv::{FileAccessErrorType, PvCoreError}; +use pvimg::error::{Error, OwnExitCode, PvError}; +use pvimg::uvdata::{KeyExchangeTrait, SeHdr, UvKeyHashesV1}; use utils::HexSlice; -use crate::{cli::TestArgs, log_println}; +use crate::cli::TestArgs; +use crate::log_println; /// Returns `Ok(true)` if at least one of the hashes is included. fn hdr_test_target_hashes(hdr: &SeHdr, key_hashes: &Path) -> Result { diff --git a/rust/pvimg/src/main.rs b/rust/pvimg/src/main.rs index 38368be5..be6b0775 100644 --- a/rust/pvimg/src/main.rs +++ b/rust/pvimg/src/main.rs @@ -16,7 +16,8 @@ mod cmd; mod se_img; mod se_img_comps; -use std::{env, process::ExitCode}; +use std::env; +use std::process::ExitCode; use clap::{Command, CommandFactory, Parser}; use cli::{validate_cli, CliOptions, SubCommands}; diff --git a/rust/pvimg/src/pv_utils/error.rs b/rust/pvimg/src/pv_utils/error.rs index 5e54a61e..f3e4b719 100644 --- a/rust/pvimg/src/pv_utils/error.rs +++ b/rust/pvimg/src/pv_utils/error.rs @@ -2,8 +2,7 @@ // // Copyright IBM Corp. 2024 -pub use pv::Error as PvError; -pub use pv::PvCoreError; +pub use pv::{Error as PvError, PvCoreError}; use utils::{impl_exitcodetrait, ExitCodeTrait}; /// Result type for this crate diff --git a/rust/pvimg/src/pv_utils/layout.rs b/rust/pvimg/src/pv_utils/layout.rs index e741c051..1d1d5a5f 100644 --- a/rust/pvimg/src/pv_utils/layout.rs +++ b/rust/pvimg/src/pv_utils/layout.rs @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT // // Copyright IBM Corp. 2024 -use std::{collections::BTreeSet, fmt::Display, rc::Rc}; +use std::collections::BTreeSet; +use std::fmt::Display; +use std::rc::Rc; -use crate::{ - misc::round_up, - pv_utils::error::{Error, Result}, -}; +use crate::misc::round_up; +use crate::pv_utils::error::{Error, Result}; /// Represents a range from [start, stop) (inclusive start, exclusive stop) #[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)] @@ -194,12 +194,11 @@ impl IntoIterator for Layout { #[allow(clippy::shadow_unrelated)] #[cfg(test)] mod tests { - use std::{collections::BTreeSet, rc::Rc}; + use std::collections::BTreeSet; + use std::rc::Rc; - use proptest::{ - prelude::{Just, Strategy}, - prop_assert, prop_assert_eq, proptest, - }; + use proptest::prelude::{Just, Strategy}; + use proptest::{prop_assert, prop_assert_eq, proptest}; use crate::pv_utils::{Interval, Layout}; diff --git a/rust/pvimg/src/pv_utils/misc.rs b/rust/pvimg/src/pv_utils/misc.rs index 322af1c1..076e3959 100644 --- a/rust/pvimg/src/pv_utils/misc.rs +++ b/rust/pvimg/src/pv_utils/misc.rs @@ -67,10 +67,8 @@ pub fn try_copy_slice_to_array( mod tests { use pv::PvCoreError; - use crate::{ - error::{Error, Result}, - pv_utils::try_copy_slice_to_array, - }; + use crate::error::{Error, Result}; + use crate::pv_utils::try_copy_slice_to_array; #[test] fn test_try_copy_slice_to_array() { diff --git a/rust/pvimg/src/pv_utils/psw.rs b/rust/pvimg/src/pv_utils/psw.rs index a33d5f9e..0f9bf50e 100644 --- a/rust/pvimg/src/pv_utils/psw.rs +++ b/rust/pvimg/src/pv_utils/psw.rs @@ -4,7 +4,8 @@ use std::fmt::Display; -use deku::{ctx::Endian, DekuRead, DekuWrite}; +use deku::ctx::Endian; +use deku::{DekuRead, DekuWrite}; use pv::request::Zeroize; use serde::{Deserialize, Serialize}; @@ -81,7 +82,8 @@ impl TryFrom for ShortPsw { #[cfg(test)] mod tests { use super::{ShortPsw, PSW}; - use crate::pv_utils::{error::Result, psw::PSW_MASK_BIT_12}; + use crate::pv_utils::error::Result; + use crate::pv_utils::psw::PSW_MASK_BIT_12; #[test] fn test_from_psw_to_short_psw_ok() { diff --git a/rust/pvimg/src/pv_utils/se_hdr/brb.rs b/rust/pvimg/src/pv_utils/se_hdr/brb.rs index 811f01c7..0cd527ac 100644 --- a/rust/pvimg/src/pv_utils/se_hdr/brb.rs +++ b/rust/pvimg/src/pv_utils/se_hdr/brb.rs @@ -1,40 +1,31 @@ // SPDX-License-Identifier: MIT // // Copyright IBM Corp. 2024 -use std::{ - fmt::Display, - io::{Read, Seek, SeekFrom}, - mem::size_of, -}; +use std::fmt::Display; +use std::io::{Read, Seek, SeekFrom}; +use std::mem::size_of; -use deku::{ctx::Endian, prelude::*}; +use deku::ctx::Endian; +use deku::prelude::*; use enum_dispatch::enum_dispatch; -use pv::{ - request::{ - openssl::pkey::{PKey, PKeyRef, Private, Public}, - seek_se_hdr_start, Aes256XtsKey, Confidential, SymKey, SymKeyType, - }, - static_assert, -}; +use pv::request::openssl::pkey::{PKey, PKeyRef, Private, Public}; +use pv::request::{seek_se_hdr_start, Aes256XtsKey, Confidential, SymKey, SymKeyType}; +use pv::static_assert; use serde::{Deserialize, Serialize}; use utils::S390ToolsMetaData; pub use super::hdr_v1::{SeHdrBinV1, SeHdrDataV1}; use super::{PlaintextControlFlagsV1, SecretControlFlagsV1}; -use crate::{ - misc::PAGESIZE, - pv_utils::{ - error::{Error, Result}, - misc::display_indented, - serializing::{serde_hex_array, serialize_to_bytes}, - uvdata::{ - AeadCipherTrait, AeadDataTrait, AeadPlainDataTrait, KeyExchangeTrait, UvDataPlainTrait, - UvDataTrait, - }, - uvdata_builder::{AeadCipherBuilderTrait, KeyExchangeBuilderTrait}, - PSW, - }, +use crate::misc::PAGESIZE; +use crate::pv_utils::error::{Error, Result}; +use crate::pv_utils::misc::display_indented; +use crate::pv_utils::serializing::{serde_hex_array, serialize_to_bytes}; +use crate::pv_utils::uvdata::{ + AeadCipherTrait, AeadDataTrait, AeadPlainDataTrait, KeyExchangeTrait, UvDataPlainTrait, + UvDataTrait, }; +use crate::pv_utils::uvdata_builder::{AeadCipherBuilderTrait, KeyExchangeBuilderTrait}; +use crate::pv_utils::PSW; #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] diff --git a/rust/pvimg/src/pv_utils/se_hdr/builder.rs b/rust/pvimg/src/pv_utils/se_hdr/builder.rs index 93bcc7af..292a30a3 100644 --- a/rust/pvimg/src/pv_utils/se_hdr/builder.rs +++ b/rust/pvimg/src/pv_utils/se_hdr/builder.rs @@ -4,19 +4,18 @@ use pv::request::Confidential; -use super::{hdr_v1::SeHdrDataV1, SeHdr}; -use crate::pv_utils::{ - error::{Error, Result}, - se_hdr::{ - brb::{SeHdrCommon, SeHdrConfBuilderTrait, SeHdrData, SeHdrPubBuilderTrait}, - ComponentMetadata, SeHdrPlain, SeHdrVersion, - }, - uvdata::UvDataPlainTrait, - uvdata_builder::{ - AeadCipherBuilderTrait, BuilderTrait, KeyExchangeBuilderTrait, UvDataBuilder, - }, - PlaintextControlFlagsV1, SecretControlFlagsV1, PSW, +use super::hdr_v1::SeHdrDataV1; +use super::SeHdr; +use crate::pv_utils::error::{Error, Result}; +use crate::pv_utils::se_hdr::brb::{ + SeHdrCommon, SeHdrConfBuilderTrait, SeHdrData, SeHdrPubBuilderTrait, }; +use crate::pv_utils::se_hdr::{ComponentMetadata, SeHdrPlain, SeHdrVersion}; +use crate::pv_utils::uvdata::UvDataPlainTrait; +use crate::pv_utils::uvdata_builder::{ + AeadCipherBuilderTrait, BuilderTrait, KeyExchangeBuilderTrait, UvDataBuilder, +}; +use crate::pv_utils::{PlaintextControlFlagsV1, SecretControlFlagsV1, PSW}; /// `SeHdrBuilder` pub type SeHdrBuilder<'a> = UvDataBuilder<'a, SeHdrPlain>; @@ -96,17 +95,13 @@ impl BuilderTrait for SeHdrBuilder<'_> { mod tests { use std::io::Cursor; - use pv::{ - request::{Confidential, SymKeyType, SHA_512_HASH_LEN}, - test_utils::get_test_key_and_cert, - }; + use pv::request::{Confidential, SymKeyType, SHA_512_HASH_LEN}; + use pv::test_utils::get_test_key_and_cert; use super::*; - use crate::pv_utils::{ - se_hdr::ComponentMetadataV1, - uvdata::{AeadDataTrait, AeadPlainDataTrait}, - UvDataTrait, - }; + use crate::pv_utils::se_hdr::ComponentMetadataV1; + use crate::pv_utils::uvdata::{AeadDataTrait, AeadPlainDataTrait}; + use crate::pv_utils::UvDataTrait; #[test] fn builder_test() { diff --git a/rust/pvimg/src/pv_utils/se_hdr/flags.rs b/rust/pvimg/src/pv_utils/se_hdr/flags.rs index f76f6b75..49e1e90e 100644 --- a/rust/pvimg/src/pv_utils/se_hdr/flags.rs +++ b/rust/pvimg/src/pv_utils/se_hdr/flags.rs @@ -24,7 +24,9 @@ //! assert!(flags.is_set(PcfV1::AllowDumping)); //! ``` -use std::{fmt::Display, fmt::LowerHex, marker::PhantomData, mem::size_of}; +use std::fmt::{Display, LowerHex}; +use std::marker::PhantomData; +use std::mem::size_of; use pv::misc::{Flags, Msb0Flags64}; diff --git a/rust/pvimg/src/pv_utils/se_hdr/hdr_v1.rs b/rust/pvimg/src/pv_utils/se_hdr/hdr_v1.rs index cf2a56fe..71b232a8 100644 --- a/rust/pvimg/src/pv_utils/se_hdr/hdr_v1.rs +++ b/rust/pvimg/src/pv_utils/se_hdr/hdr_v1.rs @@ -1,53 +1,44 @@ // SPDX-License-Identifier: MIT // // Copyright IBM Corp. 2024 -use std::{ - fmt::Display, - mem::{size_of, size_of_val}, -}; +use std::fmt::Display; +use std::mem::{size_of, size_of_val}; use base64::prelude::*; -use deku::{ctx::Endian, prelude::*}; -use openssl::{ - nid::Nid, - pkey::{PKeyRef, Public}, -}; +use deku::ctx::Endian; +use deku::prelude::*; +use openssl::nid::Nid; +use openssl::pkey::{PKeyRef, Public}; +use pv::request::openssl::pkey::{PKey, Private}; use pv::request::{ - gen_ec_key, - openssl::pkey::{PKey, Private}, - random_array, Aes256XtsKey, Confidential, EcPubKeyCoord, Encrypt, Keyslot, SymKey, SymKeyType, - Zeroize, SHA_512_HASH_LEN, + gen_ec_key, random_array, Aes256XtsKey, Confidential, EcPubKeyCoord, Encrypt, Keyslot, SymKey, + SymKeyType, Zeroize, SHA_512_HASH_LEN, }; use serde::{Deserialize, Serialize}; use utils::HexSlice; use super::keys::phkh_v1; -use crate::{ - error::Error, - misc::PAGESIZE, - pv_utils::{ - error::Result, - misc::display_indented, - se_hdr::{ - brb::{ - ComponentMetadata, ComponentMetadataV1, SeHdrCommon, SeHdrConfBuilderTrait, - SeHdrPlainTrait, SeHdrPubBuilderTrait, SeHdrTrait, - }, - keys::{BinaryKeySlotV1, EcPubKeyCoordV1}, - }, - serializing::{ - bytesize, bytesize_confidential, confidential_read_slice, confidential_write_slice, - serde_base64, serde_hex_array, serde_hex_confidential_array, serde_hex_left_padded_u64, - serialize_to_bytes, - }, - try_copy_slice_to_array, - uvdata::{ - AeadCipherTrait, AeadDataTrait, AeadPlainDataTrait, KeyExchangeTrait, UvDataPlainTrait, - UvDataTrait, - }, - uvdata_builder::{AeadCipherBuilderTrait, KeyExchangeBuilderTrait}, - PlaintextControlFlagsV1, SecretControlFlagsV1, PSW, - }, +use crate::error::Error; +use crate::misc::PAGESIZE; +use crate::pv_utils::error::Result; +use crate::pv_utils::misc::display_indented; +use crate::pv_utils::se_hdr::brb::{ + ComponentMetadata, ComponentMetadataV1, SeHdrCommon, SeHdrConfBuilderTrait, SeHdrPlainTrait, + SeHdrPubBuilderTrait, SeHdrTrait, +}; +use crate::pv_utils::se_hdr::keys::{BinaryKeySlotV1, EcPubKeyCoordV1}; +use crate::pv_utils::serializing::{ + bytesize, bytesize_confidential, confidential_read_slice, confidential_write_slice, + serde_base64, serde_hex_array, serde_hex_confidential_array, serde_hex_left_padded_u64, + serialize_to_bytes, +}; +use crate::pv_utils::uvdata::{ + AeadCipherTrait, AeadDataTrait, AeadPlainDataTrait, KeyExchangeTrait, UvDataPlainTrait, + UvDataTrait, +}; +use crate::pv_utils::uvdata_builder::{AeadCipherBuilderTrait, KeyExchangeBuilderTrait}; +use crate::pv_utils::{ + try_copy_slice_to_array, PlaintextControlFlagsV1, SecretControlFlagsV1, PSW, }; #[derive(Debug)] diff --git a/rust/pvimg/src/pv_utils/se_hdr/keys.rs b/rust/pvimg/src/pv_utils/se_hdr/keys.rs index abca0cc0..85639bde 100644 --- a/rust/pvimg/src/pv_utils/se_hdr/keys.rs +++ b/rust/pvimg/src/pv_utils/se_hdr/keys.rs @@ -2,22 +2,22 @@ // // Copyright IBM Corp. 2024 -use std::{fmt::Display, mem::size_of}; +use std::fmt::Display; +use std::mem::size_of; use base64::prelude::*; -use deku::{ctx::Endian, DekuRead, DekuWrite}; -use openssl::{ - hash::{hash, MessageDigest}, - pkey::{PKey, PKeyRef, Public}, -}; -use pv::{request::EcPubKeyCoord, static_assert}; +use deku::ctx::Endian; +use deku::{DekuRead, DekuWrite}; +use openssl::hash::{hash, MessageDigest}; +use openssl::pkey::{PKey, PKeyRef, Public}; +use pv::request::EcPubKeyCoord; +use pv::static_assert; use serde::{Deserialize, Serialize}; use utils::HexSlice; -use crate::{ - error::{Error, Result}, - pv_utils::{serializing::serde_hex_array, try_copy_slice_to_array}, -}; +use crate::error::{Error, Result}; +use crate::pv_utils::serializing::serde_hex_array; +use crate::pv_utils::try_copy_slice_to_array; /// Try to hash the public EC key. /// diff --git a/rust/pvimg/src/pv_utils/secured_comp.rs b/rust/pvimg/src/pv_utils/secured_comp.rs index 2f25842f..296b5097 100644 --- a/rust/pvimg/src/pv_utils/secured_comp.rs +++ b/rust/pvimg/src/pv_utils/secured_comp.rs @@ -2,28 +2,22 @@ // // Copyright IBM Corp. 2024 -use std::{ - fmt::{Debug, Formatter}, - io::{Read, Write}, - rc::Rc, -}; +use std::fmt::{Debug, Formatter}; +use std::io::{Read, Write}; +use std::rc::Rc; use log::debug; -use openssl::{ - bn::BigNum, - cipher::{Cipher, CipherRef}, - cipher_ctx::{CipherCtx, CipherCtxRef}, - hash::{Hasher, MessageDigest}, - nid::Nid, -}; +use openssl::bn::BigNum; +use openssl::cipher::{Cipher, CipherRef}; +use openssl::cipher_ctx::{CipherCtx, CipherCtxRef}; +use openssl::hash::{Hasher, MessageDigest}; +use openssl::nid::Nid; use pv::request::{Confidential, SymKey, SymKeyType}; use super::{try_copy_slice_to_array, Layout}; -use crate::pv_utils::{ - error::{Error, PvError, Result}, - se_hdr::{ComponentMetadata, ComponentMetadataV1}, - Interval, -}; +use crate::pv_utils::error::{Error, PvError, Result}; +use crate::pv_utils::se_hdr::{ComponentMetadata, ComponentMetadataV1}; +use crate::pv_utils::Interval; /// Operation mode for component preparation. #[allow(unused)] @@ -651,7 +645,8 @@ impl SecuredComponentBuilder { #[allow(clippy::shadow_unrelated)] #[cfg(test)] mod tests { - use std::{fmt::Debug, io::Cursor}; + use std::fmt::Debug; + use std::io::Cursor; use pv::request::Aes256XtsKey; diff --git a/rust/pvimg/src/pv_utils/serializing.rs b/rust/pvimg/src/pv_utils/serializing.rs index c94b0b9e..c036ec7b 100644 --- a/rust/pvimg/src/pv_utils/serializing.rs +++ b/rust/pvimg/src/pv_utils/serializing.rs @@ -2,10 +2,9 @@ // // Copyright IBM Corp. 2024 -use deku::{ - reader::Reader, writer::Writer, DekuContainerRead, DekuContainerWrite, DekuError, DekuReader, - DekuWriter, -}; +use deku::reader::Reader; +use deku::writer::Writer; +use deku::{DekuContainerRead, DekuContainerWrite, DekuError, DekuReader, DekuWriter}; use pv::request::{Confidential, Zeroize}; use crate::pv_utils::error::Result; @@ -13,8 +12,7 @@ use crate::pv_utils::error::Result; pub mod serde_hex_left_padded_u64 { use std::fmt::LowerHex; - use serde::Deserializer; - use serde::{Deserialize, Serialize, Serializer}; + use serde::{Deserialize, Deserializer, Serialize, Serializer}; pub fn serialize( data: &B, @@ -219,7 +217,8 @@ where #[cfg(test)] mod tests { - use deku::{ctx::Endian, DekuContainerWrite, DekuRead, DekuWrite}; + use deku::ctx::Endian; + use deku::{DekuContainerWrite, DekuRead, DekuWrite}; use pv::request::Confidential; use crate::pv_utils::serializing::{confidential_read_slice, confidential_write_slice}; diff --git a/rust/pvimg/src/pv_utils/uv_keys.rs b/rust/pvimg/src/pv_utils/uv_keys.rs index 8d785e91..ce3da76a 100644 --- a/rust/pvimg/src/pv_utils/uv_keys.rs +++ b/rust/pvimg/src/pv_utils/uv_keys.rs @@ -119,7 +119,8 @@ mod tests { use pv::misc::decode_hex; - use crate::{pv_utils::uv_keys::UvKeyHashV1, uvdata::UvKeyHashesV1}; + use crate::pv_utils::uv_keys::UvKeyHashV1; + use crate::uvdata::UvKeyHashesV1; #[test] fn from_reader() { diff --git a/rust/pvimg/src/pv_utils/uvdata.rs b/rust/pvimg/src/pv_utils/uvdata.rs index c6ed9567..5c2e8f80 100644 --- a/rust/pvimg/src/pv_utils/uvdata.rs +++ b/rust/pvimg/src/pv_utils/uvdata.rs @@ -3,17 +3,14 @@ // Copyright IBM Corp. 2024 use enum_dispatch::enum_dispatch; +use pv::request::openssl::pkey::{PKey, PKeyRef, Private, Public}; use pv::request::{ - decrypt_aead, derive_aes256_gcm_key, encrypt_aead, - openssl::pkey::{PKey, PKeyRef, Private, Public}, - Confidential, SymKey, SymKeyType, + decrypt_aead, derive_aes256_gcm_key, encrypt_aead, Confidential, SymKey, SymKeyType, }; use super::se_hdr::{SeHdrBinV1, SeHdrData, SeHdrVersioned}; -use crate::pv_utils::{ - error::{Error, Result}, - serializing::deserialize_from_bytes, -}; +use crate::pv_utils::error::{Error, Result}; +use crate::pv_utils::serializing::deserialize_from_bytes; /// Trait to be used for Authenticated Encryption with Associated Data (AEAD) /// data structures. diff --git a/rust/pvimg/src/pv_utils/uvdata_builder.rs b/rust/pvimg/src/pv_utils/uvdata_builder.rs index 58cbd740..c50f1927 100644 --- a/rust/pvimg/src/pv_utils/uvdata_builder.rs +++ b/rust/pvimg/src/pv_utils/uvdata_builder.rs @@ -7,11 +7,9 @@ use openssl::pkey::{PKey, PKeyRef, Private, Public}; use pv::request::{Confidential, SymKey}; use super::Error; -use crate::pv_utils::{ - error::Result, - se_hdr::SeHdrData, - uvdata::{AeadCipherTrait, UvDataPlainTrait}, -}; +use crate::pv_utils::error::Result; +use crate::pv_utils::se_hdr::SeHdrData; +use crate::pv_utils::uvdata::{AeadCipherTrait, UvDataPlainTrait}; #[enum_dispatch] pub trait AeadCipherBuilderTrait: AeadCipherTrait { diff --git a/rust/pvimg/src/se_img.rs b/rust/pvimg/src/se_img.rs index ef8722d8..14090c60 100644 --- a/rust/pvimg/src/se_img.rs +++ b/rust/pvimg/src/se_img.rs @@ -2,31 +2,34 @@ // // Copyright IBM Corp. 2024 -use std::{ - fmt::Display, - io::{Cursor, Seek, SeekFrom, Write}, - path::PathBuf, - rc::Rc, -}; +use std::fmt::Display; +use std::io::{Cursor, Seek, SeekFrom, Write}; +use std::path::PathBuf; +use std::rc::Rc; use anyhow::{anyhow, Context, Result}; use deku::DekuContainerRead; use log::debug; use openssl::pkey::{PKey, Public}; -use pv::{misc::read_file, request::Confidential}; -use pvimg::{ - error::Error, - misc::{round_up, serialize_to_bytes, ShortPsw, PSW, PSW_MASK_BA, PSW_MASK_EA}, - secured_comp::{ComponentTrait, Interval, Layout, SecuredComponent, SecuredComponentBuilder}, - uvdata::{ - BuilderTrait, PlaintextControlFlagsV1, SeHdrBuilder, SeHdrVersion, SecretControlFlagsV1, - }, +use pv::misc::read_file; +use pv::request::Confidential; +use pvimg::error::Error; +use pvimg::misc::{round_up, serialize_to_bytes, ShortPsw, PSW, PSW_MASK_BA, PSW_MASK_EA}; +use pvimg::secured_comp::{ + ComponentTrait, Interval, Layout, SecuredComponent, SecuredComponentBuilder, +}; +use pvimg::uvdata::{ + BuilderTrait, PlaintextControlFlagsV1, SeHdrBuilder, SeHdrVersion, SecretControlFlagsV1, }; +use crate::se_img_comps::ipib::Ipib; +use crate::se_img_comps::kernel::S390Kernel; +use crate::se_img_comps::metadata::ImgMetaData; +use crate::se_img_comps::sehdr::SeHdrComp; +use crate::se_img_comps::shortpsw::ShortPSWComp; use crate::se_img_comps::{ - create_ipib, ipib::Ipib, kernel::S390Kernel, metadata::ImgMetaData, render_stage3a, - render_stage3b, sehdr::SeHdrComp, shortpsw::ShortPSWComp, stage3a_path, stage3b_path, - CompTweakV1, Component, ComponentKind, STAGE3A_ENTRY, STAGE3A_INIT_ENTRY, STAGE3A_LOAD_ADDRESS, + create_ipib, render_stage3a, render_stage3b, stage3a_path, stage3b_path, CompTweakV1, + Component, ComponentKind, STAGE3A_ENTRY, STAGE3A_INIT_ENTRY, STAGE3A_LOAD_ADDRESS, }; pub struct SeHdrArgs<'a> { @@ -482,7 +485,8 @@ mod tests { use std::io::Cursor; use super::SeImgBuilder; - use crate::{se_img::stage3a_path, se_img_comps::stage3b_path}; + use crate::se_img::stage3a_path; + use crate::se_img_comps::stage3b_path; #[test] fn test_comp_ctx_new() { diff --git a/rust/pvimg/src/se_img_comps.rs b/rust/pvimg/src/se_img_comps.rs index 6175cc74..93abd97a 100644 --- a/rust/pvimg/src/se_img_comps.rs +++ b/rust/pvimg/src/se_img_comps.rs @@ -2,21 +2,25 @@ // // Copyright IBM Corp. 2024 -use std::{ - fmt::{Debug, Display}, - io::{Read, Seek, SeekFrom}, -}; +use std::fmt::{Debug, Display}; +use std::io::{Read, Seek, SeekFrom}; use anyhow::Context; -use deku::{ctx::Endian, DekuRead, DekuWrite}; +use deku::ctx::Endian; +use deku::{DekuRead, DekuWrite}; use enum_dispatch::enum_dispatch; use pv::request::random_array; -use pvimg::{error::Result, secured_comp::ComponentTrait}; +use pvimg::error::Result; +use pvimg::secured_comp::ComponentTrait; -use self::{ - cmdline::Cmdline, kernel::S390Kernel, metadata::ImgMetaData, ramdisk::Ramdisk, - sehdr::SeHdrComp, shortpsw::ShortPSWComp, stage3a::Stage3a, stage3b::Stage3b, -}; +use self::cmdline::Cmdline; +use self::kernel::S390Kernel; +use self::metadata::ImgMetaData; +use self::ramdisk::Ramdisk; +use self::sehdr::SeHdrComp; +use self::shortpsw::ShortPSWComp; +use self::stage3a::Stage3a; +use self::stage3b::Stage3b; pub use crate::se_img_comps::bootloader::{ create_ipib, render_stage3a, render_stage3b, stage3a_path, stage3b_path, STAGE3A_ENTRY, STAGE3A_INIT_ENTRY, STAGE3A_LOAD_ADDRESS, @@ -306,13 +310,12 @@ impl CompTweakV1 { #[cfg(test)] mod tests { use deku::{DekuContainerRead, DekuContainerWrite}; - use proptest::{ - prelude::{Just, Strategy}, - prop_assert_eq, prop_oneof, proptest, - }; + use proptest::prelude::{Just, Strategy}; + use proptest::{prop_assert_eq, prop_oneof, proptest}; use super::{ComponentCheckCtx, ComponentKind}; - use crate::se_img_comps::{check_components, kernel::S390Kernel, CompTweakPrefV1, CompTweakV1}; + use crate::se_img_comps::kernel::S390Kernel; + use crate::se_img_comps::{check_components, CompTweakPrefV1, CompTweakV1}; fn component_kind_strategy() -> impl Strategy { prop_oneof![ diff --git a/rust/pvimg/src/se_img_comps/bootloader.rs b/rust/pvimg/src/se_img_comps/bootloader.rs index 23910ba6..0f26dbe1 100644 --- a/rust/pvimg/src/se_img_comps/bootloader.rs +++ b/rust/pvimg/src/se_img_comps/bootloader.rs @@ -2,36 +2,33 @@ // // Copyright IBM Corp. 2024 -use std::{io::Cursor, path::PathBuf, rc::Rc}; +use std::io::Cursor; +use std::path::PathBuf; +use std::rc::Rc; pub mod ipl; mod stage3a_defs; mod stage3b_defs; use ipl::IPL_PARM_BLOCK_PV_VERSION; use log::trace; -use pvimg::{ - error::{Error, Result}, - misc::{serialize_to_bytes, PSW}, - secured_comp::Interval, -}; +use pvimg::error::{Error, Result}; +use pvimg::misc::{serialize_to_bytes, PSW}; +use pvimg::secured_comp::Interval; +use self::ipl::{ + ipl_parameter_block, ipl_pb0_pv, ipl_pb0_pv_comp, ipl_pbt_IPL_PBT_PV, ipl_pl_hdr, + IPL_PARM_BLOCK_VERSION, +}; pub use self::stage3a_defs::{ STAGE3A_BSS_ADDRESS, STAGE3A_BSS_SIZE, STAGE3A_ENTRY, STAGE3A_INIT_ENTRY, STAGE3A_LOAD_ADDRESS, }; -use self::{ - ipl::{ - ipl_parameter_block, ipl_pb0_pv, ipl_pb0_pv_comp, ipl_pbt_IPL_PBT_PV, ipl_pl_hdr, - IPL_PARM_BLOCK_VERSION, - }, - stage3b_defs::{memblob, stage3b_args}, -}; +use self::stage3b_defs::{memblob, stage3b_args}; use super::CompTweakPrefV1; -use crate::{ - se_img::ImgComponent, - se_img_comps::{ - bootloader::stage3a_defs::stage3a_args, stage3a::Stage3a, stage3b::Stage3b, ComponentKind, - }, -}; +use crate::se_img::ImgComponent; +use crate::se_img_comps::bootloader::stage3a_defs::stage3a_args; +use crate::se_img_comps::stage3a::Stage3a; +use crate::se_img_comps::stage3b::Stage3b; +use crate::se_img_comps::ComponentKind; /// Get the `PVIMG_PKGDATADIR` used for `pvimg` /// diff --git a/rust/pvimg/src/se_img_comps/bootloader/ipl.rs b/rust/pvimg/src/se_img_comps/bootloader/ipl.rs index c646612c..66519681 100644 --- a/rust/pvimg/src/se_img_comps/bootloader/ipl.rs +++ b/rust/pvimg/src/se_img_comps/bootloader/ipl.rs @@ -5,8 +5,10 @@ // Based on the output of rust-bindgen 0.69.1 #![allow(nonstandard_style, unused)] -use deku::{ctx::Endian, prelude::*}; -use pvimg::{error::Result, misc::bytesize}; +use deku::ctx::Endian; +use deku::prelude::*; +use pvimg::error::Result; +use pvimg::misc::bytesize; pub const IPL_FLAG_SECURE: u32 = 64; pub const IPL_RB_COMPONENT_FLAG_SIGNED: u32 = 128; diff --git a/rust/pvimg/src/se_img_comps/bootloader/stage3a_defs.rs b/rust/pvimg/src/se_img_comps/bootloader/stage3a_defs.rs index 0e866e2a..08134a31 100644 --- a/rust/pvimg/src/se_img_comps/bootloader/stage3a_defs.rs +++ b/rust/pvimg/src/se_img_comps/bootloader/stage3a_defs.rs @@ -4,7 +4,8 @@ // Based on the output of rust-bindgen 0.69.1 #![allow(nonstandard_style)] -use deku::{ctx::Endian, prelude::*}; +use deku::ctx::Endian; +use deku::prelude::*; pub const IMAGE_ENTRY: u64 = 0x10000; pub const STAGE3A_INIT_ENTRY: u64 = IMAGE_ENTRY; diff --git a/rust/pvimg/src/se_img_comps/bootloader/stage3b_defs.rs b/rust/pvimg/src/se_img_comps/bootloader/stage3b_defs.rs index d852f56f..98fce416 100644 --- a/rust/pvimg/src/se_img_comps/bootloader/stage3b_defs.rs +++ b/rust/pvimg/src/se_img_comps/bootloader/stage3b_defs.rs @@ -4,7 +4,8 @@ // Based on the output of rust-bindgen 0.69.1 #![allow(non_camel_case_types, non_snake_case, nonstandard_style)] -use deku::{ctx::Endian, prelude::*}; +use deku::ctx::Endian; +use deku::prelude::*; use pvimg::misc::PSW; #[derive(Debug, Default, Clone, DekuRead, DekuWrite)] diff --git a/rust/pvimg/src/se_img_comps/ipib.rs b/rust/pvimg/src/se_img_comps/ipib.rs index 01d0b55e..2147bd34 100644 --- a/rust/pvimg/src/se_img_comps/ipib.rs +++ b/rust/pvimg/src/se_img_comps/ipib.rs @@ -7,8 +7,7 @@ use std::io::{Read, Seek}; use pvimg::error::Result; use pvimg::secured_comp::ComponentTrait; -use super::ComponentKind; -use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug}; +use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug}; #[derive(Debug)] pub struct Ipib(CompReader); diff --git a/rust/pvimg/src/se_img_comps/metadata.rs b/rust/pvimg/src/se_img_comps/metadata.rs index ecea4f52..139bd16a 100644 --- a/rust/pvimg/src/se_img_comps/metadata.rs +++ b/rust/pvimg/src/se_img_comps/metadata.rs @@ -4,13 +4,12 @@ use std::io::{Cursor, Read, Seek}; -use pv::{request::SeImgMetaData, static_assert}; +use pv::request::SeImgMetaData; +use pv::static_assert; use pvimg::error::Result; -use super::{ - bootloader::{STAGE3A_BSS_ADDRESS, STAGE3A_BSS_SIZE}, - CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ComponentTrait, -}; +use super::bootloader::{STAGE3A_BSS_ADDRESS, STAGE3A_BSS_SIZE}; +use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ComponentTrait}; #[derive(Debug)] pub struct ImgMetaData(CompReader); diff --git a/rust/pvimg/src/se_img_comps/ramdisk.rs b/rust/pvimg/src/se_img_comps/ramdisk.rs index 01964ae7..d84228b5 100644 --- a/rust/pvimg/src/se_img_comps/ramdisk.rs +++ b/rust/pvimg/src/se_img_comps/ramdisk.rs @@ -6,8 +6,10 @@ use std::io::{Read, Seek}; use pvimg::error::Result; -use super::ComponentKind; -use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentTrait, ReadSeekDebug}; +use super::{ + CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ComponentTrait, + ReadSeekDebug, +}; #[derive(Debug)] pub struct Ramdisk(CompReader); diff --git a/rust/pvimg/src/se_img_comps/sehdr.rs b/rust/pvimg/src/se_img_comps/sehdr.rs index 1399a9c0..90734a56 100644 --- a/rust/pvimg/src/se_img_comps/sehdr.rs +++ b/rust/pvimg/src/se_img_comps/sehdr.rs @@ -7,8 +7,7 @@ use std::io::{Read, Seek}; use pvimg::error::Result; use pvimg::secured_comp::ComponentTrait; -use super::ComponentKind; -use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug}; +use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug}; #[derive(Debug)] pub struct SeHdrComp(pub CompReader); diff --git a/rust/pvimg/src/se_img_comps/shortpsw.rs b/rust/pvimg/src/se_img_comps/shortpsw.rs index c311357d..e7f29068 100644 --- a/rust/pvimg/src/se_img_comps/shortpsw.rs +++ b/rust/pvimg/src/se_img_comps/shortpsw.rs @@ -7,8 +7,7 @@ use std::io::{Read, Seek}; use pvimg::error::Result; use pvimg::secured_comp::ComponentTrait; -use super::ComponentKind; -use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug}; +use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug}; #[derive(Debug)] pub struct ShortPSWComp(CompReader); diff --git a/rust/pvimg/src/se_img_comps/stage3a.rs b/rust/pvimg/src/se_img_comps/stage3a.rs index d820ce82..4f81e91e 100644 --- a/rust/pvimg/src/se_img_comps/stage3a.rs +++ b/rust/pvimg/src/se_img_comps/stage3a.rs @@ -7,8 +7,7 @@ use std::io::{Read, Seek}; use pvimg::error::Result; use pvimg::secured_comp::ComponentTrait; -use super::ComponentKind; -use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug}; +use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug}; #[derive(Debug)] pub struct Stage3a(CompReader); diff --git a/rust/pvimg/src/se_img_comps/stage3b.rs b/rust/pvimg/src/se_img_comps/stage3b.rs index 028419f8..1c5288b7 100644 --- a/rust/pvimg/src/se_img_comps/stage3b.rs +++ b/rust/pvimg/src/se_img_comps/stage3b.rs @@ -7,8 +7,7 @@ use std::io::{Read, Seek}; use pvimg::error::Result; use pvimg::secured_comp::ComponentTrait; -use super::ComponentKind; -use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ReadSeekDebug}; +use super::{CompReader, ComponentCheckCtx, ComponentCheckTrait, ComponentKind, ReadSeekDebug}; #[derive(Debug)] pub struct Stage3b(CompReader); diff --git a/rust/pvinfo/build.rs b/rust/pvinfo/build.rs index 91212adf..f2cba165 100644 --- a/rust/pvinfo/build.rs +++ b/rust/pvinfo/build.rs @@ -4,11 +4,12 @@ // it under the terms of the MIT license. See LICENSE for details. #![allow(missing_docs)] -use clap::CommandFactory; -use clap_complete::{generate_to, Shell}; use std::env; use std::io::Error; +use clap::CommandFactory; +use clap_complete::{generate_to, Shell}; + include!("src/cli.rs"); fn main() -> Result<(), Error> { diff --git a/rust/pvinfo/src/handlers.rs b/rust/pvinfo/src/handlers.rs index 6758d7dc..9450e5a3 100644 --- a/rust/pvinfo/src/handlers.rs +++ b/rust/pvinfo/src/handlers.rs @@ -4,11 +4,12 @@ //! Handlers for processing CLI flags and subcommands +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; + use crate::constants::*; use crate::io_utils::{collect_bit_messages, collect_version_flags, read_hex_from_file}; use crate::strings::*; -use std::io::{self, Write}; -use std::path::{Path, PathBuf}; // Represents metadata for a supported content file. struct Content { @@ -18,7 +19,7 @@ struct Content { } impl Content { - //Reads a hex file, then prints either: + // Reads a hex file, then prints either: // bit messages or version flags fn handle_flag(&self, writer: &mut dyn Write, query_dir: &Path) -> io::Result { let hex = match read_hex_from_file(query_dir.join(self.file), self.label) { @@ -132,10 +133,12 @@ pub fn handle_supported_flags( // Unit Tests for handlers #[cfg(test)] mod test { - use super::*; use std::fs; + use tempfile::tempdir; + use super::*; + // Verifies that handle_supported_flags correctly processes all #[test] fn test_handle_supported_flags_with_buffer() { diff --git a/rust/pvinfo/src/io_utils.rs b/rust/pvinfo/src/io_utils.rs index 74f35322..a01ffedc 100644 --- a/rust/pvinfo/src/io_utils.rs +++ b/rust/pvinfo/src/io_utils.rs @@ -4,14 +4,15 @@ //! I/O utilities for the PV Info Tool -use crate::constants::*; -use anyhow::{Context, Result}; -use pv_core::misc::{read_file, read_file_string, try_parse_u64}; -use pv_core::misc::{Flags, Msb0Flags64}; use std::collections::HashMap; use std::path::Path; use std::str; +use anyhow::{Context, Result}; +use pv_core::misc::{read_file, read_file_string, try_parse_u64, Flags, Msb0Flags64}; + +use crate::constants::*; + // Verify that the Ultravisor directory exists pub fn check_uv_exists() -> Result<()> { let uv_path = Path::new(BASE_DIR); @@ -143,11 +144,13 @@ pub fn collect_limits(query_dir: &Path) -> HashMap { mod test { //! Unit Tests for io_utils - use super::*; use std::io::{self, Write}; use std::path::Path; + use tempfile::{tempdir, NamedTempFile}; + use super::*; + // Tests check_uv_exists() by observing the real BASE_DIR at test runtime // if BASE_DIR exists on the machine running the tests, check_uv_exists() must return Ok // otherwise, it must return Err(anyhow::Error) whose cause is an io::ErrorKind::NotFound, @@ -280,7 +283,8 @@ mod test { let hex = (1u64 << 63) | (1u64 << 61); let messages = collect_bit_messages(hex, desc); - // Expect "First Feature" and "Third Feature" (and the reserved line should get the " Bit-" if matched) + // Expect "First Feature" and "Third Feature" (and the reserved line should get the " + // Bit-" if matched) assert!(messages.iter().any(|m| m == "First Feature")); assert!(messages.iter().any(|m| m == "Third Feature")); // reserved wasn't set here; now test reserved specifically below diff --git a/rust/pvinfo/src/main.rs b/rust/pvinfo/src/main.rs index 785ed967..bec2976a 100644 --- a/rust/pvinfo/src/main.rs +++ b/rust/pvinfo/src/main.rs @@ -4,9 +4,10 @@ //! Main function for the PV Info Tool +use std::io::{self, Write}; + use anyhow::Result; use clap::Parser; -use std::io::{self, Write}; mod cli; mod constants; @@ -16,13 +17,14 @@ mod pvinfo; mod se_status; mod strings; +use std::path::PathBuf; + use crate::cli::{CliOptions, Commands, OutputFormat}; use crate::constants::*; use crate::handlers::handle_supported_flags; use crate::io_utils::check_uv_exists; use crate::pvinfo::PvInfo; use crate::se_status::SeStatus; -use std::path::PathBuf; fn main() -> Result<()> { // Parse CLI arguments and apply post-processing diff --git a/rust/pvinfo/src/pvinfo.rs b/rust/pvinfo/src/pvinfo.rs index 116b0452..2d9f9dba 100644 --- a/rust/pvinfo/src/pvinfo.rs +++ b/rust/pvinfo/src/pvinfo.rs @@ -4,6 +4,12 @@ //! PV Info method implementation for the PV Info Tool +use std::collections::HashMap; +use std::fmt; +use std::path::Path; + +use serde::Serialize; + use crate::cli::CliOptions; use crate::constants::*; use crate::io_utils::{ @@ -12,10 +18,6 @@ use crate::io_utils::{ }; use crate::se_status::*; use crate::strings::*; -use serde::Serialize; -use std::collections::HashMap; -use std::fmt; -use std::path::Path; #[derive(Serialize)] pub struct PvInfo { @@ -262,9 +264,10 @@ impl fmt::Display for PvInfo { mod test { //! Unit Tests for pvinfo_method + use std::collections::HashMap; + use super::*; use crate::se_status::SeStatus; - use std::collections::HashMap; // Test that Display for PvInfo produces a truly empty string // when all optional fields are None/ diff --git a/rust/pvinfo/src/se_status.rs b/rust/pvinfo/src/se_status.rs index adea23fe..1a509e40 100644 --- a/rust/pvinfo/src/se_status.rs +++ b/rust/pvinfo/src/se_status.rs @@ -4,8 +4,9 @@ //! se-status definitions for the PV Info Tool -use serde::Serialize; // Trait for serializing data structures (e.g., YAML) -use std::fmt; // Provides the `Display` trait for pretty-printing +use std::fmt; + +use serde::Serialize; // Trait for serializing data structures (e.g., YAML) // Provides the `Display` trait for pretty-printing /// Enum representing Secure Execution status @@ -67,8 +68,8 @@ mod test { use super::SeStatus; // Display implementation tests - // Verifies that each enum variant of SeStatus is converted into the expected human-readable string - // via the Display trait implementation + // Verifies that each enum variant of SeStatus is converted into the expected human-readable + // string via the Display trait implementation #[test] fn test_display_strings() { diff --git a/rust/pvsecret/build.rs b/rust/pvsecret/build.rs index f5054cad..99b55937 100644 --- a/rust/pvsecret/build.rs +++ b/rust/pvsecret/build.rs @@ -4,10 +4,11 @@ // it under the terms of the MIT license. See LICENSE for details. #![allow(missing_docs)] -use clap_complete::{generate_to, Shell}; use std::env; use std::io::Error; +use clap_complete::{generate_to, Shell}; + include!("src/cli.rs"); fn main() -> Result<(), Error> { diff --git a/rust/pvsecret/src/cli.rs b/rust/pvsecret/src/cli.rs index 939f40b3..1fb4937b 100644 --- a/rust/pvsecret/src/cli.rs +++ b/rust/pvsecret/src/cli.rs @@ -138,8 +138,8 @@ pub struct CreateSecretOpt { /// includes the relative file path and the SHA‑512 hash of the policy file, allowing the /// policy’s integrity to be verified. /// - /// This option conflicts with --user-data, because both options use the same user data field in - /// the ASR structure. + /// This option conflicts with --user-data, because both options use the same user data field + /// in the ASR structure. #[arg(long, value_name = "FILE", value_hint = ValueHint::FilePath, conflicts_with("user_data"))] pub policy: Option, diff --git a/rust/pvsecret/src/cmd.rs b/rust/pvsecret/src/cmd.rs index 10d99a5b..dd306ef0 100644 --- a/rust/pvsecret/src/cmd.rs +++ b/rust/pvsecret/src/cmd.rs @@ -22,18 +22,20 @@ mod retr; // Commands (directly) related to UVCs are only available on s389x #[cfg(target_arch = "s390x")] mod uv_cmd { - pub use super::*; pub use add::add; pub use list::list; pub use lock::lock; pub use retr::retr; + + pub use super::*; pub const UV_CMD_FN: &[&str] = &["+add", "+lock", "+list"]; } #[cfg(not(target_arch = "s390x"))] mod uv_cmd { - use crate::cli::{AddSecretOpt, ListSecretOpt, RetrSecretOptions}; use anyhow::{bail, Result}; + + use crate::cli::{AddSecretOpt, ListSecretOpt, RetrSecretOptions}; macro_rules! not_supp { ($name: ident $( ,$opt: ty )?) => { pub fn $name($(_: &$opt)?) -> Result<()> { diff --git a/rust/pvsecret/src/cmd/add.rs b/rust/pvsecret/src/cmd/add.rs index e55db54b..8b4ecc4f 100644 --- a/rust/pvsecret/src/cmd/add.rs +++ b/rust/pvsecret/src/cmd/add.rs @@ -2,18 +2,15 @@ // // Copyright IBM Corp. 2023 -use crate::{ - cli::{AddSecretOpt, AddSecretOptComb}, - cmd::list::list_uvc, -}; use anyhow::{bail, Context, Result}; use log::warn; -use pv::{ - secret::AddSecretRequest, - uv::{AddCmd, UvCmd, UvDevice}, -}; +use pv::secret::AddSecretRequest; +use pv::uv::{AddCmd, UvCmd, UvDevice}; use utils::get_reader_from_cli_file_arg; +use crate::cli::{AddSecretOpt, AddSecretOptComb}; +use crate::cmd::list::list_uvc; + /// Do an Add Secret UVC pub fn add(opt: &AddSecretOpt) -> Result<()> { let opt_comb = AddSecretOptComb::from(opt); diff --git a/rust/pvsecret/src/cmd/create.rs b/rust/pvsecret/src/cmd/create.rs index ca3aa190..26351e14 100644 --- a/rust/pvsecret/src/cmd/create.rs +++ b/rust/pvsecret/src/cmd/create.rs @@ -2,27 +2,20 @@ // // Copyright IBM Corp. 2023, 2024 -use std::{ - fs::OpenOptions, - io::{Read, Write}, - path::Path, -}; +use std::fs::OpenOptions; +use std::io::{Read, Write}; +use std::path::Path; use anyhow::{anyhow, bail, Context, Error, Result}; use log::{debug, info, trace, warn}; -use pv::request::openssl; -use pv::{ - misc::{ - decode_hex, encode_hex, open_file, pv_guest_bit_set, read_exact_file, read_file, - try_parse_u128, try_parse_u64, write, - }, - request::{ - openssl::pkey::{PKey, Private}, - BootHdrTags, PolicyReference, ReqEncrCtx, Request, SymKeyType, - }, - secret::{AddSecretFlags, AddSecretRequest, AddSecretVersion, ExtSecret, GuestSecret}, - uv::ConfigUid, +use pv::misc::{ + decode_hex, encode_hex, open_file, pv_guest_bit_set, read_exact_file, read_file, + try_parse_u128, try_parse_u64, write, }; +use pv::request::openssl::pkey::{PKey, Private}; +use pv::request::{openssl, BootHdrTags, PolicyReference, ReqEncrCtx, Request, SymKeyType}; +use pv::secret::{AddSecretFlags, AddSecretRequest, AddSecretVersion, ExtSecret, GuestSecret}; +use pv::uv::ConfigUid; use serde_yaml::Value; use utils::get_writer_from_cli_file_arg; use zerocopy::IntoBytes; diff --git a/rust/pvsecret/src/cmd/list.rs b/rust/pvsecret/src/cmd/list.rs index f846773e..591130e8 100644 --- a/rust/pvsecret/src/cmd/list.rs +++ b/rust/pvsecret/src/cmd/list.rs @@ -4,12 +4,13 @@ use std::io::ErrorKind; -use crate::cli::{ListSecretOpt, ListSecretOptComb, ListSecretOutputType}; use anyhow::{Context, Error, Result}; use log::{info, warn}; use pv::uv::{ListCmd, SecretList, UvDevice}; use utils::{get_writer_from_cli_file_arg, STDOUT}; +use crate::cli::{ListSecretOpt, ListSecretOptComb, ListSecretOutputType}; + const SECRET_LIST_BUF_SIZE: usize = 4; /// Do a List Secrets UVC diff --git a/rust/pvsecret/src/cmd/retr.rs b/rust/pvsecret/src/cmd/retr.rs index 37fb3838..2500779f 100644 --- a/rust/pvsecret/src/cmd/retr.rs +++ b/rust/pvsecret/src/cmd/retr.rs @@ -2,16 +2,14 @@ // // Copyright IBM Corp. 2024 -use std::{collections::VecDeque, fmt::Display}; +use std::collections::VecDeque; +use std::fmt::Display; use anyhow::{anyhow, bail, Context, Result}; use log::{debug, info, warn}; -use pv::{ - misc::open_file, - misc::write, - secret::{GuestSecret, RetrievedSecret}, - uv::{RetrieveCmd, SecretEntry, SecretId, SecretList, UvDevice}, -}; +use pv::misc::{open_file, write}; +use pv::secret::{GuestSecret, RetrievedSecret}; +use pv::uv::{RetrieveCmd, SecretEntry, SecretId, SecretList, UvDevice}; use utils::get_writer_from_cli_file_arg; use super::list::list_uvc; diff --git a/rust/pvsecret/src/cmd/verify.rs b/rust/pvsecret/src/cmd/verify.rs index bf6fc8f8..347b4918 100644 --- a/rust/pvsecret/src/cmd/verify.rs +++ b/rust/pvsecret/src/cmd/verify.rs @@ -2,16 +2,15 @@ // // Copyright IBM Corp. 2024 -use crate::cli::{VerifyOpt, VerifyOptComb}; use anyhow::{anyhow, Context, Result}; use log::warn; use pv::misc::{read_certs, read_file}; -use pv::{ - request::openssl::pkey::{PKey, Public}, - secret::verify_asrcb_and_get_user_data, -}; +use pv::request::openssl::pkey::{PKey, Public}; +use pv::secret::verify_asrcb_and_get_user_data; use utils::{get_reader_from_cli_file_arg, get_writer_from_cli_file_arg}; +use crate::cli::{VerifyOpt, VerifyOptComb}; + /// read the content of a DER or PEM x509 and return the public key fn read_sgn_key(path: &str) -> Result> { read_certs(read_file(path, "user-signing key")?)? diff --git a/rust/pvsecret/src/main.rs b/rust/pvsecret/src/main.rs index 4072f479..820ba91e 100644 --- a/rust/pvsecret/src/main.rs +++ b/rust/pvsecret/src/main.rs @@ -6,10 +6,11 @@ mod cli; mod cmd; +use std::process::ExitCode; + use clap::{CommandFactory, Parser}; use cli::{validate_cli, CliOptions, Command}; use log::trace; -use std::process::ExitCode; use utils::{print_cli_error, print_error, print_version, PvLogger}; static LOGGER: PvLogger = PvLogger; diff --git a/rust/pvverify/build.rs b/rust/pvverify/build.rs index f5574933..aefdb87f 100644 --- a/rust/pvverify/build.rs +++ b/rust/pvverify/build.rs @@ -3,11 +3,12 @@ // Copyright IBM Corp. 2025 #![allow(missing_docs)] -use clap::{CommandFactory, ValueEnum}; -use clap_complete::{generate_to, Shell}; use std::env; use std::io::Error; +use clap::{CommandFactory, ValueEnum}; +use clap_complete::{generate_to, Shell}; + include!("src/cli.rs"); fn main() -> Result<(), Error> { diff --git a/rust/utils/src/cli.rs b/rust/utils/src/cli.rs index 84ed84f1..bae1b378 100644 --- a/rust/utils/src/cli.rs +++ b/rust/utils/src/cli.rs @@ -2,21 +2,17 @@ // // Copyright IBM Corp. 2023, 2024 -use clap::{ArgAction, ArgGroup, Args, Command, ValueHint}; -use log::{info, warn, LevelFilter}; -use pv::misc::read_file; -use pv::{ - misc::{create_file, open_file, read_certs}, - request::{ - openssl::pkey::{PKey, Public}, - HkdVerifier, - }, - Error, Result, -}; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use std::process::ExitCode; +use clap::{ArgAction, ArgGroup, Args, Command, ValueHint}; +use log::{info, warn, LevelFilter}; +use pv::misc::{create_file, open_file, read_certs, read_file}; +use pv::request::openssl::pkey::{PKey, Public}; +use pv::request::HkdVerifier; +use pv::{Error, Result}; + /// CLI Argument collection for handling host-keys, IBM signing keys, and certificates. #[derive(Args, Debug, Clone, PartialEq, Eq, Default)] #[command( diff --git a/rust/utils/src/exit_code.rs b/rust/utils/src/exit_code.rs index 450f6f2e..5691808c 100644 --- a/rust/utils/src/exit_code.rs +++ b/rust/utils/src/exit_code.rs @@ -88,7 +88,8 @@ macro_rules! impl_exitcodetrait { #[cfg(test)] mod tests { - use crate::{exit_code::ExitCodeDoc, ExitCodeTrait, ExitCodeVariantDoc}; + use crate::exit_code::ExitCodeDoc; + use crate::{ExitCodeTrait, ExitCodeVariantDoc}; #[test] fn test_impl_exitcodetrait_with_doc() { diff --git a/rust/utils/src/file.rs b/rust/utils/src/file.rs index 4014799d..aefdd96e 100644 --- a/rust/utils/src/file.rs +++ b/rust/utils/src/file.rs @@ -2,13 +2,11 @@ // // Copyright IBM Corp. 2024 -use std::{ - ffi::OsStr, - fs::{rename, File, OpenOptions}, - io::{self, Seek, SeekFrom, Write}, - os::unix::fs::OpenOptionsExt, - path::Path, -}; +use std::ffi::OsStr; +use std::fs::{rename, File, OpenOptions}; +use std::io::{self, Seek, SeekFrom, Write}; +use std::os::unix::fs::OpenOptionsExt; +use std::path::Path; use pv::{Error, FileAccessErrorType, PvCoreError, Result}; @@ -80,7 +78,8 @@ impl AtomicFile { /// ``` /// # use utils::AtomicFile; /// - /// let file = AtomicFile::with_extension("test", ".incomplete", &mut std::fs::OpenOptions::new()).unwrap(); + /// let file = AtomicFile::with_extension("test", ".incomplete", &mut std::fs::OpenOptions::new()) + /// .unwrap(); /// ``` pub fn with_extension, S: AsRef>( output: P, diff --git a/rust/utils/src/hexslice.rs b/rust/utils/src/hexslice.rs index eb9b7b2e..15db92fc 100644 --- a/rust/utils/src/hexslice.rs +++ b/rust/utils/src/hexslice.rs @@ -2,9 +2,10 @@ // // Copyright IBM Corp. 2024 -use serde::Serialize; use std::fmt::{Display, Formatter}; +use serde::Serialize; + /// Displays/Serializes an u8-slice into a Hex-string /// /// Thin wrapper around an u8-slice. diff --git a/rust/utils/src/hostname.rs b/rust/utils/src/hostname.rs index 9fb24f7c..5bcb4658 100644 --- a/rust/utils/src/hostname.rs +++ b/rust/utils/src/hostname.rs @@ -2,7 +2,8 @@ // // Copyright IBM Corp. 2026 -use std::{ffi::CStr, io}; +use std::ffi::CStr; +use std::io; /// Returns the maximum hostname length supported by the system. /// @@ -12,7 +13,8 @@ use std::{ffi::CStr, io}; fn max_hostname_len() -> usize { const _POSIX_HOST_NAME_MAX: usize = 255; - // SAFETY: sysconf is safe to call with _SC_HOST_NAME_MAX and only reads system configuration without side effects. + // SAFETY: sysconf is safe to call with _SC_HOST_NAME_MAX and only reads system configuration + // without side effects. let n = unsafe { libc::sysconf(libc::_SC_HOST_NAME_MAX) }; if n < 0 { _POSIX_HOST_NAME_MAX diff --git a/rust/utils/src/lib.rs b/rust/utils/src/lib.rs index 8af368ee..7252ed7f 100644 --- a/rust/utils/src/lib.rs +++ b/rust/utils/src/lib.rs @@ -14,20 +14,18 @@ mod tmpfile; pub use ::log::LevelFilter; -pub use crate::{ - cli::{ - combined_path_opt, combined_path_req, get_reader_from_cli_file_arg, - get_writer_from_cli_file_arg, print_cli_error, print_error, CertificateOptions, - DeprecatedVerbosityOptions, VerbosityOptions, STDIN, STDOUT, - }, - exit_code::{docstring, ExitCodeDoc, ExitCodeTrait, ExitCodeVariantDoc}, - file::{AtomicFile, AtomicFileOperation}, - hexslice::HexSlice, - hostname::gethostname, - json::S390ToolsMetaData, - log::PvLogger, - tmpfile::TemporaryDirectory, +pub use crate::cli::{ + combined_path_opt, combined_path_req, get_reader_from_cli_file_arg, + get_writer_from_cli_file_arg, print_cli_error, print_error, CertificateOptions, + DeprecatedVerbosityOptions, VerbosityOptions, STDIN, STDOUT, }; +pub use crate::exit_code::{docstring, ExitCodeDoc, ExitCodeTrait, ExitCodeVariantDoc}; +pub use crate::file::{AtomicFile, AtomicFileOperation}; +pub use crate::hexslice::HexSlice; +pub use crate::hostname::gethostname; +pub use crate::json::S390ToolsMetaData; +pub use crate::log::PvLogger; +pub use crate::tmpfile::TemporaryDirectory; /// Get the s390-tools release string /// diff --git a/rust/utils/src/tmpfile.rs b/rust/utils/src/tmpfile.rs index 883d5586..eaaaa61a 100644 --- a/rust/utils/src/tmpfile.rs +++ b/rust/utils/src/tmpfile.rs @@ -2,11 +2,9 @@ // // Copyright IBM Corp. 2024 -use std::{ - ffi::{CString, OsStr}, - os::unix::prelude::OsStrExt, - path::{Path, PathBuf}, -}; +use std::ffi::{CString, OsStr}; +use std::os::unix::prelude::OsStrExt; +use std::path::{Path, PathBuf}; /// Rust wrapper for `libc::mkdtemp` fn mkdtemp>(template: P) -> Result {