diff --git a/common/crypto/src/encryption/mod.rs b/common/crypto/src/encryption/mod.rs index 1ab614e8d4..4d94f06f4b 100644 --- a/common/crypto/src/encryption/mod.rs +++ b/common/crypto/src/encryption/mod.rs @@ -1,4 +1,4 @@ -use crate::PemStorableKey; +use crate::{PemStorableKey, PemStorableKeyPair}; use curve25519_dalek::montgomery::MontgomeryPoint; use curve25519_dalek::scalar::Scalar; @@ -39,6 +39,19 @@ impl KeyPair { } } +impl PemStorableKeyPair for KeyPair { + type PrivatePemKey = PrivateKey; + type PublicPemKey = PublicKey; + + fn private_pem_key(&self) -> &Self::PrivatePemKey { + self.private_key() + } + + fn public_pem_key(&self) -> &Self::PublicPemKey { + self.public_key() + } +} + // COPY IS DERIVED ONLY TEMPORARILY UNTIL https://github.com/nymtech/nym/issues/47 is fixed #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub struct PrivateKey(pub Scalar); diff --git a/common/crypto/src/identity/mod.rs b/common/crypto/src/identity/mod.rs index 39c03e8469..b7fe294c78 100644 --- a/common/crypto/src/identity/mod.rs +++ b/common/crypto/src/identity/mod.rs @@ -1,4 +1,4 @@ -use crate::{encryption, PemStorableKey}; +use crate::{encryption, PemStorableKey, PemStorableKeyPair}; use bs58; use curve25519_dalek::scalar::Scalar; use sphinx::route::DestinationAddressBytes; @@ -36,6 +36,19 @@ impl MixIdentityKeyPair { } } +impl PemStorableKeyPair for MixIdentityKeyPair { + type PrivatePemKey = MixIdentityPrivateKey; + type PublicPemKey = MixIdentityPublicKey; + + fn private_pem_key(&self) -> &Self::PrivatePemKey { + self.private_key() + } + + fn public_pem_key(&self) -> &Self::PublicPemKey { + self.public_key() + } +} + #[derive(Debug, Clone, Eq, PartialEq)] pub struct MixIdentityPublicKey(encryption::PublicKey); diff --git a/common/crypto/src/lib.rs b/common/crypto/src/lib.rs index c5c3334e47..f5401aead5 100644 --- a/common/crypto/src/lib.rs +++ b/common/crypto/src/lib.rs @@ -7,3 +7,11 @@ pub mod identity; pub trait PemStorableKey { fn pem_type(&self) -> String; } + +pub trait PemStorableKeyPair { + type PrivatePemKey: PemStorableKey; + type PublicPemKey: PemStorableKey; + + fn private_pem_key(&self) -> &Self::PrivatePemKey; + fn public_pem_key(&self) -> &Self::PublicPemKey; +}