Update Dsa

This commit is contained in:
Steven Fackler 2016-10-31 20:04:55 -07:00
parent 28f375974a
commit fe5fb75d45
1 changed files with 6 additions and 38 deletions

View File

@ -2,27 +2,17 @@ use error::ErrorStack;
use ffi; use ffi;
use libc::{c_int, c_char, c_void}; use libc::{c_int, c_char, c_void};
use std::fmt; use std::fmt;
use std::ops::Deref;
use std::ptr; use std::ptr;
use bio::{MemBio, MemBioSlice}; use bio::{MemBio, MemBioSlice};
use bn::BigNum; use bn::BigNum;
use {cvt, cvt_p}; use {cvt, cvt_p};
use opaque::Opaque;
use types::Ref; use types::Ref;
use util::{CallbackState, invoke_passwd_cb}; use util::{CallbackState, invoke_passwd_cb};
pub struct DsaRef(Opaque); type_!(Dsa, ffi::DSA, ffi::DSA_free);
impl DsaRef {
pub unsafe fn from_ptr<'a>(ptr: *mut ffi::DSA) -> &'a DsaRef {
&*(ptr as *mut _)
}
pub fn as_ptr(&self) -> *mut ffi::DSA {
self as *const _ as *mut _
}
impl Ref<Dsa> {
/// Writes an DSA private key as unencrypted PEM formatted data /// Writes an DSA private key as unencrypted PEM formatted data
pub fn private_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> { pub fn private_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
assert!(self.has_private_key()); assert!(self.has_private_key());
@ -96,21 +86,7 @@ impl DsaRef {
} }
} }
pub struct Dsa(*mut ffi::DSA);
impl Drop for Dsa {
fn drop(&mut self) {
unsafe {
ffi::DSA_free(self.0);
}
}
}
impl Dsa { impl Dsa {
pub unsafe fn from_ptr(dsa: *mut ffi::DSA) -> Dsa {
Dsa(dsa)
}
/// Generate a DSA key pair. /// Generate a DSA key pair.
pub fn generate(bits: u32) -> Result<Dsa, ErrorStack> { pub fn generate(bits: u32) -> Result<Dsa, ErrorStack> {
unsafe { unsafe {
@ -178,11 +154,9 @@ impl Dsa {
} }
} }
impl Deref for Dsa { impl fmt::Debug for Dsa {
type Target = DsaRef; fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DSA")
fn deref(&self) -> &DsaRef {
unsafe { DsaRef::from_ptr(self.0) }
} }
} }
@ -217,12 +191,6 @@ mod compat {
} }
} }
impl fmt::Debug for Dsa {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DSA")
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use libc::c_char; use libc::c_char;