Moves the keypair generation to an extension trait

This technical change lets us avoid polluting the code with derives of Debug.
This commit is contained in:
François Garillot
2020-06-19 15:23:03 -04:00
parent f989330807
commit 7a2d309263
+8 -2
View File
@@ -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<u8>;
}
#[cfg(test)]
trait KeyPairExt: KeyPair + Debug {
/// Test-only strategy returning a proptest Strategy based on
/// generate_random
#[cfg(test)]
fn uniform_keypair_strategy() -> BoxedStrategy<Self> {
// 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<KP> 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