diff options
| author | Steven Fackler <[email protected]> | 2016-08-07 22:56:44 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-08-07 22:56:44 -0700 |
| commit | 6b1016c86e72d26d15584789456bd317bee92bca (patch) | |
| tree | 120d9fd40cb761b6496ea8d562f71eb2f17bf1cd /openssl/src/crypto | |
| parent | Remove X509Generator::bitlenth (diff) | |
| download | rust-openssl-6b1016c86e72d26d15584789456bd317bee92bca.tar.xz rust-openssl-6b1016c86e72d26d15584789456bd317bee92bca.zip | |
Add PKey::from_rsa
Diffstat (limited to 'openssl/src/crypto')
| -rw-r--r-- | openssl/src/crypto/pkey.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs index 501ffa37..607d4986 100644 --- a/openssl/src/crypto/pkey.rs +++ b/openssl/src/crypto/pkey.rs @@ -1,8 +1,9 @@ use libc::{c_void, c_char}; use std::ptr; -use bio::{MemBio, MemBioSlice}; - +use std::mem; use ffi; + +use bio::{MemBio, MemBioSlice}; use crypto::rsa::RSA; use error::ErrorStack; use crypto::util::{CallbackState, invoke_passwd_cb}; @@ -14,11 +15,14 @@ unsafe impl Sync for PKey {} /// Represents a public key, optionally with a private key attached. impl PKey { - pub fn new() -> Result<PKey, ErrorStack> { - ffi::init(); + /// Create a new `PKey` containing an RSA key. + pub fn from_rsa(rsa: RSA) -> Result<PKey, ErrorStack> { unsafe { let evp = try_ssl_null!(ffi::EVP_PKEY_new()); - Ok(PKey::from_handle(evp)) + let pkey = PKey(evp); + try_ssl!(ffi::EVP_PKEY_assign(pkey.0, ffi::EVP_PKEY_RSA, rsa.as_ptr() as *mut _)); + mem::forget(rsa); + Ok(pkey) } } |