From b1e5c8b1ed69a16aca6d651cb7a68f4854897d2c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 12 May 2018 16:34:47 -0700 Subject: Implement Clone for Rsa Closes #917 --- openssl/src/rsa.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'openssl/src') diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index ec1de35f..0ad55b96 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -77,6 +77,23 @@ generic_foreign_type_and_impl_send_sync! { pub struct RsaRef; } +impl Clone for Rsa { + fn clone(&self) -> Rsa { + (**self).to_owned() + } +} + +impl ToOwned for RsaRef { + type Owned = Rsa; + + fn to_owned(&self) -> Rsa { + unsafe { + ffi::RSA_up_ref(self.as_ptr()); + Rsa::from_ptr(self.as_ptr()) + } + } +} + impl RsaRef where T: HasPrivate, @@ -845,7 +862,7 @@ mod test { #[test] fn test_pem_pkcs1_padding() { - let keypair = super::Rsa::generate(512).unwrap(); + let keypair = super::Rsa::generate(2048).unwrap(); let pubkey_pem = keypair.public_key_to_pem_pkcs1().unwrap(); let pubkey = super::Rsa::public_key_from_pem_pkcs1(&pubkey_pem).unwrap(); let msg = "foo".as_bytes(); @@ -862,4 +879,10 @@ mod test { assert_eq!(len1, len2); assert_ne!(encrypted1, encrypted2); } + + #[test] + fn clone() { + let key = Rsa::generate(2048).unwrap(); + key.clone(); + } } -- cgit v1.2.3