NFC: Use pointer::cast
instead of as
for pointer casts.
Enforce this pattern with Clippy.
This commit is contained in:
parent
1fa6d09eef
commit
2b1194c845
@ -114,8 +114,8 @@ fn ctr32_encrypt_blocks_(
|
||||
let blocks_u32 = blocks as u32;
|
||||
assert_eq!(blocks, polyfill::usize_from_u32(blocks_u32));
|
||||
|
||||
let input = in_out[src].as_ptr() as *const [u8; BLOCK_LEN];
|
||||
let output = in_out.as_mut_ptr() as *mut [u8; BLOCK_LEN];
|
||||
let input = in_out[src].as_ptr().cast::<[u8; BLOCK_LEN]>();
|
||||
let output = in_out.as_mut_ptr().cast::<[u8; BLOCK_LEN]>();
|
||||
|
||||
unsafe {
|
||||
f(input, output, blocks, key, ctr);
|
||||
|
@ -124,7 +124,7 @@ impl Context {
|
||||
debug_assert_eq!(input_bytes % BLOCK_LEN, 0);
|
||||
debug_assert!(input_bytes > 0);
|
||||
|
||||
let input = input.as_ptr() as *const [u8; BLOCK_LEN];
|
||||
let input = input.as_ptr().cast::<[u8; BLOCK_LEN]>();
|
||||
// SAFETY:
|
||||
// - `[[u8; BLOCK_LEN]]` has the same bit validity as `[u8]`.
|
||||
// - `[[u8; BLOCK_LEN]]` has the same alignment requirement as `[u8]`.
|
||||
|
@ -40,7 +40,7 @@ pub(super) extern "C" fn block_data_order(
|
||||
) {
|
||||
let state = unsafe { &mut state.as32 };
|
||||
let state: &mut State = (&mut state[..CHAINING_WORDS]).try_into().unwrap();
|
||||
let data = data as *const [<W32 as Word>::InputBytes; 16];
|
||||
let data = data.cast::<[<W32 as Word>::InputBytes; 16]>();
|
||||
let blocks = unsafe { core::slice::from_raw_parts(data, num) };
|
||||
*state = block_data_order_(*state, blocks)
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ fn block_data_order<S: Sha2>(
|
||||
M: *const u8,
|
||||
num: c::size_t,
|
||||
) -> [S; CHAINING_WORDS] {
|
||||
let M = M as *const [S::InputBytes; 16];
|
||||
let M = M.cast::<[S::InputBytes; 16]>();
|
||||
let M: &[[S::InputBytes; 16]] = unsafe { core::slice::from_raw_parts(M, num) };
|
||||
|
||||
for M in M {
|
||||
|
@ -32,8 +32,9 @@ macro_rules! impl_array_encoding {
|
||||
{
|
||||
#[inline]
|
||||
fn as_byte_array(&self) -> &[u8; $elems * core::mem::size_of::<$base>()] {
|
||||
let as_bytes_ptr =
|
||||
self.as_ptr() as *const [u8; $elems * core::mem::size_of::<$base>()];
|
||||
let as_bytes_ptr = self
|
||||
.as_ptr()
|
||||
.cast::<[u8; $elems * core::mem::size_of::<$base>()]>();
|
||||
unsafe { &*as_bytes_ptr }
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,8 @@
|
||||
invalid_reference_casting,
|
||||
clippy::char_lit_as_u8,
|
||||
clippy::fn_to_numeric_cast,
|
||||
clippy::fn_to_numeric_cast_with_truncation
|
||||
clippy::fn_to_numeric_cast_with_truncation,
|
||||
clippy::ptr_as_ptr
|
||||
)]
|
||||
#![warn(
|
||||
clippy::unnecessary_cast,
|
||||
|
@ -18,8 +18,8 @@ macro_rules! define_chunks_fixed {
|
||||
{
|
||||
#[inline(always)]
|
||||
fn chunks_fixed(self) -> &'a [[T; $chunk_len]; $chunked_len] {
|
||||
let as_ptr: *const [T; $chunk_len] = self.as_ptr() as *const [T; $chunk_len];
|
||||
let as_ptr = as_ptr as *const [[T; $chunk_len]; $chunked_len];
|
||||
let as_ptr = self.as_ptr().cast::<[T; $chunk_len]>();
|
||||
let as_ptr = as_ptr.cast::<[[T; $chunk_len]; $chunked_len]>();
|
||||
unsafe { &*as_ptr }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user