From 29934b368612b6d239cad07e49b085fb676f70e1 Mon Sep 17 00:00:00 2001 From: Kayh Date: Wed, 23 Oct 2024 21:52:13 -0400 Subject: [PATCH] impl Clone --- crates/xdid-method-key/src/keys/p256.rs | 2 ++ crates/xdid-method-key/src/keys/p384.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/xdid-method-key/src/keys/p256.rs b/crates/xdid-method-key/src/keys/p256.rs index cce6a9e..fb24274 100644 --- a/crates/xdid-method-key/src/keys/p256.rs +++ b/crates/xdid-method-key/src/keys/p256.rs @@ -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 { @@ -50,6 +51,7 @@ impl Signer for P256KeyPair { } } +#[derive(Clone, PartialEq, Eq)] struct P256PublicKey(p256::PublicKey); impl PublicKey for P256PublicKey { diff --git a/crates/xdid-method-key/src/keys/p384.rs b/crates/xdid-method-key/src/keys/p384.rs index a90cf4a..4fa7a52 100644 --- a/crates/xdid-method-key/src/keys/p384.rs +++ b/crates/xdid-method-key/src/keys/p384.rs @@ -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() } } @@ -52,6 +51,7 @@ impl Signer for P384KeyPair { } } +#[derive(Clone, PartialEq, Eq)] struct P384PublicKey(p384::PublicKey); impl PublicKey for P384PublicKey {