Extended pemstorable traits with methods required for more generic store
This commit is contained in:
@@ -43,13 +43,17 @@ impl PemStorableKeyPair for KeyPair {
|
||||
type PrivatePemKey = PrivateKey;
|
||||
type PublicPemKey = PublicKey;
|
||||
|
||||
fn private_pem_key(&self) -> &Self::PrivatePemKey {
|
||||
fn private_key(&self) -> &Self::PrivatePemKey {
|
||||
self.private_key()
|
||||
}
|
||||
|
||||
fn public_pem_key(&self) -> &Self::PublicPemKey {
|
||||
fn public_key(&self) -> &Self::PublicPemKey {
|
||||
self.public_key()
|
||||
}
|
||||
|
||||
fn from_bytes(priv_bytes: &[u8], pub_bytes: &[u8]) -> Self {
|
||||
Self::from_bytes(priv_bytes, pub_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
// COPY IS DERIVED ONLY TEMPORARILY UNTIL https://github.com/nymtech/nym/issues/47 is fixed
|
||||
@@ -74,6 +78,10 @@ impl PemStorableKey for PrivateKey {
|
||||
fn pem_type(&self) -> String {
|
||||
String::from("X25519 PRIVATE KEY")
|
||||
}
|
||||
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
self.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
@@ -102,4 +110,8 @@ impl PemStorableKey for PublicKey {
|
||||
fn pem_type(&self) -> String {
|
||||
String::from("X25519 PUBLIC KEY")
|
||||
}
|
||||
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
self.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,13 +40,17 @@ impl PemStorableKeyPair for MixIdentityKeyPair {
|
||||
type PrivatePemKey = MixIdentityPrivateKey;
|
||||
type PublicPemKey = MixIdentityPublicKey;
|
||||
|
||||
fn private_pem_key(&self) -> &Self::PrivatePemKey {
|
||||
fn private_key(&self) -> &Self::PrivatePemKey {
|
||||
self.private_key()
|
||||
}
|
||||
|
||||
fn public_pem_key(&self) -> &Self::PublicPemKey {
|
||||
fn public_key(&self) -> &Self::PublicPemKey {
|
||||
self.public_key()
|
||||
}
|
||||
|
||||
fn from_bytes(priv_bytes: &[u8], pub_bytes: &[u8]) -> Self {
|
||||
Self::from_bytes(priv_bytes, pub_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
@@ -82,6 +86,10 @@ impl PemStorableKey for MixIdentityPublicKey {
|
||||
fn pem_type(&self) -> String {
|
||||
format!("DUMMY KEY BASED ON {}", self.0.pem_type())
|
||||
}
|
||||
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
self.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
// COPY IS DERIVED ONLY TEMPORARILY UNTIL https://github.com/nymtech/nym/issues/47 is fixed
|
||||
@@ -118,4 +126,8 @@ impl PemStorableKey for MixIdentityPrivateKey {
|
||||
fn pem_type(&self) -> String {
|
||||
format!("DUMMY KEY BASED ON {}", self.0.pem_type())
|
||||
}
|
||||
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
self.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
pub mod encryption;
|
||||
pub mod identity;
|
||||
|
||||
// TODO: this trait will need to be moved elsewhere, probably to some 'persistence' crate
|
||||
// but since it will need to be used by all identities, it's not really appropriate if it lived in nym-client
|
||||
// TODO: ideally those trait should be moved to 'pemstore' crate, however, that would cause
|
||||
// circular dependency. The best solution would be to remove dependency on 'crypto' from
|
||||
// pemstore by using either dynamic dispatch or generics - perhaps this should be done
|
||||
// at some point during one of refactors.
|
||||
|
||||
pub trait PemStorableKey {
|
||||
fn pem_type(&self) -> String;
|
||||
fn to_bytes(&self) -> Vec<u8>;
|
||||
}
|
||||
|
||||
pub trait PemStorableKeyPair {
|
||||
type PrivatePemKey: PemStorableKey;
|
||||
type PublicPemKey: PemStorableKey;
|
||||
|
||||
fn private_pem_key(&self) -> &Self::PrivatePemKey;
|
||||
fn public_pem_key(&self) -> &Self::PublicPemKey;
|
||||
fn private_key(&self) -> &Self::PrivatePemKey;
|
||||
fn public_key(&self) -> &Self::PublicPemKey;
|
||||
|
||||
fn from_bytes(priv_bytes: &[u8], pub_bytes: &[u8]) -> Self;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user