aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/crypto/pkey.rs
diff options
context:
space:
mode:
authorBenjamin Fry <[email protected]>2016-02-17 23:18:42 -0800
committerBenjamin Fry <[email protected]>2016-02-17 23:18:42 -0800
commitef95223d2679d68b36df77393bd334d4da02077f (patch)
treecc89a9298a784b981940e2b191328957722062aa /openssl/src/crypto/pkey.rs
parentUpdate appveyor openssl version (diff)
downloadrust-openssl-ef95223d2679d68b36df77393bd334d4da02077f.tar.xz
rust-openssl-ef95223d2679d68b36df77393bd334d4da02077f.zip
adding functionality to directly get and set RSA key material
Diffstat (limited to 'openssl/src/crypto/pkey.rs')
-rw-r--r--openssl/src/crypto/pkey.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs
index e556730d..dc613bc7 100644
--- a/openssl/src/crypto/pkey.rs
+++ b/openssl/src/crypto/pkey.rs
@@ -205,6 +205,30 @@ 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;
+ }
+ }
+ }
+ }
+ }
+
+ /// 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))
+ }
+ }
+
/**
* Returns a DER serialized form of the public key, suitable for load_pub().
*/