Clean up RSA and DSA accessors
This commit is contained in:
parent
deb94a904b
commit
e4b97921a9
|
|
@ -145,7 +145,7 @@ impl DSA {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn size(&self) -> Option<u32> {
|
pub fn size(&self) -> Option<u32> {
|
||||||
if self.has_q() {
|
if self.q().is_some() {
|
||||||
unsafe { Some(ffi::DSA_size(self.0) as u32) }
|
unsafe { Some(ffi::DSA_size(self.0) as u32) }
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -189,31 +189,37 @@ impl DSA {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn p<'a>(&'a self) -> BigNumRef<'a> {
|
pub fn p<'a>(&'a self) -> Option<BigNumRef<'a>> {
|
||||||
assert!(self.has_p());
|
unsafe {
|
||||||
unsafe { BigNumRef::from_handle((*self.0).p) }
|
let p = (*self.0).p;
|
||||||
|
if p.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(BigNumRef::from_handle((*self.0).p))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_p(&self) -> bool {
|
pub fn q<'a>(&'a self) -> Option<BigNumRef<'a>> {
|
||||||
unsafe { !(*self.0).p.is_null() }
|
unsafe {
|
||||||
|
let q = (*self.0).q;
|
||||||
|
if q.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(BigNumRef::from_handle((*self.0).q))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn q<'a>(&'a self) -> BigNumRef<'a> {
|
pub fn g<'a>(&'a self) -> Option<BigNumRef<'a>> {
|
||||||
assert!(self.has_q());
|
unsafe {
|
||||||
unsafe { BigNumRef::from_handle((*self.0).q) }
|
let g = (*self.0).g;
|
||||||
|
if g.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(BigNumRef::from_handle((*self.0).g))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_q(&self) -> bool {
|
|
||||||
unsafe { !(*self.0).q.is_null() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn g<'a>(&'a self) -> BigNumRef<'a> {
|
|
||||||
assert!(self.has_g());
|
|
||||||
unsafe { BigNumRef::from_handle((*self.0).g) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_g(&self) -> bool {
|
|
||||||
unsafe { !(*self.0).q.is_null() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_public_key(&self) -> bool {
|
pub fn has_public_key(&self) -> bool {
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ impl RSA {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn size(&self) -> Option<u32> {
|
pub fn size(&self) -> Option<u32> {
|
||||||
if self.has_n() {
|
if self.n().is_some() {
|
||||||
unsafe { Some(ffi::RSA_size(self.0) as u32) }
|
unsafe { Some(ffi::RSA_size(self.0) as u32) }
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -184,49 +184,59 @@ impl RSA {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn n<'a>(&'a self) -> BigNumRef<'a> {
|
pub fn n<'a>(&'a self) -> Option<BigNumRef<'a>> {
|
||||||
assert!(self.has_n());
|
unsafe {
|
||||||
unsafe { BigNumRef::from_handle((*self.0).n) }
|
let n = (*self.0).n;
|
||||||
|
if n.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(BigNumRef::from_handle(n))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_n(&self) -> bool {
|
pub fn d<'a>(&self) -> Option<BigNumRef<'a>> {
|
||||||
unsafe { !(*self.0).n.is_null() }
|
unsafe {
|
||||||
|
let d = (*self.0).d;
|
||||||
|
if d.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(BigNumRef::from_handle(d))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn d<'a>(&self) -> BigNumRef<'a> {
|
pub fn e<'a>(&'a self) -> Option<BigNumRef<'a>> {
|
||||||
assert!(self.has_d());
|
unsafe {
|
||||||
unsafe { BigNumRef::from_handle((*self.0).d) }
|
let e = (*self.0).e;
|
||||||
|
if e.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(BigNumRef::from_handle(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_d(&self) -> bool {
|
pub fn p<'a>(&'a self) -> Option<BigNumRef<'a>> {
|
||||||
unsafe { !(*self.0).d.is_null() }
|
unsafe {
|
||||||
|
let p = (*self.0).p;
|
||||||
|
if p.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(BigNumRef::from_handle(p))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn e<'a>(&'a self) -> BigNumRef<'a> {
|
pub fn q<'a>(&'a self) -> Option<BigNumRef<'a>> {
|
||||||
assert!(self.has_e());
|
unsafe {
|
||||||
unsafe { BigNumRef::from_handle((*self.0).e) }
|
let q = (*self.0).q;
|
||||||
|
if q.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(BigNumRef::from_handle(q))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_e(&self) -> bool {
|
|
||||||
unsafe { !(*self.0).e.is_null() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue