diff --git a/src/lib.rs b/src/lib.rs index d77e0fe..658b7c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -128,10 +128,16 @@ impl From for [u8; 32] { /// A Diffie-Hellman secret key used to derive a shared secret when /// 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))] pub struct StaticSecret(pub(crate) Scalar); +impl From for [u8; 32] { + fn from(static_secret: StaticSecret) -> [u8; 32] { + static_secret.0.to_bytes() + } +} + impl From<[u8; 32]> for StaticSecret { fn from(bytes: [u8; 32]) -> StaticSecret { match Scalar::from_canonical_bytes(bytes) { @@ -264,6 +270,15 @@ mod tests { ); } + #[test] + fn from_into_static_secret_bytes(static_secret in any::()) { + let bytes: [u8; 32] = static_secret.into(); + + prop_assert_eq!( + static_secret, StaticSecret::from(bytes) + ); + } + #[test] fn scalar_mul_different_paths( secret in any::(),