diff options
| author | Benjamin Fry <[email protected]> | 2016-02-17 23:18:42 -0800 |
|---|---|---|
| committer | Benjamin Fry <[email protected]> | 2016-02-17 23:18:42 -0800 |
| commit | ef95223d2679d68b36df77393bd334d4da02077f (patch) | |
| tree | cc89a9298a784b981940e2b191328957722062aa /openssl/src/crypto/rsa.rs | |
| parent | Update appveyor openssl version (diff) | |
| download | rust-openssl-ef95223d2679d68b36df77393bd334d4da02077f.tar.xz rust-openssl-ef95223d2679d68b36df77393bd334d4da02077f.zip | |
adding functionality to directly get and set RSA key material
Diffstat (limited to 'openssl/src/crypto/rsa.rs')
| -rw-r--r-- | openssl/src/crypto/rsa.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/openssl/src/crypto/rsa.rs b/openssl/src/crypto/rsa.rs index ee0d9ec4..034f8828 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(*mut ffi::RSA); +pub struct RSA(pub *mut ffi::RSA); impl Drop for RSA { fn drop(&mut self) { @@ -18,6 +18,15 @@ impl Drop for RSA { } impl RSA { + /// only useful for associating the key material directly with the key, it's safer to use + /// the supplied load and save methods for DER formatted keys. + pub fn new() -> Result<RSA, SslError> { + unsafe { + let rsa = try_ssl_null!(ffi::RSA_new()); + Ok(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 @@ -61,6 +70,19 @@ impl RSA { } } + /// set the key modulus + pub fn set_n(&mut self, n: BigNum) { + unsafe { + (*self.0).n = n.into_raw(); + } + } + + pub fn has_n(&self) -> bool { + unsafe { + !(*self.0).n.is_null() + } + } + pub fn d(&self) -> Result<BigNum, SslError> { unsafe { BigNum::new_from_ffi((*self.0).d) @@ -73,6 +95,19 @@ impl RSA { } } + /// set the exponent + pub fn set_e(&mut self, e: BigNum) { + unsafe { + (*self.0).e = e.into_raw(); + } + } + + pub fn has_e(&self) -> bool { + unsafe { + !(*self.0).e.is_null() + } + } + pub fn p(&self) -> Result<BigNum, SslError> { unsafe { BigNum::new_from_ffi((*self.0).p) |