diff options
| author | Kevin King <[email protected]> | 2016-04-06 18:44:17 -0400 |
|---|---|---|
| committer | Kevin King <[email protected]> | 2016-04-06 19:39:50 -0400 |
| commit | 4016edd4de9f660a1a4c5fa67f2f04c6a828fab0 (patch) | |
| tree | f1dc0445cf8269cddbcf8a44be37b87d2d76fc81 /openssl/src/crypto | |
| parent | Merge pull request #372 from jwilm/safe-bio-method-wrapper (diff) | |
| download | rust-openssl-4016edd4de9f660a1a4c5fa67f2f04c6a828fab0.tar.xz rust-openssl-4016edd4de9f660a1a4c5fa67f2f04c6a828fab0.zip | |
add EVP_PKEY_copy_parameters to FFI
copy EVP_PKEY params in PKey::clone
test that PKey::clone creates a copy
Diffstat (limited to 'openssl/src/crypto')
| -rw-r--r-- | openssl/src/crypto/pkey.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs index cafd50ad..f945276d 100644 --- a/openssl/src/crypto/pkey.rs +++ b/openssl/src/crypto/pkey.rs @@ -53,10 +53,6 @@ fn openssl_hash_nid(hash: HashType) -> c_int { } } -extern "C" { - fn rust_EVP_PKEY_clone(pkey: *mut ffi::EVP_PKEY); -} - pub struct PKey { evp: *mut ffi::EVP_PKEY, parts: Parts, @@ -614,10 +610,10 @@ impl Drop for PKey { impl Clone for PKey { fn clone(&self) -> Self { unsafe { - rust_EVP_PKEY_clone(self.evp); + let new_evp = ffi::EVP_PKEY_new(); + assert!(ffi::EVP_PKEY_copy_parameters(new_evp, self.evp) == 0); + PKey::from_handle(new_evp, self.parts) } - - PKey::from_handle(self.evp, self.parts) } } @@ -866,4 +862,16 @@ mod tests { pkey.load_pub(&[]); pkey.verify(&[], &[]); } + + #[test] + fn test_pkey_clone_creates_copy() { + let mut pkey = super::PKey::new(); + pkey.gen(512); + let old_pkey_n = pkey.get_rsa().n().unwrap(); + + let mut pkey2 = pkey.clone(); + pkey2.gen(512); + + assert!(old_pkey_n == pkey.get_rsa().n().unwrap()); + } } |