Commit fe5fb75d authored by Steven Fackler's avatar Steven Fackler
Browse files

Update Dsa

parent 28f37597
Loading
Loading
Loading
Loading
+6 −38
Original line number Diff line number Diff line
@@ -2,27 +2,17 @@ use error::ErrorStack;
use ffi;
use libc::{c_int, c_char, c_void};
use std::fmt;
use std::ops::Deref;
use std::ptr;

use bio::{MemBio, MemBioSlice};
use bn::BigNum;
use {cvt, cvt_p};
use opaque::Opaque;
use types::Ref;
use util::{CallbackState, invoke_passwd_cb};

pub struct DsaRef(Opaque);

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 _
    }
type_!(Dsa, ffi::DSA, ffi::DSA_free);

impl Ref<Dsa> {
    /// Writes an DSA private key as unencrypted PEM formatted data
    pub fn private_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
        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 {
    pub unsafe fn from_ptr(dsa: *mut ffi::DSA) -> Dsa {
        Dsa(dsa)
    }

    /// Generate a DSA key pair.
    pub fn generate(bits: u32) -> Result<Dsa, ErrorStack> {
        unsafe {
@@ -178,11 +154,9 @@ impl Dsa {
    }
}

impl Deref for Dsa {
    type Target = DsaRef;

    fn deref(&self) -> &DsaRef {
        unsafe { DsaRef::from_ptr(self.0) }
impl fmt::Debug for Dsa {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "DSA")
    }
}

@@ -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)]
mod test {
    use libc::c_char;