From f24fa790cdc006d02bc829e2963a5ad1bd7aaed0 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Wed, 7 Aug 2024 00:55:35 -0700 Subject: [PATCH] Migrate to 2021 edition Also avoid suppressing some lints Signed-off-by: Travis Finkenauer --- Cargo.toml | 3 ++- tss-esapi-sys/Cargo.toml | 2 +- tss-esapi/Cargo.toml | 2 +- tss-esapi/src/abstraction/transient/mod.rs | 1 - tss-esapi/src/lib.rs | 4 ---- tss-esapi/src/structures/buffers/public.rs | 3 +-- tss-esapi/src/structures/buffers/sensitive.rs | 3 +-- .../structures/buffers/sensitive_create.rs | 3 +-- tss-esapi/src/structures/ecc/point.rs | 6 +---- tss-esapi/src/structures/nv/storage/public.rs | 3 +-- tss-esapi/test_all.sh | 22 +++++++++++++++++++ .../tests/integration_tests/common/mod.rs | 11 ---------- .../integration_tests/tcti_ldr_tests/mod.rs | 1 - 13 files changed, 31 insertions(+), 33 deletions(-) create mode 100755 tss-esapi/test_all.sh diff --git a/Cargo.toml b/Cargo.toml index 324e058b..e88eb84a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,3 @@ [workspace] -members = ["tss-esapi", "tss-esapi-sys"] \ No newline at end of file +resolver = "2" +members = ["tss-esapi", "tss-esapi-sys"] diff --git a/tss-esapi-sys/Cargo.toml b/tss-esapi-sys/Cargo.toml index 0e8615fc..fc8152c8 100644 --- a/tss-esapi-sys/Cargo.toml +++ b/tss-esapi-sys/Cargo.toml @@ -2,7 +2,7 @@ name = "tss-esapi-sys" version = "0.5.0" authors = ["Parsec Project Contributors"] -edition = "2018" +edition = "2021" description = "FFI wrapper around TSS 2.0 Enhanced System API" readme = "README.md" keywords = ["tpm", "tss", "esys", "esapi"] diff --git a/tss-esapi/Cargo.toml b/tss-esapi/Cargo.toml index f89fee56..bf0ad941 100644 --- a/tss-esapi/Cargo.toml +++ b/tss-esapi/Cargo.toml @@ -2,7 +2,7 @@ name = "tss-esapi" version = "8.0.0-alpha" authors = ["Parsec Project Contributors"] -edition = "2018" # TODO Update edition to 2021 - Remove the disabled lints that are due to using old edition. +edition = "2021" description = "Rust-native wrapper around TSS 2.0 Enhanced System API" readme = "README.md" keywords = ["tpm", "tss", "esys", "esapi"] diff --git a/tss-esapi/src/abstraction/transient/mod.rs b/tss-esapi/src/abstraction/transient/mod.rs index f378383f..bff3881c 100644 --- a/tss-esapi/src/abstraction/transient/mod.rs +++ b/tss-esapi/src/abstraction/transient/mod.rs @@ -118,7 +118,6 @@ pub struct ObjectWrapper { /// /// This abstraction makes public key cryptography more accessible, focusing on asymmetric /// encryption and signatures in particular, by allowing users to offload object and session management. -#[allow(clippy::module_name_repetitions)] #[derive(Debug)] pub struct TransientKeyContext { context: Context, diff --git a/tss-esapi/src/lib.rs b/tss-esapi/src/lib.rs index 646c2baf..cd2704ca 100644 --- a/tss-esapi/src/lib.rs +++ b/tss-esapi/src/lib.rs @@ -29,10 +29,6 @@ missing_copy_implementations, rustdoc::broken_intra_doc_links, )] -// This comes from Zeroize they changed version of Syn used -// when zeroize_derive was updated to Rust Edition 2021. -// TODO: Remove this when updating Rust Edition. -#![allow(clippy::multiple_crate_versions)] //! # TSS 2.0 Rust Wrapper over Enhanced System API //! This crate exposes the functionality of the TCG Software Stack Enhanced System API to //! Rust developers, both directly through FFI bindings and through more Rust-tailored interfaces diff --git a/tss-esapi/src/structures/buffers/public.rs b/tss-esapi/src/structures/buffers/public.rs index 5f2ccc25..74b2b512 100644 --- a/tss-esapi/src/structures/buffers/public.rs +++ b/tss-esapi/src/structures/buffers/public.rs @@ -24,8 +24,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop}; pub struct PublicBuffer(Vec); impl PublicBuffer { - #[allow(unused_qualifications)] - pub const MAX_SIZE: usize = std::mem::size_of::(); + pub const MAX_SIZE: usize = size_of::(); pub fn value(&self) -> &[u8] { &self.0 diff --git a/tss-esapi/src/structures/buffers/sensitive.rs b/tss-esapi/src/structures/buffers/sensitive.rs index a8f3eb38..f345c102 100644 --- a/tss-esapi/src/structures/buffers/sensitive.rs +++ b/tss-esapi/src/structures/buffers/sensitive.rs @@ -23,8 +23,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop}; pub struct SensitiveBuffer(Vec); impl SensitiveBuffer { - #[allow(unused_qualifications)] - pub const MAX_SIZE: usize = std::mem::size_of::(); + pub const MAX_SIZE: usize = size_of::(); pub fn value(&self) -> &[u8] { &self.0 diff --git a/tss-esapi/src/structures/buffers/sensitive_create.rs b/tss-esapi/src/structures/buffers/sensitive_create.rs index 96a9f6f0..2eee8bf3 100644 --- a/tss-esapi/src/structures/buffers/sensitive_create.rs +++ b/tss-esapi/src/structures/buffers/sensitive_create.rs @@ -23,8 +23,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop}; pub struct SensitiveCreateBuffer(Vec); impl SensitiveCreateBuffer { - #[allow(unused_qualifications)] - pub const MAX_SIZE: usize = std::mem::size_of::(); + pub const MAX_SIZE: usize = size_of::(); pub const MIN_SIZE: usize = 4; /// Returns the content of the buffer. diff --git a/tss-esapi/src/structures/ecc/point.rs b/tss-esapi/src/structures/ecc/point.rs index 2d83b9c7..317fbe77 100644 --- a/tss-esapi/src/structures/ecc/point.rs +++ b/tss-esapi/src/structures/ecc/point.rs @@ -49,11 +49,7 @@ impl From for TPMS_ECC_POINT { impl From for TPM2B_ECC_POINT { fn from(ecc_point: EccPoint) -> Self { - #[allow(unused_qualifications)] - let size = std::mem::size_of::() - + ecc_point.x().len() - + std::mem::size_of::() - + ecc_point.y().len(); + let size = size_of::() + ecc_point.x().len() + size_of::() + ecc_point.y().len(); TPM2B_ECC_POINT { size: size as u16, point: ecc_point.into(), diff --git a/tss-esapi/src/structures/nv/storage/public.rs b/tss-esapi/src/structures/nv/storage/public.rs index b4d674ef..47b1f898 100644 --- a/tss-esapi/src/structures/nv/storage/public.rs +++ b/tss-esapi/src/structures/nv/storage/public.rs @@ -27,8 +27,7 @@ pub struct NvPublic { } impl NvPublic { - #[allow(unused_qualifications)] - const MAX_SIZE: usize = std::mem::size_of::(); + const MAX_SIZE: usize = size_of::(); pub fn nv_index(&self) -> NvIndexTpmHandle { self.nv_index diff --git a/tss-esapi/test_all.sh b/tss-esapi/test_all.sh new file mode 100755 index 00000000..a49f90d4 --- /dev/null +++ b/tss-esapi/test_all.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -eux + +CARGO="${CARGO:-cargo}" +export TPM2_TSS_PATH="${TPM2_TSS_PATH:-$HOME/tpm2-tss-3.2.2}" + +NUM=1 +t() { + echo "TEST ${NUM}" + ${CARGO} t --no-run --no-default-features --features 'generate-bindings integration-tests serde' + NUM=$((NUM + 1)) +} + +DEFAULT=('' '--no-default-features') + +for X in "${DEFAULT[@]}" ; do + t $X --features 'generate-bindings' + t $X --features 'generate-bindings integration-tests' + t $X --features 'generate-bindings integration-tests serde' + t $X --features 'generate-bindings integration-tests serde abstraction' +done diff --git a/tss-esapi/tests/integration_tests/common/mod.rs b/tss-esapi/tests/integration_tests/common/mod.rs index 20f07201..18b1eb4d 100644 --- a/tss-esapi/tests/integration_tests/common/mod.rs +++ b/tss-esapi/tests/integration_tests/common/mod.rs @@ -48,7 +48,6 @@ pub use tpml_types_equality_checks::*; pub use tpms_types_equality_checks::*; pub use tpmt_types_equality_checks::*; -#[allow(dead_code)] pub const HASH: [u8; 64] = [ 0x69, 0x3E, 0xDB, 0x1B, 0x22, 0x79, 0x03, 0xF4, 0xC0, 0xBF, 0xD6, 0x91, 0x76, 0x37, 0x84, 0x69, 0x3E, 0xDB, 0x1B, 0x22, 0x79, 0x03, 0xF4, 0xC0, 0xBF, 0xD6, 0x91, 0x76, 0x37, 0x84, 0xA2, 0x94, @@ -56,7 +55,6 @@ pub const HASH: [u8; 64] = [ 0x92, 0x50, 0x35, 0xC2, 0x8C, 0x5C, 0x3C, 0xCA, 0xFE, 0x18, 0xE8, 0x81, 0x37, 0x78, 0x37, 0x78, ]; -#[allow(dead_code)] pub const KEY: [u8; 256] = [ 231, 97, 201, 180, 0, 1, 185, 150, 85, 90, 174, 188, 105, 133, 188, 3, 206, 5, 222, 71, 185, 1, 209, 243, 36, 130, 250, 116, 17, 0, 24, 4, 25, 225, 250, 198, 245, 210, 140, 23, 139, 169, 15, @@ -178,14 +176,12 @@ pub fn sensitives() -> [Sensitive; 4] { } static LOG_INIT: Once = Once::new(); -#[allow(dead_code)] pub fn setup_logging() { LOG_INIT.call_once(|| { env_logger::init(); }); } -#[allow(dead_code)] pub fn create_tcti() -> TctiNameConf { setup_logging(); @@ -195,13 +191,11 @@ pub fn create_tcti() -> TctiNameConf { } } -#[allow(dead_code)] pub fn create_ctx_without_session() -> Context { let tcti = create_tcti(); Context::new(tcti).unwrap() } -#[allow(dead_code)] pub fn create_ctx_with_session() -> Context { let mut ctx = create_ctx_without_session(); let session = ctx @@ -229,7 +223,6 @@ pub fn create_ctx_with_session() -> Context { ctx } -#[allow(dead_code)] pub fn decryption_key_pub() -> Public { utils::create_restricted_decryption_rsa_public( Cipher::aes_256_cfb() @@ -241,7 +234,6 @@ pub fn decryption_key_pub() -> Public { .expect("Failed to create a restricted decryption rsa public structure") } -#[allow(dead_code)] pub fn encryption_decryption_key_pub() -> Public { utils::create_unrestricted_encryption_decryption_rsa_public( RsaKeyBits::Rsa2048, @@ -250,7 +242,6 @@ pub fn encryption_decryption_key_pub() -> Public { .expect("Failed to create an unrestricted encryption decryption rsa public structure") } -#[allow(dead_code)] pub fn signing_key_pub() -> Public { utils::create_unrestricted_signing_rsa_public( RsaScheme::create(RsaSchemeAlgorithm::RsaSsa, Some(HashingAlgorithm::Sha256)) @@ -261,7 +252,6 @@ pub fn signing_key_pub() -> Public { .expect("Failed to create an unrestricted signing rsa public structure") } -#[allow(dead_code)] pub fn get_pcr_policy_digest( context: &mut Context, mangle: bool, @@ -415,7 +405,6 @@ pub fn get_pcr_policy_digest( } } -#[allow(dead_code)] pub fn create_public_sealed_object() -> Public { let object_attributes = ObjectAttributesBuilder::new() .with_fixed_tpm(true) diff --git a/tss-esapi/tests/integration_tests/tcti_ldr_tests/mod.rs b/tss-esapi/tests/integration_tests/tcti_ldr_tests/mod.rs index fdff9a09..bb1fadc8 100644 --- a/tss-esapi/tests/integration_tests/tcti_ldr_tests/mod.rs +++ b/tss-esapi/tests/integration_tests/tcti_ldr_tests/mod.rs @@ -5,7 +5,6 @@ use std::env; use std::str::FromStr; use tss_esapi::tcti_ldr::TctiNameConf; -#[allow(dead_code)] pub fn name_conf() -> TctiNameConf { match env::var("TEST_TCTI") { Err(_) => TctiNameConf::Mssim(Default::default()),