From c747c625c8e91ddd8abbb272991e4731d843fb80 Mon Sep 17 00:00:00 2001 From: Dan Norris Date: Thu, 19 Sep 2024 17:05:08 -0400 Subject: [PATCH] feat: derive Clone for KeyPair and XKey (#50) Allow KeyPair and XKey structs to be cloned. We have no technical reason not to do this, since it is trivial to copy out a private key from either key type and the underlying members of the struct are all already Clone. Signed-off-by: Dan Norris --- src/lib.rs | 3 ++- src/xkeys.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 02b80c5..334a23c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,7 +87,8 @@ const PUBLIC_KEY_PREFIXES: [u8; 8] = [ type Result = std::result::Result; /// The main interface used for reading and writing _nkey-encoded_ key pairs, including -/// seeds and public keys. Instances of this type cannot be cloned. +/// seeds and public keys. +#[derive(Clone)] pub struct KeyPair { kp_type: KeyPairType, sk: Option, //rawkey_kind: RawKeyKind, diff --git a/src/xkeys.rs b/src/xkeys.rs index 8c9b370..d6dd6eb 100644 --- a/src/xkeys.rs +++ b/src/xkeys.rs @@ -17,7 +17,8 @@ use crypto_box::{PublicKey, SecretKey}; use rand::{CryptoRng, Rng, RngCore}; /// The main interface used for reading and writing _nkey-encoded_ curve key -/// pairs. Instances of this type cannot be cloned. +/// pairs. +#[derive(Clone)] pub struct XKey { public: PublicKey, secret: Option,