Skip to content

Commit

Permalink
Merge pull request #43 from peat/master
Browse files Browse the repository at this point in the history
Add .to_bytes() to PublicKey, SharedSecret
  • Loading branch information
hdevalence committed Aug 18, 2020
2 parents 5115951 + 1d61e1b commit 5d245dc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/x25519.rs
Expand Up @@ -41,6 +41,12 @@ impl From<[u8; 32]> for PublicKey {
}

impl PublicKey {
/// Convert this public key to a byte array.
#[inline]
pub fn to_bytes(&self) -> [u8; 32] {
self.0.to_bytes()
}

/// View this public key as a byte array.
#[inline]
pub fn as_bytes(&self) -> &[u8; 32] {
Expand Down Expand Up @@ -143,6 +149,12 @@ impl<'a> From<&'a StaticSecret> for PublicKey {
pub struct SharedSecret(pub(crate) MontgomeryPoint);

impl SharedSecret {
/// Convert this shared secret to a byte array.
#[inline]
pub fn to_bytes(&self) -> [u8; 32] {
self.0.to_bytes()
}

/// View this shared secret key as a byte array.
#[inline]
pub fn as_bytes(&self) -> &[u8; 32] {
Expand Down

0 comments on commit 5d245dc

Please sign in to comment.