Skip to content

Commit

Permalink
Added conversion to wrapped types to ed/secp pk/sk/sig types
Browse files Browse the repository at this point in the history
  • Loading branch information
izolyomi committed Jul 5, 2021
1 parent c7bbb23 commit 5738d02
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
6 changes: 6 additions & 0 deletions keyvault/src/ed25519/pk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ impl From<ed::PublicKey> for EdPublicKey {
}
}

impl<'a> From<&'a EdPublicKey> for &'a ed::PublicKey {
fn from(pk: &'a EdPublicKey) -> &'a ed::PublicKey {
&pk.0
}
}

impl PublicKey<Ed25519> for EdPublicKey {
fn key_id(&self) -> EdKeyId {
EdKeyId::from(self)
Expand Down
10 changes: 8 additions & 2 deletions keyvault/src/ed25519/sk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ impl PrivateKey<Ed25519> for EdPrivateKey {
}

impl From<ed::Keypair> for EdPrivateKey {
fn from(kp: ed::Keypair) -> Self {
Self(kp)
fn from(sk: ed::Keypair) -> Self {
Self(sk)
}
}

impl From<EdPrivateKey> for ed::Keypair {
fn from(sk: EdPrivateKey) -> ed::Keypair {
sk.0
}
}
12 changes: 12 additions & 0 deletions keyvault/src/secp256k1/pk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ impl fmt::Debug for SecpPublicKey {
}
}

impl From<secp::PublicKey> for SecpPublicKey {
fn from(pk: secp::PublicKey) -> Self {
Self(pk)
}
}

impl From<SecpPublicKey> for secp::PublicKey {
fn from(pk: SecpPublicKey) -> secp::PublicKey {
pk.0
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
12 changes: 12 additions & 0 deletions keyvault/src/secp256k1/sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ impl fmt::Debug for SecpSignature {
}
}

impl From<secp::Signature> for SecpSignature {
fn from(sig: secp::Signature) -> Self {
Self(sig)
}
}

impl From<SecpSignature> for secp::Signature {
fn from(sig: SecpSignature) -> secp::Signature {
sig.0
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
12 changes: 12 additions & 0 deletions keyvault/src/secp256k1/sk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ impl PrivateKey<Secp256k1> for SecpPrivateKey {
SecpSignature(sig)
}
}

impl From<secp::SecretKey> for SecpPrivateKey {
fn from(sk: secp::SecretKey) -> Self {
Self(sk)
}
}

impl From<SecpPrivateKey> for secp::SecretKey {
fn from(sk: SecpPrivateKey) -> secp::SecretKey {
sk.0
}
}

0 comments on commit 5738d02

Please sign in to comment.