diff options
| author | Steven Fackler <[email protected]> | 2016-11-13 17:06:50 +0000 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-11-13 17:06:50 +0000 |
| commit | 48c0009418cbbf7c69c24b35d56e80edb0c80d45 (patch) | |
| tree | 21ab4cb2b259ea883a36865d0971c3ad65ea0722 /openssl/src/rsa.rs | |
| parent | Macroise to_der (diff) | |
| download | rust-openssl-48c0009418cbbf7c69c24b35d56e80edb0c80d45.tar.xz rust-openssl-48c0009418cbbf7c69c24b35d56e80edb0c80d45.zip | |
Macroise from_der
Diffstat (limited to 'openssl/src/rsa.rs')
| -rw-r--r-- | openssl/src/rsa.rs | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index 89c0bb85..5090f6ad 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -1,9 +1,8 @@ use ffi; -use std::cmp; use std::fmt; use std::ptr; use std::mem; -use libc::{c_int, c_void, c_char, c_long}; +use libc::{c_int, c_void, c_char}; use {cvt, cvt_p, cvt_n}; use bn::{BigNum, BigNumRef}; @@ -251,6 +250,8 @@ impl Rsa { } private_key_from_pem!(Rsa, ffi::PEM_read_bio_RSAPrivateKey); + private_key_from_der!(Rsa, ffi::d2i_RSAPrivateKey); + public_key_from_der!(Rsa, ffi::d2i_RSA_PUBKEY); #[deprecated(since = "0.9.2", note = "use private_key_from_pem_callback")] pub fn private_key_from_pem_cb<F>(buf: &[u8], pass_cb: F) -> Result<Rsa, ErrorStack> @@ -282,26 +283,6 @@ impl Rsa { Ok(Rsa(rsa)) } } - - /// Reads an RSA private key from DER formatted data. - pub fn private_key_from_der(buf: &[u8]) -> Result<Rsa, ErrorStack> { - unsafe { - ffi::init(); - let len = cmp::min(buf.len(), c_long::max_value() as usize) as c_long; - let dsa = try!(cvt_p(ffi::d2i_RSAPrivateKey(ptr::null_mut(), &mut buf.as_ptr(), len))); - Ok(Rsa(dsa)) - } - } - - /// Reads an RSA public key from DER formatted data. - pub fn public_key_from_der(buf: &[u8]) -> Result<Rsa, ErrorStack> { - unsafe { - ffi::init(); - let len = cmp::min(buf.len(), c_long::max_value() as usize) as c_long; - let dsa = try!(cvt_p(ffi::d2i_RSA_PUBKEY(ptr::null_mut(), &mut buf.as_ptr(), len))); - Ok(Rsa(dsa)) - } - } } impl fmt::Debug for Rsa { |