Defined 'PemStorableKeypair' trait and implemented it on existing keypairs

This commit is contained in:
Jedrzej Stuczynski
2020-02-04 11:28:49 +00:00
parent 495b0c7ed9
commit 165d022015
3 changed files with 36 additions and 2 deletions
+14 -1
View File
@@ -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);
+14 -1
View File
@@ -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);
+8
View File
@@ -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;
}