mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +00:00
impl AsRef for keys as well
This commit is contained in:
parent
7374fd3d2f
commit
d95e3bd536
1 changed files with 26 additions and 0 deletions
|
|
@ -60,6 +60,14 @@ impl PublicKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for PublicKey {
|
||||||
|
/// View this public key as a byte array.
|
||||||
|
#[inline]
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
self.as_bytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A short-lived Diffie-Hellman secret key that can only be used to compute a single
|
/// A short-lived Diffie-Hellman secret key that can only be used to compute a single
|
||||||
/// [`SharedSecret`].
|
/// [`SharedSecret`].
|
||||||
///
|
///
|
||||||
|
|
@ -187,11 +195,13 @@ impl StaticSecret {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract this key's bytes for serialization.
|
/// Extract this key's bytes for serialization.
|
||||||
|
#[inline]
|
||||||
pub fn to_bytes(&self) -> [u8; 32] {
|
pub fn to_bytes(&self) -> [u8; 32] {
|
||||||
self.0.to_bytes()
|
self.0.to_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// View this key as a byte array.
|
/// View this key as a byte array.
|
||||||
|
#[inline]
|
||||||
pub fn as_bytes(&self) -> &[u8; 32] {
|
pub fn as_bytes(&self) -> &[u8; 32] {
|
||||||
self.0.as_bytes()
|
self.0.as_bytes()
|
||||||
}
|
}
|
||||||
|
|
@ -211,6 +221,14 @@ impl<'a> From<&'a StaticSecret> for PublicKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for StaticSecret {
|
||||||
|
/// View this key as a byte array.
|
||||||
|
#[inline]
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
self.as_bytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The result of a Diffie-Hellman key exchange.
|
/// The result of a Diffie-Hellman key exchange.
|
||||||
///
|
///
|
||||||
/// Each party computes this using their [`EphemeralSecret`] or [`StaticSecret`] and their
|
/// Each party computes this using their [`EphemeralSecret`] or [`StaticSecret`] and their
|
||||||
|
|
@ -271,6 +289,14 @@ impl SharedSecret {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for SharedSecret {
|
||||||
|
/// View this shared secret key as a byte array.
|
||||||
|
#[inline]
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
self.as_bytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// "Decode" a scalar from a 32-byte array.
|
/// "Decode" a scalar from a 32-byte array.
|
||||||
///
|
///
|
||||||
/// By "decode" here, what is really meant is applying key clamping by twiddling
|
/// By "decode" here, what is really meant is applying key clamping by twiddling
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue