We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 08c330f commit 7bd28e1Copy full SHA for 7bd28e1
src/ecdh.rs
@@ -4,6 +4,7 @@
4
//!
5
6
use core::borrow::Borrow;
7
+use core::convert::TryFrom;
8
use core::{ptr, str};
9
10
use secp256k1_sys::types::{c_int, c_uchar, c_void};
@@ -66,13 +67,9 @@ impl SharedSecret {
66
67
/// Creates a shared secret from `bytes` slice.
68
#[inline]
69
pub fn from_slice(bytes: &[u8]) -> Result<SharedSecret, Error> {
- match bytes.len() {
70
- SHARED_SECRET_SIZE => {
71
- let mut ret = [0u8; SHARED_SECRET_SIZE];
72
- ret[..].copy_from_slice(bytes);
73
- Ok(SharedSecret(ret))
74
- }
75
- _ => Err(Error::InvalidSharedSecret),
+ match <[u8; SHARED_SECRET_SIZE]>::try_from(bytes) {
+ Ok(bytes) => Ok(SharedSecret(bytes)),
+ Err(_) => Err(Error::InvalidSharedSecret),
76
}
77
78
0 commit comments