aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-08-08 19:04:30 -0700
committerSteven Fackler <[email protected]>2016-08-08 19:04:30 -0700
commite4b97921a9ff2f1bddd49f4a64981ccfeadd9b04 (patch)
tree7a7eef4ce053268991c7155f6fa6ea582bc02442 /openssl/src
parentFix build on 1.9 (diff)
downloadrust-openssl-e4b97921a9ff2f1bddd49f4a64981ccfeadd9b04.tar.xz
rust-openssl-e4b97921a9ff2f1bddd49f4a64981ccfeadd9b04.zip
Clean up RSA and DSA accessors
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/crypto/dsa.rs50
-rw-r--r--openssl/src/crypto/rsa.rs82
2 files changed, 74 insertions, 58 deletions
diff --git a/openssl/src/crypto/dsa.rs b/openssl/src/crypto/dsa.rs
index 099657da..7852d391 100644
--- a/openssl/src/crypto/dsa.rs
+++ b/openssl/src/crypto/dsa.rs
@@ -145,7 +145,7 @@ impl DSA {
}
pub fn size(&self) -> Option<u32> {
- if self.has_q() {
+ if self.q().is_some() {
unsafe { Some(ffi::DSA_size(self.0) as u32) }
} else {
None
@@ -189,31 +189,37 @@ impl DSA {
self.0
}
- pub fn p<'a>(&'a self) -> BigNumRef<'a> {
- assert!(self.has_p());
- unsafe { BigNumRef::from_handle((*self.0).p) }
- }
-
- 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() }
+ pub fn p<'a>(&'a self) -> Option<BigNumRef<'a>> {
+ unsafe {
+ let p = (*self.0).p;
+ if p.is_null() {
+ None
+ } else {
+ Some(BigNumRef::from_handle((*self.0).p))
+ }
+ }
}
- pub fn g<'a>(&'a self) -> BigNumRef<'a> {
- assert!(self.has_g());
- unsafe { BigNumRef::from_handle((*self.0).g) }
+ pub fn q<'a>(&'a self) -> Option<BigNumRef<'a>> {
+ unsafe {
+ let q = (*self.0).q;
+ if q.is_null() {
+ None
+ } else {
+ Some(BigNumRef::from_handle((*self.0).q))
+ }
+ }
}
- pub fn has_g(&self) -> bool {
- unsafe { !(*self.0).q.is_null() }
+ pub fn g<'a>(&'a self) -> Option<BigNumRef<'a>> {
+ unsafe {
+ let g = (*self.0).g;
+ if g.is_null() {
+ None
+ } else {
+ Some(BigNumRef::from_handle((*self.0).g))
+ }
+ }
}
pub fn has_public_key(&self) -> bool {
diff --git a/openssl/src/crypto/rsa.rs b/openssl/src/crypto/rsa.rs
index 66341a8b..2dfa64a6 100644
--- a/openssl/src/crypto/rsa.rs
+++ b/openssl/src/crypto/rsa.rs
@@ -144,7 +144,7 @@ impl RSA {
}
pub fn size(&self) -> Option<u32> {
- if self.has_n() {
+ if self.n().is_some() {
unsafe { Some(ffi::RSA_size(self.0) as u32) }
} else {
None
@@ -184,49 +184,59 @@ impl RSA {
self.0
}
- 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<'a>(&self) -> BigNumRef<'a> {
- assert!(self.has_d());
- unsafe { BigNumRef::from_handle((*self.0).d) }
- }
-
- 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 n<'a>(&'a self) -> Option<BigNumRef<'a>> {
+ unsafe {
+ let n = (*self.0).n;
+ if n.is_null() {
+ None
+ } else {
+ Some(BigNumRef::from_handle(n))
+ }
+ }
}
- pub fn p<'a>(&'a self) -> BigNumRef<'a> {
- assert!(self.has_p());
- unsafe { BigNumRef::from_handle((*self.0).p) }
+ pub fn d<'a>(&self) -> Option<BigNumRef<'a>> {
+ unsafe {
+ let d = (*self.0).d;
+ if d.is_null() {
+ None
+ } else {
+ Some(BigNumRef::from_handle(d))
+ }
+ }
}
- pub fn has_p(&self) -> bool {
- unsafe { !(*self.0).p.is_null() }
+ pub fn e<'a>(&'a self) -> Option<BigNumRef<'a>> {
+ unsafe {
+ let e = (*self.0).e;
+ if e.is_null() {
+ None
+ } else {
+ Some(BigNumRef::from_handle(e))
+ }
+ }
}
- pub fn q<'a>(&'a self) -> BigNumRef<'a> {
- assert!(self.has_q());
- unsafe { BigNumRef::from_handle((*self.0).q) }
+ pub fn p<'a>(&'a self) -> Option<BigNumRef<'a>> {
+ unsafe {
+ let p = (*self.0).p;
+ if p.is_null() {
+ None
+ } else {
+ Some(BigNumRef::from_handle(p))
+ }
+ }
}
- pub fn has_q(&self) -> bool {
- unsafe { !(*self.0).q.is_null() }
+ pub fn q<'a>(&'a self) -> Option<BigNumRef<'a>> {
+ unsafe {
+ let q = (*self.0).q;
+ if q.is_null() {
+ None
+ } else {
+ Some(BigNumRef::from_handle(q))
+ }
+ }
}
}