Skip to content

Commit 9bc110b

Browse files
committed
Merge #676: Add byte accessors to ElligatorSwiftSharedSecret
7fe89c4 Add byte accessors to `ElligatorSwiftSharedSecret` (Martin Habovstiak) Pull request description: The inner bytes of `ElligatorSwiftSharedSecret` were almost inaccessible making the type almost useless, so this commit adds methods to access inner bytes. Closes #675 ACKs for top commit: apoelstra: ACK 7fe89c4 Tree-SHA512: 5ec457401c83423b180f7a6f28048f93040c39129050707b981d1c113e3daa85a37b3f848e61cd3230cc26db4a783e561b77e09b766fd8193d8f7bf187214091
2 parents 4dede13 + 7fe89c4 commit 9bc110b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/ellswift.rs

+14
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ impl ElligatorSwift {
266266
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
267267
pub struct ElligatorSwiftSharedSecret([u8; 32]);
268268

269+
impl ElligatorSwiftSharedSecret {
270+
/// Creates shared secret from bytes.
271+
///
272+
/// This is generally not needed except for unusual cases like restoring the secret from a
273+
/// database.
274+
pub const fn from_secret_bytes(bytes: [u8; 32]) -> Self { Self(bytes) }
275+
276+
/// Returns the secret bytes as an array.
277+
pub const fn to_secret_bytes(self) -> [u8; 32] { self.0 }
278+
279+
/// Returns the secret bytes as a reference to an array.
280+
pub const fn as_secret_bytes(&self) -> &[u8; 32] { &self.0 }
281+
}
282+
269283
/// Represents which party we are in the ECDH, A is the initiator, B is the responder.
270284
/// This is important because the hash of the shared secret is different depending on which party
271285
/// we are. In this context, "we" means the party that is using this library, and possesses the

0 commit comments

Comments
 (0)