aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Fry <[email protected]>2016-02-23 20:49:21 -0800
committerBenjamin Fry <[email protected]>2016-02-23 20:49:21 -0800
commit6ebe581308af861b440557be5baba2edb354f7b8 (patch)
treef2fce3e588bd7b33164c9b04a773026ce4daaa39
parentadding functionality to directly get and set RSA key material (diff)
downloadrust-openssl-6ebe581308af861b440557be5baba2edb354f7b8.tar.xz
rust-openssl-6ebe581308af861b440557be5baba2edb354f7b8.zip
review fixes, keep raw RSA initiallization private
-rw-r--r--openssl/src/crypto/pkey.rs11
-rw-r--r--openssl/src/crypto/rsa.rs6
2 files changed, 9 insertions, 8 deletions
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs
index dc613bc7..df4ac709 100644
--- a/openssl/src/crypto/pkey.rs
+++ b/openssl/src/crypto/pkey.rs
@@ -208,13 +208,10 @@ 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;
- }
+ if ffi::EVP_PKEY_set1_RSA(self.evp, rsa_ptr) == 1 {
+ if rsa.has_e() && rsa.has_n() {
+ self.parts = Parts::Public;
}
}
}
@@ -225,7 +222,7 @@ impl PKey {
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))
}
}
diff --git a/openssl/src/crypto/rsa.rs b/openssl/src/crypto/rsa.rs
index 034f8828..80eec7da 100644
--- a/openssl/src/crypto/rsa.rs
+++ b/openssl/src/crypto/rsa.rs
@@ -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