From 9df5ac169b114a6e7cb3a895cdd7753cf925800d Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Mon, 7 Aug 2023 17:17:21 +0300 Subject: [PATCH] Update Clippy and fix lints (#83) --- .github/workflows/workspace.yml | 2 +- concat-kdf/tests/tests.rs | 21 +++++++++++++++------ hkdf/tests/tests.rs | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index 02a2884..2ac675c 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -17,7 +17,7 @@ jobs: - uses: RustCrypto/actions/cargo-cache@master - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.56.0 # MSRV + toolchain: 1.71.0 components: clippy - run: cargo clippy --all -- -D warnings diff --git a/concat-kdf/tests/tests.rs b/concat-kdf/tests/tests.rs index 0b54e70..c813252 100644 --- a/concat-kdf/tests/tests.rs +++ b/concat-kdf/tests/tests.rs @@ -191,10 +191,19 @@ fn test_errors() { ); // key has a length that causes counter overflow. - assert_eq!( - concat_kdf::derive_key_into::(&[0u8; 42], &[], unsafe { - std::slice::from_raw_parts_mut(0 as *mut u8, Sha224::output_size() * u32::MAX as usize) - }), - Err(concat_kdf::Error::CounterOverflow) - ); + #[cfg(target_pointer_width = "64")] + { + let size = Sha224::output_size() * u32::MAX as usize; + let layout = std::alloc::Layout::from_size_align(size, 1).unwrap(); + unsafe { + // We assume that OS will not allocate physicall memory for this buffer + let p = std::alloc::alloc_zeroed(layout); + let buf = std::slice::from_raw_parts_mut(p, size); + assert_eq!( + concat_kdf::derive_key_into::(&[0u8; 42], &[], buf), + Err(concat_kdf::Error::CounterOverflow) + ); + std::alloc::dealloc(p, layout) + }; + } } diff --git a/hkdf/tests/tests.rs b/hkdf/tests/tests.rs index 6893889..15a45c4 100644 --- a/hkdf/tests/tests.rs +++ b/hkdf/tests/tests.rs @@ -209,8 +209,8 @@ fn test_lengths() { // Runtime is O(length), so exhaustively testing all legal lengths // would take too long (at least without --release). Only test a // subset: the first 500, the last 10, and every 100th in between. - let lengths = (0..MAX_SHA256_LENGTH + 1) - .filter(|&len| len < 500 || len > MAX_SHA256_LENGTH - 10 || len % 100 == 0); + let range = 500..MAX_SHA256_LENGTH - 10; + let lengths = (0..MAX_SHA256_LENGTH + 1).filter(|len| !range.contains(len) || *len % 100 == 0); for length in lengths { let mut okm = vec![0u8; length];