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:
+8
-2
@@ -39,7 +39,7 @@ pub trait SizedBytes: Sized + PartialEq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A Keypair trait with public-private verification
|
/// 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
|
/// The single key representation must have a specific byte size itself
|
||||||
type Repr: SizedBytes + Clone;
|
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
|
/// Computes the diffie hellman function on a public key and private key
|
||||||
fn diffie_hellman(pk: Self::Repr, sk: Self::Repr) -> Vec<u8>;
|
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
|
/// Test-only strategy returning a proptest Strategy based on
|
||||||
/// generate_random
|
/// generate_random
|
||||||
#[cfg(test)]
|
|
||||||
fn uniform_keypair_strategy() -> BoxedStrategy<Self> {
|
fn uniform_keypair_strategy() -> BoxedStrategy<Self> {
|
||||||
// The no_shrink is because keypairs should be fixed -- shrinking would cause a different
|
// 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.
|
// 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
|
/// 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
|
/// 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
|
/// first, followed by the private key in binary formats (and expect it in this
|
||||||
|
|||||||
Reference in New Issue
Block a user