Skip to content

Commit

Permalink
impl Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Oct 24, 2024
1 parent 2bafea1 commit 29934b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions crates/xdid-method-key/src/keys/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ring::{

use super::{DidKeyPair, KeyParser, Multicodec, PublicKey, SignError, Signer, WithMulticodec};

#[derive(Clone, PartialEq, Eq)]
pub struct P256KeyPair(SecretKey);

impl DidKeyPair for P256KeyPair {
Expand Down Expand Up @@ -50,6 +51,7 @@ impl Signer for P256KeyPair {
}
}

#[derive(Clone, PartialEq, Eq)]
struct P256PublicKey(p256::PublicKey);

impl PublicKey for P256PublicKey {
Expand Down
14 changes: 7 additions & 7 deletions crates/xdid-method-key/src/keys/p384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ use ring::{

use super::{DidKeyPair, KeyParser, Multicodec, PublicKey, SignError, Signer, WithMulticodec};

pub struct P384KeyPair {
secret: SecretKey,
}
#[derive(Clone, PartialEq, Eq)]
pub struct P384KeyPair(SecretKey);

impl DidKeyPair for P384KeyPair {
fn generate() -> Self {
let mut rng = OsRng;
let secret = SecretKey::random(&mut rng);
Self { secret }
Self(secret)
}

fn public(&self) -> impl PublicKey {
P384PublicKey(self.secret.public_key())
P384PublicKey(self.0.public_key())
}
fn public_bytes(&self) -> Box<[u8]> {
self.secret.public_key().to_sec1_bytes()
self.0.public_key().to_sec1_bytes()
}
fn secret_bytes(&self) -> Box<[u8]> {
self.secret.to_bytes().to_vec().into()
self.0.to_bytes().to_vec().into()
}
}

Expand All @@ -52,6 +51,7 @@ impl Signer for P384KeyPair {
}
}

#[derive(Clone, PartialEq, Eq)]
struct P384PublicKey(p384::PublicKey);

impl PublicKey for P384PublicKey {
Expand Down

0 comments on commit 29934b3

Please sign in to comment.