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

Camel case Dsa

parent 2fd201d9
Loading
Loading
Loading
Loading
+23 −23
Original line number Diff line number Diff line
@@ -10,12 +10,12 @@ use bio::{MemBio, MemBioSlice};
use util::{CallbackState, invoke_passwd_cb};

/// Builder for upfront DSA parameter generation
pub struct DSAParams(*mut ffi::DSA);
pub struct DsaParams(*mut ffi::DSA);

impl DSAParams {
    pub fn with_size(size: u32) -> Result<DSAParams, ErrorStack> {
impl DsaParams {
    pub fn with_size(size: u32) -> Result<DsaParams, ErrorStack> {
        unsafe {
            let dsa = DSAParams(try!(cvt_p(ffi::DSA_new())));
            let dsa = DsaParams(try!(cvt_p(ffi::DSA_new())));
            try!(cvt(ffi::DSA_generate_parameters_ex(dsa.0,
                                                     size as c_int,
                                                     ptr::null(),
@@ -28,17 +28,17 @@ impl DSAParams {
    }

    /// Generate a key pair from the initialized parameters
    pub fn generate(self) -> Result<DSA, ErrorStack> {
    pub fn generate(self) -> Result<Dsa, ErrorStack> {
        unsafe {
            try!(cvt(ffi::DSA_generate_key(self.0)));
            let dsa = DSA(self.0);
            let dsa = Dsa(self.0);
            ::std::mem::forget(self);
            Ok(dsa)
        }
    }
}

impl Drop for DSAParams {
impl Drop for DsaParams {
    fn drop(&mut self) {
        unsafe {
            ffi::DSA_free(self.0);
@@ -46,9 +46,9 @@ impl Drop for DSAParams {
    }
}

pub struct DSA(*mut ffi::DSA);
pub struct Dsa(*mut ffi::DSA);

impl Drop for DSA {
impl Drop for Dsa {
    fn drop(&mut self) {
        unsafe {
            ffi::DSA_free(self.0);
@@ -56,20 +56,20 @@ impl Drop for DSA {
    }
}

impl DSA {
    pub unsafe fn from_ptr(dsa: *mut ffi::DSA) -> DSA {
        DSA(dsa)
impl Dsa {
    pub unsafe fn from_ptr(dsa: *mut ffi::DSA) -> Dsa {
        Dsa(dsa)
    }

    /// Generate a DSA key pair
    /// For more complicated key generation scenarios see the `DSAParams` type
    pub fn generate(size: u32) -> Result<DSA, ErrorStack> {
        let params = try!(DSAParams::with_size(size));
    pub fn generate(size: u32) -> Result<Dsa, ErrorStack> {
        let params = try!(DsaParams::with_size(size));
        params.generate()
    }

    /// Reads a DSA private key from PEM formatted data.
    pub fn private_key_from_pem(buf: &[u8]) -> Result<DSA, ErrorStack> {
    pub fn private_key_from_pem(buf: &[u8]) -> Result<Dsa, ErrorStack> {
        ffi::init();
        let mem_bio = try!(MemBioSlice::new(buf));

@@ -78,7 +78,7 @@ impl DSA {
                                                                 ptr::null_mut(),
                                                                 None,
                                                                 ptr::null_mut())));
            Ok(DSA(dsa))
            Ok(Dsa(dsa))
        }
    }

@@ -87,7 +87,7 @@ impl DSA {
    ///
    /// The callback will be passed the password buffer and should return the number of characters
    /// placed into the buffer.
    pub fn private_key_from_pem_cb<F>(buf: &[u8], pass_cb: F) -> Result<DSA, ErrorStack>
    pub fn private_key_from_pem_cb<F>(buf: &[u8], pass_cb: F) -> Result<Dsa, ErrorStack>
        where F: FnOnce(&mut [c_char]) -> usize
    {
        ffi::init();
@@ -100,7 +100,7 @@ impl DSA {
                                                                 ptr::null_mut(),
                                                                 Some(invoke_passwd_cb::<F>),
                                                                 cb_ptr)));
            Ok(DSA(dsa))
            Ok(Dsa(dsa))
        }
    }

@@ -120,7 +120,7 @@ impl DSA {
    }

    /// Reads an DSA public key from PEM formatted data.
    pub fn public_key_from_pem(buf: &[u8]) -> Result<DSA, ErrorStack>
    pub fn public_key_from_pem(buf: &[u8]) -> Result<Dsa, ErrorStack>
    {
        ffi::init();

@@ -130,7 +130,7 @@ impl DSA {
                                                              ptr::null_mut(),
                                                              None,
                                                              ptr::null_mut())));
            Ok(DSA(dsa))
            Ok(Dsa(dsa))
        }
    }

@@ -228,7 +228,7 @@ mod compat {
    }
}

impl fmt::Debug for DSA {
impl fmt::Debug for Dsa {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "DSA")
    }
@@ -242,14 +242,14 @@ mod test {

    #[test]
    pub fn test_generate() {
        DSA::generate(1024).unwrap();
        Dsa::generate(1024).unwrap();
    }

    #[test]
    pub fn test_password() {
        let mut password_queried = false;
        let key = include_bytes!("../test/dsa-encrypted.pem");
        DSA::private_key_from_pem_cb(key, |password| {
        Dsa::private_key_from_pem_cb(key, |password| {
            password_queried = true;
            password[0] = b'm' as c_char;
            password[1] = b'y' as c_char;
+2 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ use ffi;

use {cvt, cvt_p};
use bio::{MemBio, MemBioSlice};
use dsa::DSA;
use dsa::Dsa;
use rsa::RSA;
use error::ErrorStack;
use util::{CallbackState, invoke_passwd_cb};
@@ -29,7 +29,7 @@ impl PKey {
    }

    /// Create a new `PKey` containing a DSA key.
    pub fn from_dsa(dsa: DSA) -> Result<PKey, ErrorStack> {
    pub fn from_dsa(dsa: Dsa) -> Result<PKey, ErrorStack> {
        unsafe {
            let evp = try!(cvt_p(ffi::EVP_PKEY_new()));
            let pkey = PKey(evp);
+5 −5
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ mod test {
    use hash::MessageDigest;
    use sign::{Signer, Verifier};
    use rsa::RSA;
    use dsa::DSA;
    use dsa::Dsa;
    use pkey::PKey;

    static INPUT: &'static [u8] =
@@ -280,12 +280,12 @@ mod test {

        let private_key = {
            let key = include_bytes!("../test/dsa.pem");
            PKey::from_dsa(DSA::private_key_from_pem(key).unwrap()).unwrap()
            PKey::from_dsa(Dsa::private_key_from_pem(key).unwrap()).unwrap()
        };

        let public_key = {
            let key = include_bytes!("../test/dsa.pem.pub");
            PKey::from_dsa(DSA::public_key_from_pem(key).unwrap()).unwrap()
            PKey::from_dsa(Dsa::public_key_from_pem(key).unwrap()).unwrap()
        };

        let mut signer = Signer::new(MessageDigest::sha1(), &private_key).unwrap();
@@ -303,12 +303,12 @@ mod test {

        let private_key = {
            let key = include_bytes!("../test/dsa.pem");
            PKey::from_dsa(DSA::private_key_from_pem(key).unwrap()).unwrap()
            PKey::from_dsa(Dsa::private_key_from_pem(key).unwrap()).unwrap()
        };

        let public_key = {
            let key = include_bytes!("../test/dsa.pem.pub");
            PKey::from_dsa(DSA::public_key_from_pem(key).unwrap()).unwrap()
            PKey::from_dsa(Dsa::public_key_from_pem(key).unwrap()).unwrap()
        };

        let mut signer = Signer::new(MessageDigest::sha1(), &private_key).unwrap();