aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorMathijs van de Nes <[email protected]>2015-09-10 12:47:26 +0200
committerMathijs van de Nes <[email protected]>2015-09-10 12:58:40 +0200
commit02b109bf0417026fe7825ef5abd3e7bf4595241f (patch)
tree04b95b0194cfc0d74a2de32aa8c14b1f3f4f72f0 /openssl/src
parentMerge pull request #265 from alexcrichton/swap-order (diff)
downloadrust-openssl-02b109bf0417026fe7825ef5abd3e7bf4595241f.tar.xz
rust-openssl-02b109bf0417026fe7825ef5abd3e7bf4595241f.zip
Check _fromstr function for success
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/crypto/pkey.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs
index 48308381..5d4bd7f1 100644
--- a/openssl/src/crypto/pkey.rs
+++ b/openssl/src/crypto/pkey.rs
@@ -110,11 +110,16 @@ impl PKey {
}
}
- fn _fromstr(&mut self, s: &[u8], f: unsafe extern "C" fn(*const *mut ffi::RSA, *const *const u8, c_uint) -> *mut ffi::RSA) {
+ fn _fromstr(&mut self, s: &[u8], f: unsafe extern "C" fn(*const *mut ffi::RSA, *const *const u8, c_uint) -> *mut ffi::RSA) -> bool {
unsafe {
let rsa = ptr::null_mut();
f(&rsa, &s.as_ptr(), s.len() as c_uint);
- ffi::EVP_PKEY_set1_RSA(self.evp, rsa);
+ if !rsa.is_null() {
+ ffi::EVP_PKEY_set1_RSA(self.evp, rsa) == 1
+ }
+ else {
+ false
+ }
}
}
@@ -148,8 +153,9 @@ impl PKey {
* Loads a serialized form of the public key, as produced by save_pub().
*/
pub fn load_pub(&mut self, s: &[u8]) {
- self._fromstr(s, ffi::d2i_RSA_PUBKEY);
- self.parts = Parts::Public;
+ if self._fromstr(s, ffi::d2i_RSA_PUBKEY) {
+ self.parts = Parts::Public;
+ }
}
/**
@@ -164,8 +170,9 @@ impl PKey {
* save_priv().
*/
pub fn load_priv(&mut self, s: &[u8]) {
- self._fromstr(s, ffi::d2i_RSAPrivateKey);
- self.parts = Parts::Both;
+ if self._fromstr(s, ffi::d2i_RSAPrivateKey) {
+ self.parts = Parts::Both;
+ }
}
/// Stores private key as a PEM