From 7dbef567e6cec78adb1d7ec55735935ca7de20fd Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 13 Nov 2016 18:00:42 +0000 Subject: [PATCH] Remove some stray manual impls --- openssl/src/dsa.rs | 12 ++---------- openssl/src/pkey.rs | 12 ++---------- openssl/src/rsa.rs | 14 ++------------ 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/openssl/src/dsa.rs b/openssl/src/dsa.rs index fbef2c18..a4a8bf30 100644 --- a/openssl/src/dsa.rs +++ b/openssl/src/dsa.rs @@ -4,7 +4,7 @@ use libc::{c_int, c_char, c_void}; use std::fmt; use std::ptr; -use bio::{MemBio, MemBioSlice}; +use bio::MemBioSlice; use bn::BigNumRef; use {cvt, cvt_p}; use types::OpenSslTypeRef; @@ -14,15 +14,7 @@ type_!(Dsa, DsaRef, ffi::DSA, ffi::DSA_free); impl DsaRef { private_key_to_pem!(ffi::PEM_write_bio_DSAPrivateKey); - - /// Encodes a DSA public key as PEM formatted data. - pub fn public_key_to_pem(&self) -> Result, ErrorStack> { - let mem_bio = try!(MemBio::new()); - unsafe { - try!(cvt(ffi::PEM_write_bio_DSA_PUBKEY(mem_bio.as_ptr(), self.as_ptr()))); - } - Ok(mem_bio.get_buf().to_owned()) - } + public_key_to_pem!(ffi::PEM_write_bio_DSA_PUBKEY); private_key_to_der!(ffi::i2d_DSAPrivateKey); public_key_to_der!(ffi::i2d_DSAPublicKey); diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index b5ccd3cc..ee564836 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -4,7 +4,7 @@ use std::mem; use ffi; use {cvt, cvt_p}; -use bio::{MemBio, MemBioSlice}; +use bio::MemBioSlice; use dh::Dh; use dsa::Dsa; use ec_key::EcKey; @@ -48,20 +48,12 @@ impl PKeyRef { } } + public_key_to_pem!(ffi::PEM_write_bio_PUBKEY); private_key_to_pem!(ffi::PEM_write_bio_PKCS8PrivateKey); private_key_to_der!(ffi::i2d_PrivateKey); public_key_to_der!(ffi::i2d_PUBKEY); - /// Encodes the public key in the PEM format. - pub fn public_key_to_pem(&self) -> Result, ErrorStack> { - let mem_bio = try!(MemBio::new()); - unsafe { - try!(cvt(ffi::PEM_write_bio_PUBKEY(mem_bio.as_ptr(), self.as_ptr()))); - } - Ok(mem_bio.get_buf().to_owned()) - } - /// Returns the size of the key. /// /// This corresponds to the bit length of the modulus of an RSA key, and the bit length of the diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index 68fc9584..8c3507f4 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -6,7 +6,7 @@ use libc::{c_int, c_void, c_char}; use {cvt, cvt_p, cvt_n}; use bn::{BigNum, BigNumRef}; -use bio::{MemBio, MemBioSlice}; +use bio::MemBioSlice; use error::ErrorStack; use util::{CallbackState, invoke_passwd_cb_old}; use types::OpenSslTypeRef; @@ -23,17 +23,7 @@ type_!(Rsa, RsaRef, ffi::RSA, ffi::RSA_free); impl RsaRef { private_key_to_pem!(ffi::PEM_write_bio_RSAPrivateKey); - - /// Writes an RSA public key as PEM formatted data - pub fn public_key_to_pem(&self) -> Result, ErrorStack> { - let mem_bio = try!(MemBio::new()); - - unsafe { - try!(cvt(ffi::PEM_write_bio_RSA_PUBKEY(mem_bio.as_ptr(), self.as_ptr()))); - } - - Ok(mem_bio.get_buf().to_owned()) - } + public_key_to_pem!(ffi::PEM_write_bio_RSA_PUBKEY); private_key_to_der!(ffi::i2d_RSAPrivateKey); public_key_to_der!(ffi::i2d_RSA_PUBKEY);