Impl From<StaticSecret> for [u8; 32]
Plus derive(Copy), proptest bytes roundtrip
This commit is contained in:
parent
06fddf3fb1
commit
18e12e7406
17
src/lib.rs
17
src/lib.rs
|
@ -128,10 +128,16 @@ impl From<SharedSecret> for [u8; 32] {
|
||||||
|
|
||||||
/// A Diffie-Hellman secret key used to derive a shared secret when
|
/// A Diffie-Hellman secret key used to derive a shared secret when
|
||||||
/// combined with a public key, that can be stored and loaded.
|
/// combined with a public key, that can be stored and loaded.
|
||||||
#[derive(Clone, Eq, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
#[cfg_attr(test, derive(Debug))]
|
#[cfg_attr(test, derive(Debug))]
|
||||||
pub struct StaticSecret(pub(crate) Scalar);
|
pub struct StaticSecret(pub(crate) Scalar);
|
||||||
|
|
||||||
|
impl From<StaticSecret> for [u8; 32] {
|
||||||
|
fn from(static_secret: StaticSecret) -> [u8; 32] {
|
||||||
|
static_secret.0.to_bytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<[u8; 32]> for StaticSecret {
|
impl From<[u8; 32]> for StaticSecret {
|
||||||
fn from(bytes: [u8; 32]) -> StaticSecret {
|
fn from(bytes: [u8; 32]) -> StaticSecret {
|
||||||
match Scalar::from_canonical_bytes(bytes) {
|
match Scalar::from_canonical_bytes(bytes) {
|
||||||
|
@ -264,6 +270,15 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_into_static_secret_bytes(static_secret in any::<StaticSecret>()) {
|
||||||
|
let bytes: [u8; 32] = static_secret.into();
|
||||||
|
|
||||||
|
prop_assert_eq!(
|
||||||
|
static_secret, StaticSecret::from(bytes)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn scalar_mul_different_paths(
|
fn scalar_mul_different_paths(
|
||||||
secret in any::<EphemeralSecret>(),
|
secret in any::<EphemeralSecret>(),
|
||||||
|
|
Loading…
Reference in New Issue