From 55fee497bb42522123587c61ce4b7443455c8e61 Mon Sep 17 00:00:00 2001 From: Edouard Oger Date: Thu, 28 Feb 2019 14:10:49 -0500 Subject: [PATCH] Implement Clone for Dsa --- openssl-sys/src/dsa.rs | 1 + openssl/src/dsa.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/openssl-sys/src/dsa.rs b/openssl-sys/src/dsa.rs index 2887b2dd..604c68f0 100644 --- a/openssl-sys/src/dsa.rs +++ b/openssl-sys/src/dsa.rs @@ -5,6 +5,7 @@ use *; extern "C" { pub fn DSA_new() -> *mut DSA; pub fn DSA_free(dsa: *mut DSA); + pub fn DSA_up_ref(dsa: *mut DSA) -> c_int; pub fn DSA_size(dsa: *const DSA) -> c_int; pub fn DSA_sign( dummy: c_int, diff --git a/openssl/src/dsa.rs b/openssl/src/dsa.rs index 8e154ee5..1b55d12e 100644 --- a/openssl/src/dsa.rs +++ b/openssl/src/dsa.rs @@ -59,6 +59,23 @@ generic_foreign_type_and_impl_send_sync! { pub struct DsaRef; } +impl Clone for Dsa { + fn clone(&self) -> Dsa { + (**self).to_owned() + } +} + +impl ToOwned for DsaRef { + type Owned = Dsa; + + fn to_owned(&self) -> Dsa { + unsafe { + ffi::DSA_up_ref(self.as_ptr()); + Dsa::from_ptr(self.as_ptr()) + } + } +} + impl DsaRef where T: HasPublic, @@ -412,4 +429,10 @@ mod test { verifier.update(TEST_DATA).unwrap(); assert!(verifier.verify(&signature[..]).unwrap()); } + + #[test] + fn clone() { + let key = Dsa::generate(2048).unwrap(); + drop(key.clone()); + } }