Skip to content

Commit

Permalink
Fix Nightly warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Jun 19, 2024
1 parent b15cc6c commit 8ab868a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 46 deletions.
4 changes: 2 additions & 2 deletions blobby/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ fn encode_vlq(mut val: usize, buf: &mut [u8; 4]) -> &[u8] {
/// - (J << 1) & 0x01: indicates this blob is index entry J
/// - (L << 1) & 0x00: indicates an explicit blob of len L
/// - (in the latter case) explicit blob contents (L bytes)
pub fn encode_blobs<'a, I, T: 'a>(blobs: &'a I) -> (Vec<u8>, usize)
pub fn encode_blobs<'a, I, T>(blobs: &'a I) -> (Vec<u8>, usize)
where
&'a I: IntoIterator<Item = &'a T>,
T: AsRef<[u8]>,
T: AsRef<[u8]> + 'a,
{
let mut idx_map = BTreeMap::new();
blobs
Expand Down
18 changes: 9 additions & 9 deletions inout/src/inout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ impl<'inp, 'out, T> InOut<'inp, 'out, T> {
/// # Safety
/// Behavior is undefined if any of the following conditions are violated:
/// - `in_ptr` must point to a properly initialized value of type `T` and
/// must be valid for reads.
/// must be valid for reads.
/// - `out_ptr` must point to a properly initialized value of type `T` and
/// must be valid for both reads and writes.
/// must be valid for both reads and writes.
/// - `in_ptr` and `out_ptr` must be either equal or non-overlapping.
/// - If `in_ptr` and `out_ptr` are equal, then the memory referenced by
/// them must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden.
/// them must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden.
/// - If `in_ptr` and `out_ptr` are not equal, then the memory referenced by
/// `out_ptr` must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime `'a`. Both read and write
/// accesses are forbidden. The memory referenced by `in_ptr` must not be
/// mutated for the duration of lifetime `'a`, except inside an `UnsafeCell`.
/// `out_ptr` must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime `'a`. Both read and write
/// accesses are forbidden. The memory referenced by `in_ptr` must not be
/// mutated for the duration of lifetime `'a`, except inside an `UnsafeCell`.
#[inline(always)]
pub unsafe fn from_raw(in_ptr: *const T, out_ptr: *mut T) -> InOut<'inp, 'out, T> {
Self {
Expand Down
20 changes: 10 additions & 10 deletions inout/src/inout_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,20 @@ impl<'inp, 'out, T> InOutBuf<'inp, 'out, T> {
/// # Safety
/// Behavior is undefined if any of the following conditions are violated:
/// - `in_ptr` must point to a properly initialized value of type `T` and
/// must be valid for reads for `len * mem::size_of::<T>()` many bytes.
/// must be valid for reads for `len * mem::size_of::<T>()` many bytes.
/// - `out_ptr` must point to a properly initialized value of type `T` and
/// must be valid for both reads and writes for `len * mem::size_of::<T>()`
/// many bytes.
/// must be valid for both reads and writes for `len * mem::size_of::<T>()`
/// many bytes.
/// - `in_ptr` and `out_ptr` must be either equal or non-overlapping.
/// - If `in_ptr` and `out_ptr` are equal, then the memory referenced by
/// them must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden.
/// them must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden.
/// - If `in_ptr` and `out_ptr` are not equal, then the memory referenced by
/// `out_ptr` must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden. The memory referenced by `in_ptr` must not be
/// mutated for the duration of lifetime `'a`, except inside an `UnsafeCell`.
/// `out_ptr` must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden. The memory referenced by `in_ptr` must not be
/// mutated for the duration of lifetime `'a`, except inside an `UnsafeCell`.
/// - The total size `len * mem::size_of::<T>()` must be no larger than `isize::MAX`.
#[inline(always)]
pub unsafe fn from_raw(
Expand Down
22 changes: 11 additions & 11 deletions inout/src/reserved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ impl<'a, T> InOutBufReserved<'a, 'a, T> {
/// # Safety
/// Behavior is undefined if any of the following conditions are violated:
/// - `in_ptr` must point to a properly initialized value of type `T` and
/// must be valid for reads for `in_len * mem::size_of::<T>()` many bytes.
/// must be valid for reads for `in_len * mem::size_of::<T>()` many bytes.
/// - `out_ptr` must point to a properly initialized value of type `T` and
/// must be valid for both reads and writes for `out_len * mem::size_of::<T>()`
/// many bytes.
/// must be valid for both reads and writes for `out_len * mem::size_of::<T>()`
/// many bytes.
/// - `in_ptr` and `out_ptr` must be either equal or non-overlapping.
/// - If `in_ptr` and `out_ptr` are equal, then the memory referenced by
/// them must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden.
/// them must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden.
/// - If `in_ptr` and `out_ptr` are not equal, then the memory referenced by
/// `out_ptr` must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden. The memory referenced by `in_ptr` must not be
/// mutated for the duration of lifetime `'a`, except inside an `UnsafeCell`.
/// `out_ptr` must not be accessed through any other pointer (not derived from
/// the return value) for the duration of lifetime 'a. Both read and write
/// accesses are forbidden. The memory referenced by `in_ptr` must not be
/// mutated for the duration of lifetime `'a`, except inside an `UnsafeCell`.
/// - The total size `in_len * mem::size_of::<T>()` and
/// `out_len * mem::size_of::<T>()` must be no larger than `isize::MAX`.
/// `out_len * mem::size_of::<T>()` must be no larger than `isize::MAX`.
#[inline(always)]
pub unsafe fn from_raw(
in_ptr: *const T,
Expand Down
13 changes: 7 additions & 6 deletions wycheproof2blb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
)]
use std::io::Write;

mod aead;
// We use `pub mod` to silence "field is never read" warnings
pub mod aead;
mod aes_siv;
mod ecdsa;
mod ed25519;
mod hkdf;
mod mac;
pub mod mac;
mod wycheproof;

/// Test information
Expand All @@ -22,10 +23,10 @@ pub struct TestInfo {
}

/// Generator function which takes input parameters:
/// - contents of Wycheproof test data file
/// - algorithm name
/// - key size (in bits) to include
/// and returns the raw contents, together with a list of test identifiers (one per entry).
/// - contents of Wycheproof test data file
/// - algorithm name
/// - key size (in bits) to include
/// and returns the raw contents, together with a list of test identifiers (one per entry).
type BlbGenerator = fn(&[u8], &str, u32) -> Vec<TestInfo>;

struct Algorithm {
Expand Down
16 changes: 8 additions & 8 deletions zeroize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ mod x86;

use core::{
marker::{PhantomData, PhantomPinned},
mem::{self, MaybeUninit},
mem::{self, size_of, MaybeUninit},
num::{
self, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize,
NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
Expand Down Expand Up @@ -409,10 +409,10 @@ where
//
// Safety:
//
// The memory pointed to by `self` is valid for `mem::size_of::<Self>()` bytes.
// The memory pointed to by `self` is valid for `size_of::<Self>()` bytes.
// It is also properly aligned, because `u8` has an alignment of `1`.
unsafe {
volatile_set((self as *mut Self).cast::<u8>(), 0, mem::size_of::<Self>());
volatile_set((self as *mut Self).cast::<u8>(), 0, size_of::<Self>());
}

// Ensures self is overwritten with the `None` bit pattern. volatile_write can't be
Expand Down Expand Up @@ -457,7 +457,7 @@ impl<Z> Zeroize for MaybeUninit<Z> {
impl<Z> Zeroize for [MaybeUninit<Z>] {
fn zeroize(&mut self) {
let ptr = self.as_mut_ptr().cast::<MaybeUninit<u8>>();
let size = self.len().checked_mul(mem::size_of::<Z>()).unwrap();
let size = self.len().checked_mul(size_of::<Z>()).unwrap();
assert!(size <= isize::MAX as usize);

// Safety:
Expand Down Expand Up @@ -767,7 +767,7 @@ fn volatile_write<T: Copy + Sized>(dst: &mut T, src: T) {
/// The memory pointed to by `dst` must be a single allocated object that is valid for `count`
/// contiguous elements of `T`.
/// `count` must not be larger than an `isize`.
/// `dst` being offset by `mem::size_of::<T> * count` bytes must not wrap around the address space.
/// `dst` being offset by `size_of::<T> * count` bytes must not wrap around the address space.
/// Also `dst` must be properly aligned.
#[inline(always)]
unsafe fn volatile_set<T: Copy + Sized>(dst: *mut T, src: T, count: usize) {
Expand All @@ -783,7 +783,7 @@ unsafe fn volatile_set<T: Copy + Sized>(dst: *mut T, src: T, count: usize) {
// Safety:
//
// This is safe, because the pointer is valid and because `dst` is well aligned for `T` and
// `ptr` is an offset of `dst` by a multiple of `mem::size_of::<T>()` bytes.
// `ptr` is an offset of `dst` by a multiple of `size_of::<T>()` bytes.
ptr::write_volatile(ptr, src);
}
}
Expand Down Expand Up @@ -837,10 +837,10 @@ unsafe fn volatile_set<T: Copy + Sized>(dst: *mut T, src: T, count: usize) {
/// ```
#[inline(always)]
pub unsafe fn zeroize_flat_type<F: Sized>(data: *mut F) {
let size = mem::size_of::<F>();
let size = size_of::<F>();
// Safety:
//
// This is safe because `mem::size_of<T>()` returns the exact size of the object in memory, and
// This is safe because `size_of<T>()` returns the exact size of the object in memory, and
// `data_ptr` points directly to the first byte of the data.
volatile_set(data as *mut u8, 0, size);
atomic_fence()
Expand Down

0 comments on commit 8ab868a

Please sign in to comment.