diff options
| author | Steven Fackler <[email protected]> | 2016-08-07 14:19:44 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-08-07 14:33:18 -0700 |
| commit | 05089bacb3cde8fe3ec9f68b5682668d4f63383c (patch) | |
| tree | e2f7d2bb028e02504e1eecb62b4f91e2f83adb9c /openssl/src/crypto/rsa.rs | |
| parent | Clean up asn1time (diff) | |
| download | rust-openssl-05089bacb3cde8fe3ec9f68b5682668d4f63383c.tar.xz rust-openssl-05089bacb3cde8fe3ec9f68b5682668d4f63383c.zip | |
Refactor BigNum
Diffstat (limited to 'openssl/src/crypto/rsa.rs')
| -rw-r--r-- | openssl/src/crypto/rsa.rs | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/openssl/src/crypto/rsa.rs b/openssl/src/crypto/rsa.rs index 5c70c8ea..73239731 100644 --- a/openssl/src/crypto/rsa.rs +++ b/openssl/src/crypto/rsa.rs @@ -3,7 +3,7 @@ use std::fmt; use std::ptr; use libc::{c_int, c_void, c_char}; -use bn::BigNum; +use bn::{BigNum, BigNumRef}; use bio::{MemBio, MemBioSlice}; use error::ErrorStack; use crypto::HashTypeInternals; @@ -171,43 +171,49 @@ impl RSA { self.0 } - // The following getters are unsafe, since BigNum::new_from_ffi fails upon null pointers - pub fn n(&self) -> Result<BigNum, ErrorStack> { - unsafe { - BigNum::new_from_ffi((*self.0).n) - } + pub fn n<'a>(&'a self) -> BigNumRef<'a> { + assert!(self.has_n()); + unsafe { BigNumRef::from_handle((*self.0).n) } } pub fn has_n(&self) -> bool { unsafe { !(*self.0).n.is_null() } } - pub fn d(&self) -> Result<BigNum, ErrorStack> { - unsafe { - BigNum::new_from_ffi((*self.0).d) - } + pub fn d<'a>(&self) -> BigNumRef<'a> { + assert!(self.has_d()); + unsafe { BigNumRef::from_handle((*self.0).d) } } - pub fn e(&self) -> Result<BigNum, ErrorStack> { - unsafe { - BigNum::new_from_ffi((*self.0).e) - } + pub fn has_d(&self) -> bool { + unsafe { !(*self.0).d.is_null() } + } + + pub fn e<'a>(&'a self) -> BigNumRef<'a> { + assert!(self.has_e()); + unsafe { BigNumRef::from_handle((*self.0).e) } } pub fn has_e(&self) -> bool { unsafe { !(*self.0).e.is_null() } } - pub fn p(&self) -> Result<BigNum, ErrorStack> { - unsafe { - BigNum::new_from_ffi((*self.0).p) - } + pub fn p<'a>(&'a self) -> BigNumRef<'a> { + assert!(self.has_p()); + unsafe { BigNumRef::from_handle((*self.0).p) } } - pub fn q(&self) -> Result<BigNum, ErrorStack> { - unsafe { - BigNum::new_from_ffi((*self.0).q) - } + pub fn has_p(&self) -> bool { + unsafe { !(*self.0).p.is_null() } + } + + pub fn q<'a>(&'a self) -> BigNumRef<'a> { + assert!(self.has_q()); + unsafe { BigNumRef::from_handle((*self.0).q) } + } + + pub fn has_q(&self) -> bool { + unsafe { !(*self.0).q.is_null() } } } |