Skip to content

Commit

Permalink
Correct ownership semantics of SSL_{CTX_,}use_PrivateKey
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Apr 9, 2024
1 parent 16f975c commit 517a530
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rustls-libssl/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ entry! {
return Error::null_pointer().raise().into();
}

let pkey = EvpPkey::new_adopt(pkey);
let pkey = EvpPkey::new_incref(pkey);

match ctx
.lock()
Expand Down Expand Up @@ -1514,7 +1514,7 @@ entry! {
return Error::null_pointer().raise().into();
}

let pkey = EvpPkey::new_adopt(pkey);
let pkey = EvpPkey::new_incref(pkey);

match ssl
.lock()
Expand Down
7 changes: 5 additions & 2 deletions rustls-libssl/src/evp_pkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ pub struct EvpPkey {
}

impl EvpPkey {
/// Use a pre-existing private key, adopting ownership.
pub fn new_adopt(pkey: *mut EVP_PKEY) -> Self {
/// Use a pre-existing private key, incrementing ownership.
///
/// `pkey` continues to belong to the caller.
pub fn new_incref(pkey: *mut EVP_PKEY) -> Self {
debug_assert!(!pkey.is_null());
unsafe { EVP_PKEY_up_ref(pkey) };
Self { pkey }
}

Expand Down

0 comments on commit 517a530

Please sign in to comment.