From db92f898d30e0337814acaf906a0ea1541eb81c1 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 10 Jan 2020 11:50:30 +0000 Subject: [PATCH] MixnetIdentity Key traits --- common/crypto/src/identity/mod.rs | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 common/crypto/src/identity/mod.rs diff --git a/common/crypto/src/identity/mod.rs b/common/crypto/src/identity/mod.rs new file mode 100644 index 0000000000..175806394e --- /dev/null +++ b/common/crypto/src/identity/mod.rs @@ -0,0 +1,38 @@ + +pub trait MixnetIdentityKeyPair +where + Priv: MixnetIdentityPrivateKey, + Pub: MixnetIdentityPublicKey, +{ + fn new() -> Self; + fn private_key(&self) -> &Priv; + fn public_key(&self) -> &Pub; + + // TODO: signing related methods +} + +pub trait MixnetIdentityPublicKey: + Sized + for<'a> From<&'a ::PrivateKeyMaterial> +{ + // we need to couple public and private keys together + type PrivateKeyMaterial: MixnetIdentityPrivateKey; + + fn to_bytes(&self) -> Vec; + fn from_bytes(b: &[u8]) -> Self; +} + +pub trait MixnetIdentityPrivateKey: Sized { + // we need to couple public and private keys together + type PublicKeyMaterial: MixnetIdentityPublicKey; + + /// Returns the associated public key + fn public_key(&self) -> Self::PublicKeyMaterial { + self.into() + } + + fn to_bytes(&self) -> Vec; + fn from_bytes(b: &[u8]) -> Self; +} + +// same for validator +