review fixes, keep raw RSA initiallization private

This commit is contained in:
Benjamin Fry 2016-02-23 20:49:21 -08:00
parent ef95223d26
commit 6ebe581308
2 changed files with 9 additions and 8 deletions

View File

@ -208,9 +208,7 @@ impl PKey {
/// pass ownership of the RSA key to this
pub fn set_rsa(&mut self, rsa: RSA) {
unsafe {
// TODO: should we do something like panic if null? this will fail silently right now
let rsa_ptr = rsa.as_ptr();
if !rsa_ptr.is_null() {
if ffi::EVP_PKEY_set1_RSA(self.evp, rsa_ptr) == 1 {
if rsa.has_e() && rsa.has_n() {
self.parts = Parts::Public;
@ -218,14 +216,13 @@ impl PKey {
}
}
}
}
/// get a reference to the interal RSA key for direct access to the key components
pub fn get_rsa(&self) -> RSA {
unsafe {
let evp_pkey: *mut ffi::EVP_PKEY = self.evp;
// 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))
}
}

View File

@ -7,7 +7,7 @@ use std::io::{self, Read};
use bn::BigNum;
use bio::MemBio;
pub struct RSA(pub *mut ffi::RSA);
pub struct RSA(*mut ffi::RSA);
impl Drop for RSA {
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.
pub fn private_key_from_pem<R>(reader: &mut R) -> Result<RSA, SslError>
where R: Read