Skip to content

Commit 2cb687f

Browse files
committed
Use to_le_bytes instead of mem::transmute
Since we bumped the MSRV we have `to_le_bytes` available now, use it instead of `mem::transmute`. Remove code comment suggesting to do exactly this and clear clippy warning. While we are at it, use `cast` instead of `as`.
1 parent c15b9d2 commit 2cb687f

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/ecdsa/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Structs and functionality related to the ECDSA signature algorithm.
22
3-
use core::{fmt, str, ops, ptr, mem};
3+
use core::{fmt, str, ops, ptr};
44

55
use crate::{Signing, Verification, Message, PublicKey, Secp256k1, SecretKey, from_hex, Error, ffi};
66
use crate::ffi::CPtr;
@@ -398,14 +398,8 @@ impl<C: Signing> Secp256k1<C> {
398398
}
399399

400400
counter += 1;
401-
// From 1.32 can use `to_le_bytes` instead
402-
let le_counter = counter.to_le();
403-
let le_counter_bytes : [u8; 4] = mem::transmute(le_counter);
404-
for (i, b) in le_counter_bytes.iter().enumerate() {
405-
extra_entropy[i] = *b;
406-
}
407-
408-
entropy_p = extra_entropy.as_ptr() as *const ffi::types::c_void;
401+
extra_entropy[..4].copy_from_slice(&counter.to_le_bytes());
402+
entropy_p = extra_entropy.as_ptr().cast::<ffi::types::c_void>();
409403

410404
// When fuzzing, these checks will usually spinloop forever, so just short-circuit them.
411405
#[cfg(fuzzing)]

0 commit comments

Comments
 (0)