summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-10-09 12:52:24 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-10-13 12:08:11 +0200
commit2e167267ce81fc7293110db992443363de576cf6 (patch)
treeb2bc1935cee89a68bf9ae2da6edc678582927774
parent81573890225522e55f8b2983405723f0f16e7f28 (diff)
openpgp: Explicitly implement Clone for Protected.
-rw-r--r--openpgp/src/crypto/mem.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/openpgp/src/crypto/mem.rs b/openpgp/src/crypto/mem.rs
index 2c9f7fca..39e0ad9c 100644
--- a/openpgp/src/crypto/mem.rs
+++ b/openpgp/src/crypto/mem.rs
@@ -45,9 +45,18 @@ use memsec;
///
/// // p is cleared once it goes out of scope.
/// ```
-#[derive(Clone)]
pub struct Protected(Box<[u8]>);
+impl Clone for Protected {
+ fn clone(&self) -> Self {
+ // Make a vector with the correct size to avoid potential
+ // reallocations when turning it into a `Protected`.
+ let mut p = Vec::with_capacity(self.len());
+ p.extend_from_slice(&self);
+ p.into_boxed_slice().into()
+ }
+}
+
impl PartialEq for Protected {
fn eq(&self, other: &Self) -> bool {
secure_cmp(&self.0, &other.0) == Ordering::Equal