review fixes, keep raw RSA initiallization private
This commit is contained in:
parent
ef95223d26
commit
6ebe581308
|
|
@ -208,13 +208,10 @@ impl PKey {
|
||||||
/// pass ownership of the RSA key to this
|
/// pass ownership of the RSA key to this
|
||||||
pub fn set_rsa(&mut self, rsa: RSA) {
|
pub fn set_rsa(&mut self, rsa: RSA) {
|
||||||
unsafe {
|
unsafe {
|
||||||
// TODO: should we do something like panic if null? this will fail silently right now
|
|
||||||
let rsa_ptr = rsa.as_ptr();
|
let rsa_ptr = rsa.as_ptr();
|
||||||
if !rsa_ptr.is_null() {
|
if ffi::EVP_PKEY_set1_RSA(self.evp, rsa_ptr) == 1 {
|
||||||
if ffi::EVP_PKEY_set1_RSA(self.evp, rsa_ptr) == 1 {
|
if rsa.has_e() && rsa.has_n() {
|
||||||
if rsa.has_e() && rsa.has_n() {
|
self.parts = Parts::Public;
|
||||||
self.parts = Parts::Public;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -225,7 +222,7 @@ impl PKey {
|
||||||
unsafe {
|
unsafe {
|
||||||
let evp_pkey: *mut ffi::EVP_PKEY = self.evp;
|
let evp_pkey: *mut ffi::EVP_PKEY = self.evp;
|
||||||
// this is safe as the ffi increments a reference counter to the internal key
|
// this is safe as the ffi increments a reference counter to the internal key
|
||||||
RSA(ffi::EVP_PKEY_get1_RSA(evp_pkey))
|
RSA::with_raw(ffi::EVP_PKEY_get1_RSA(evp_pkey))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use std::io::{self, Read};
|
||||||
use bn::BigNum;
|
use bn::BigNum;
|
||||||
use bio::MemBio;
|
use bio::MemBio;
|
||||||
|
|
||||||
pub struct RSA(pub *mut ffi::RSA);
|
pub struct RSA(*mut ffi::RSA);
|
||||||
|
|
||||||
impl Drop for RSA {
|
impl Drop for RSA {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
|
@ -27,6 +27,10 @@ impl RSA {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_raw(rsa: *mut ffi::RSA) -> RSA {
|
||||||
|
RSA(rsa)
|
||||||
|
}
|
||||||
|
|
||||||
/// Reads an RSA private key from PEM formatted data.
|
/// Reads an RSA private key from PEM formatted data.
|
||||||
pub fn private_key_from_pem<R>(reader: &mut R) -> Result<RSA, SslError>
|
pub fn private_key_from_pem<R>(reader: &mut R) -> Result<RSA, SslError>
|
||||||
where R: Read
|
where R: Read
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue