Revert "Revert "impl Clone for PKey and X509 by using their 'references' member""
This commit is contained in:
parent
4e58fd10de
commit
627f394d59
|
|
@ -7,3 +7,11 @@ void rust_SSL_clone(SSL *ssl) {
|
||||||
void rust_SSL_CTX_clone(SSL_CTX *ctx) {
|
void rust_SSL_CTX_clone(SSL_CTX *ctx) {
|
||||||
CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_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);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ fn openssl_hash_nid(hash: HashType) -> c_int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn rust_EVP_PKEY_clone(pkey: *mut ffi::EVP_PKEY);
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PKey {
|
pub struct PKey {
|
||||||
evp: *mut ffi::EVP_PKEY,
|
evp: *mut ffi::EVP_PKEY,
|
||||||
parts: Parts,
|
parts: Parts,
|
||||||
|
|
@ -585,6 +589,16 @@ impl Drop for PKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Clone for PKey {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
unsafe {
|
||||||
|
rust_EVP_PKEY_clone(self.evp);
|
||||||
|
}
|
||||||
|
|
||||||
|
PKey::from_handle(self.evp, self.parts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
|
||||||
|
|
@ -509,6 +509,20 @@ impl<'ctx> X509<'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn rust_X509_clone(x509: *mut ffi::X509);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> Clone for X509<'ctx> {
|
||||||
|
fn clone(&self) -> X509<'ctx> {
|
||||||
|
unsafe { rust_X509_clone(self.handle) }
|
||||||
|
/* FIXME: given that we now have refcounting control, 'owned' should be uneeded, the 'ctx
|
||||||
|
* is probably also uneeded. We can remove both to condense the x509 api quite a bit
|
||||||
|
*/
|
||||||
|
X509::new(self.handle, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'ctx> Drop for X509<'ctx> {
|
impl<'ctx> Drop for X509<'ctx> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.owned {
|
if self.owned {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue