aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin King <[email protected]>2016-04-06 18:44:17 -0400
committerKevin King <[email protected]>2016-04-06 19:39:50 -0400
commit4016edd4de9f660a1a4c5fa67f2f04c6a828fab0 (patch)
treef1dc0445cf8269cddbcf8a44be37b87d2d76fc81
parentMerge pull request #372 from jwilm/safe-bio-method-wrapper (diff)
downloadrust-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
-rw-r--r--openssl-sys/src/lib.rs1
-rw-r--r--openssl/src/c_helpers.c4
-rw-r--r--openssl/src/crypto/pkey.rs22
3 files changed, 16 insertions, 11 deletions
diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs
index 6d6d6103..77f846ab 100644
--- a/openssl-sys/src/lib.rs
+++ b/openssl-sys/src/lib.rs
@@ -548,6 +548,7 @@ extern "C" {
pub fn EVP_PKEY_new() -> *mut EVP_PKEY;
pub fn EVP_PKEY_free(k: *mut EVP_PKEY);
pub fn EVP_PKEY_assign(pkey: *mut EVP_PKEY, typ: c_int, key: *const c_void) -> c_int;
+ pub fn EVP_PKEY_copy_parameters(to: *mut EVP_PKEY, from: *const EVP_PKEY) -> c_int;
pub fn EVP_PKEY_get1_RSA(k: *mut EVP_PKEY) -> *mut RSA;
pub fn EVP_PKEY_set1_RSA(k: *mut EVP_PKEY, r: *mut RSA) -> c_int;
pub fn EVP_PKEY_cmp(a: *const EVP_PKEY, b: *const EVP_PKEY) -> c_int;
diff --git a/openssl/src/c_helpers.c b/openssl/src/c_helpers.c
index 1b48565e..e884bebd 100644
--- a/openssl/src/c_helpers.c
+++ b/openssl/src/c_helpers.c
@@ -8,10 +8,6 @@ void rust_SSL_CTX_clone(SSL_CTX *ctx) {
CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
}
-void rust_EVP_PKEY_clone(EVP_PKEY *pkey) {
- CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
-}
-
void rust_X509_clone(X509 *x509) {
CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
}
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());
+ }
}