From 7a2d3092630b6bf76dff0eda729590dcd1db1485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Fri, 19 Jun 2020 11:08:29 -0400 Subject: [PATCH] Moves the keypair generation to an extension trait This technical change lets us avoid polluting the code with derives of Debug. --- src/keypair.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/keypair.rs b/src/keypair.rs index b660ee1..03611f6 100644 --- a/src/keypair.rs +++ b/src/keypair.rs @@ -39,7 +39,7 @@ pub trait SizedBytes: Sized + PartialEq { } /// A Keypair trait with public-private verification -pub trait KeyPair: Sized + Debug { +pub trait KeyPair: Sized { /// The single key representation must have a specific byte size itself type Repr: SizedBytes + Clone; @@ -68,10 +68,12 @@ pub trait KeyPair: Sized + Debug { /// Computes the diffie hellman function on a public key and private key fn diffie_hellman(pk: Self::Repr, sk: Self::Repr) -> Vec; +} +#[cfg(test)] +trait KeyPairExt: KeyPair + Debug { /// Test-only strategy returning a proptest Strategy based on /// generate_random - #[cfg(test)] fn uniform_keypair_strategy() -> BoxedStrategy { // The no_shrink is because keypairs should be fixed -- shrinking would cause a different // keypair to be generated, which appears to not be very useful. @@ -85,6 +87,10 @@ pub trait KeyPair: Sized + Debug { } } +// blanket implementation +#[cfg(test)] +impl KeyPairExt for KP where KP: KeyPair + Debug {} + /// This is a blanket implementation of SizedBytes for any instance of KeyPair /// with any length of keys. This encodes that we serialize the public key /// first, followed by the private key in binary formats (and expect it in this