Camel case Dsa

This commit is contained in:
Steven Fackler 2016-10-22 10:16:49 -07:00
parent 2fd201d9c3
commit b619c4e885
3 changed files with 30 additions and 30 deletions

View File

@ -10,12 +10,12 @@ use bio::{MemBio, MemBioSlice};
use util::{CallbackState, invoke_passwd_cb}; use util::{CallbackState, invoke_passwd_cb};
/// Builder for upfront DSA parameter generation /// Builder for upfront DSA parameter generation
pub struct DSAParams(*mut ffi::DSA); pub struct DsaParams(*mut ffi::DSA);
impl DSAParams { impl DsaParams {
pub fn with_size(size: u32) -> Result<DSAParams, ErrorStack> { pub fn with_size(size: u32) -> Result<DsaParams, ErrorStack> {
unsafe { 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, try!(cvt(ffi::DSA_generate_parameters_ex(dsa.0,
size as c_int, size as c_int,
ptr::null(), ptr::null(),
@ -28,17 +28,17 @@ impl DSAParams {
} }
/// Generate a key pair from the initialized parameters /// Generate a key pair from the initialized parameters
pub fn generate(self) -> Result<DSA, ErrorStack> { pub fn generate(self) -> Result<Dsa, ErrorStack> {
unsafe { unsafe {
try!(cvt(ffi::DSA_generate_key(self.0))); try!(cvt(ffi::DSA_generate_key(self.0)));
let dsa = DSA(self.0); let dsa = Dsa(self.0);
::std::mem::forget(self); ::std::mem::forget(self);
Ok(dsa) Ok(dsa)
} }
} }
} }
impl Drop for DSAParams { impl Drop for DsaParams {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ffi::DSA_free(self.0); 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) { fn drop(&mut self) {
unsafe { unsafe {
ffi::DSA_free(self.0); ffi::DSA_free(self.0);
@ -56,20 +56,20 @@ impl Drop for DSA {
} }
} }
impl DSA { impl Dsa {
pub unsafe fn from_ptr(dsa: *mut ffi::DSA) -> DSA { pub unsafe fn from_ptr(dsa: *mut ffi::DSA) -> Dsa {
DSA(dsa) Dsa(dsa)
} }
/// Generate a DSA key pair /// Generate a DSA key pair
/// For more complicated key generation scenarios see the `DSAParams` type /// For more complicated key generation scenarios see the `DSAParams` type
pub fn generate(size: u32) -> Result<DSA, ErrorStack> { pub fn generate(size: u32) -> Result<Dsa, ErrorStack> {
let params = try!(DSAParams::with_size(size)); let params = try!(DsaParams::with_size(size));
params.generate() params.generate()
} }
/// Reads a DSA private key from PEM formatted data. /// 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(); ffi::init();
let mem_bio = try!(MemBioSlice::new(buf)); let mem_bio = try!(MemBioSlice::new(buf));
@ -78,7 +78,7 @@ impl DSA {
ptr::null_mut(), ptr::null_mut(),
None, None,
ptr::null_mut()))); 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 /// The callback will be passed the password buffer and should return the number of characters
/// placed into the buffer. /// 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 where F: FnOnce(&mut [c_char]) -> usize
{ {
ffi::init(); ffi::init();
@ -100,7 +100,7 @@ impl DSA {
ptr::null_mut(), ptr::null_mut(),
Some(invoke_passwd_cb::<F>), Some(invoke_passwd_cb::<F>),
cb_ptr))); cb_ptr)));
Ok(DSA(dsa)) Ok(Dsa(dsa))
} }
} }
@ -120,7 +120,7 @@ impl DSA {
} }
/// Reads an DSA public key from PEM formatted data. /// 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(); ffi::init();
@ -130,7 +130,7 @@ impl DSA {
ptr::null_mut(), ptr::null_mut(),
None, None,
ptr::null_mut()))); 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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DSA") write!(f, "DSA")
} }
@ -242,14 +242,14 @@ mod test {
#[test] #[test]
pub fn test_generate() { pub fn test_generate() {
DSA::generate(1024).unwrap(); Dsa::generate(1024).unwrap();
} }
#[test] #[test]
pub fn test_password() { pub fn test_password() {
let mut password_queried = false; let mut password_queried = false;
let key = include_bytes!("../test/dsa-encrypted.pem"); 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_queried = true;
password[0] = b'm' as c_char; password[0] = b'm' as c_char;
password[1] = b'y' as c_char; password[1] = b'y' as c_char;

View File

@ -5,7 +5,7 @@ use ffi;
use {cvt, cvt_p}; use {cvt, cvt_p};
use bio::{MemBio, MemBioSlice}; use bio::{MemBio, MemBioSlice};
use dsa::DSA; use dsa::Dsa;
use rsa::RSA; use rsa::RSA;
use error::ErrorStack; use error::ErrorStack;
use util::{CallbackState, invoke_passwd_cb}; use util::{CallbackState, invoke_passwd_cb};
@ -29,7 +29,7 @@ impl PKey {
} }
/// Create a new `PKey` containing a DSA key. /// 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 { unsafe {
let evp = try!(cvt_p(ffi::EVP_PKEY_new())); let evp = try!(cvt_p(ffi::EVP_PKEY_new()));
let pkey = PKey(evp); let pkey = PKey(evp);

View File

@ -211,7 +211,7 @@ mod test {
use hash::MessageDigest; use hash::MessageDigest;
use sign::{Signer, Verifier}; use sign::{Signer, Verifier};
use rsa::RSA; use rsa::RSA;
use dsa::DSA; use dsa::Dsa;
use pkey::PKey; use pkey::PKey;
static INPUT: &'static [u8] = static INPUT: &'static [u8] =
@ -280,12 +280,12 @@ mod test {
let private_key = { let private_key = {
let key = include_bytes!("../test/dsa.pem"); 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 public_key = {
let key = include_bytes!("../test/dsa.pem.pub"); 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(); let mut signer = Signer::new(MessageDigest::sha1(), &private_key).unwrap();
@ -303,12 +303,12 @@ mod test {
let private_key = { let private_key = {
let key = include_bytes!("../test/dsa.pem"); 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 public_key = {
let key = include_bytes!("../test/dsa.pem.pub"); 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(); let mut signer = Signer::new(MessageDigest::sha1(), &private_key).unwrap();