From 6b2c4d4efe6a30b0b017b59a0bea1f8c1c0af69f Mon Sep 17 00:00:00 2001 From: Dominik Spicher Date: Thu, 10 Mar 2022 15:57:29 +0100 Subject: [PATCH] Allow SharedSecret to be created from byte array This was accidentally removed in 8b2edad. See also the discussion on https://github.com/rust-bitcoin/rust-secp256k1/pull/402 --- src/ecdh.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ecdh.rs b/src/ecdh.rs index e36553e5a..786912d86 100644 --- a/src/ecdh.rs +++ b/src/ecdh.rs @@ -47,6 +47,14 @@ const SHARED_SECRET_SIZE: usize = constants::SECRET_KEY_SIZE; pub struct SharedSecret([u8; SHARED_SECRET_SIZE]); impl_display_secret!(SharedSecret); +impl From<[u8; SHARED_SECRET_SIZE]> for SharedSecret { + fn from(arr: [u8; SHARED_SECRET_SIZE]) -> Self { + let mut data = [0u8; SHARED_SECRET_SIZE]; + data[..SHARED_SECRET_SIZE].copy_from_slice(&arr); + Self(data) + } +} + impl SharedSecret { /// Creates a new shared secret from a pubkey and secret key. #[inline]