Repository: dalek-cryptography/ed25519-dalek (language: rust)

Issue:
Derive Clone for Keypair?
Is there any particular reason that the Keypair struct doesn't derive Clone? I have a spot where I need to clone one, and I've resorted to doing `to_bytes`->`from_bytes` which feels less than great.

If there's not a particular reason, I'd be happy to make a PR. Thanks!


Discussion / hints:
It's my understanding (please correct me if wrong!) that if we implement `Clone` then the `Drop` methods will still be recursively called. If so, it should be safe to implement `Clone` for `Keypair` (with the caveat that programmers who explicitly do this will temporarily have more copies of the `SecretKey` sitting around in memory.. which.. isn't the best). I'd like to ensure in some sense that programmers are disinclined to do this somehow, but I'm not sure how best to, which is why I've not a `#[derive(Clone)]` for `SecretKey` thus far.
@isislovecruft I figured that wanting to avoid extra copies in memory was probably the reason.

I can't think of any really great mechanism for that, besides maybe not actually implementing the `Clone` trait, and just having a special function for it, but that has a variety of associated issues.

:man_shrugging: The other way to look at it is people who want to clone one are gonna do it anyway (like I did), so just make things clear in the docs and leave it at that?
>I'd like to ensure in some sense that programmers are disinclined to do this somehow, but I'm not sure how best to, which is why I've not a `#[derive(Clone)]` for `SecretKey` thus far.

I think you could put this behind an opt-in crate-level feature (say, `cloneable_secret_key`) that would make programmers think twice about enabling it. If this sounds reasonable, I could verify that the approach works and make a PR.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 05efbbd..efae846 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,3 +9,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Changes
 * Bumped MSRV from 1.41 to 1.60.0
 * Removed `ExpandedSecretKey` API ((#205)[https://github.com/dalek-cryptography/ed25519-dalek/pull/205])
+* Implemented `Clone` for `SigningKey`
diff --git a/src/signing.rs b/src/signing.rs
index 1f6a4eb..c6b32f3 100644
--- a/src/signing.rs
+++ b/src/signing.rs
@@ -50,7 +50,7 @@ pub type SecretKey = [u8; SECRET_KEY_LENGTH];
 /// ed25519 signing key which can be used to produce signatures.
 // Invariant: `public` is always the public key of `secret`. This prevents the signing function
 // oracle attack described in https://github.com/MystenLabs/ed25519-unsafe-libs
-#[derive(Debug)]
+#[derive(Clone, Debug)]
 pub struct SigningKey {
     /// The secret half of this signing key.
     pub(crate) secret_key: SecretKey,


Test patch: