Skip to content

Commit 225884b

Browse files
committed
Use pointer casting instead of fallible conversion
1 parent 6cda165 commit 225884b

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

elliptic-curve/src/point/non_identity.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Non-identity point type.
22
33
use core::ops::{Deref, Mul};
4-
use core::slice;
54

65
use group::{Curve, Group, GroupEncoding, prime::PrimeCurveAffine};
76
use rand_core::CryptoRng;
@@ -122,8 +121,7 @@ where
122121

123122
#[allow(unsafe_code)]
124123
// SAFETY: `NonIdentity` is `repr(transparent)`.
125-
let points: &[P] = unsafe { slice::from_raw_parts(points.as_ptr().cast(), N) };
126-
let points = points.try_into().expect("slice should be size `N`");
124+
let points: &[P; N] = unsafe { &*(points as *const [Self; N]).cast() };
127125
let affine_points = <P as BatchNormalize<_>>::batch_normalize(points);
128126

129127
// Ensure `array::map()` can be optimized to a `memcpy`.
@@ -155,7 +153,7 @@ where
155153

156154
#[allow(unsafe_code)]
157155
// SAFETY: `NonIdentity` is `repr(transparent)`.
158-
let points: &[P] = unsafe { slice::from_raw_parts(points.as_ptr().cast(), points.len()) };
156+
let points: &[P] = unsafe { core::slice::from_raw_parts(points.as_ptr().cast(), points.len()) };
159157
let mut affine_points = <P as BatchNormalize<_>>::batch_normalize(points);
160158

161159
// Ensure casting is safe.

0 commit comments

Comments
 (0)