Loading openssl-sys/src/lib.rs +1 −0 Original line number Diff line number Diff line Loading @@ -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; Loading openssl/src/c_helpers.c +0 −4 Original line number Diff line number Diff line Loading @@ -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); } openssl/src/crypto/pkey.rs +15 −7 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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) } } Loading Loading @@ -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()); } } Loading
openssl-sys/src/lib.rs +1 −0 Original line number Diff line number Diff line Loading @@ -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; Loading
openssl/src/c_helpers.c +0 −4 Original line number Diff line number Diff line Loading @@ -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); }
openssl/src/crypto/pkey.rs +15 −7 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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) } } Loading Loading @@ -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()); } }