Merge rust-bitcoin/rust-secp256k1#676: Add byte accessors to `ElligatorSwiftSharedSecret`

7fe89c488b 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 7fe89c488b

Tree-SHA512: 5ec457401c83423b180f7a6f28048f93040c39129050707b981d1c113e3daa85a37b3f848e61cd3230cc26db4a783e561b77e09b766fd8193d8f7bf187214091
This commit is contained in:
Andrew Poelstra 2024-01-30 18:13:00 +00:00
commit 9bc110b7d2
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 14 additions and 0 deletions

View File

@ -266,6 +266,20 @@ impl ElligatorSwift {
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ElligatorSwiftSharedSecret([u8; 32]); pub struct ElligatorSwiftSharedSecret([u8; 32]);
impl ElligatorSwiftSharedSecret {
/// Creates shared secret from bytes.
///
/// This is generally not needed except for unusual cases like restoring the secret from a
/// database.
pub const fn from_secret_bytes(bytes: [u8; 32]) -> Self { Self(bytes) }
/// Returns the secret bytes as an array.
pub const fn to_secret_bytes(self) -> [u8; 32] { self.0 }
/// Returns the secret bytes as a reference to an array.
pub const fn as_secret_bytes(&self) -> &[u8; 32] { &self.0 }
}
/// Represents which party we are in the ECDH, A is the initiator, B is the responder. /// Represents which party we are in the ECDH, A is the initiator, B is the responder.
/// This is important because the hash of the shared secret is different depending on which party /// This is important because the hash of the shared secret is different depending on which party
/// we are. In this context, "we" means the party that is using this library, and possesses the /// we are. In this context, "we" means the party that is using this library, and possesses the