Skip to content

Commit 7fe89c4

Browse files
committed
Add byte accessors to ElligatorSwiftSharedSecret
The inner bytes of `ElligatorSwiftSharedSecret` were almost inaccessible making the type almost useless, so this commit adds methods to access inner bytes. Closes #675
1 parent 4dede13 commit 7fe89c4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/ellswift.rs

Lines changed: 14 additions & 0 deletions
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)