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