Method renames

This commit is contained in:
Steven Fackler 2016-08-10 21:28:17 -07:00
parent c15642ccea
commit 59fe901357
7 changed files with 52 additions and 52 deletions

View File

@ -28,7 +28,7 @@ impl<'a> MemBioSlice<'a> {
Ok(MemBioSlice(bio, PhantomData))
}
pub fn handle(&self) -> *mut ffi::BIO {
pub fn as_ptr(&self) -> *mut ffi::BIO {
self.0
}
}
@ -53,7 +53,7 @@ impl MemBio {
Ok(MemBio(bio))
}
pub fn handle(&self) -> *mut ffi::BIO {
pub fn as_ptr(&self) -> *mut ffi::BIO {
self.0
}

View File

@ -72,7 +72,7 @@ impl DSA {
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let dsa = try_ssl_null!(ffi::PEM_read_bio_DSAPrivateKey(mem_bio.handle(),
let dsa = try_ssl_null!(ffi::PEM_read_bio_DSAPrivateKey(mem_bio.as_ptr(),
ptr::null_mut(),
None,
ptr::null_mut()));
@ -96,7 +96,7 @@ impl DSA {
unsafe {
let cb_ptr = &mut cb as *mut _ as *mut c_void;
let dsa = try_ssl_null!(ffi::PEM_read_bio_DSAPrivateKey(mem_bio.handle(),
let dsa = try_ssl_null!(ffi::PEM_read_bio_DSAPrivateKey(mem_bio.as_ptr(),
ptr::null_mut(),
Some(invoke_passwd_cb::<F>),
cb_ptr));
@ -113,7 +113,7 @@ impl DSA {
let mem_bio = try!(MemBio::new());
unsafe {
try_ssl!(ffi::PEM_write_bio_DSAPrivateKey(mem_bio.handle(), self.0,
try_ssl!(ffi::PEM_write_bio_DSAPrivateKey(mem_bio.as_ptr(), self.0,
ptr::null(), ptr::null_mut(), 0,
None, ptr::null_mut()))
};
@ -128,7 +128,7 @@ impl DSA {
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let dsa = try_ssl_null!(ffi::PEM_read_bio_DSA_PUBKEY(mem_bio.handle(),
let dsa = try_ssl_null!(ffi::PEM_read_bio_DSA_PUBKEY(mem_bio.as_ptr(),
ptr::null_mut(),
None,
ptr::null_mut()));
@ -139,7 +139,7 @@ impl DSA {
/// Writes an DSA public key as PEM formatted data
pub fn public_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
let mem_bio = try!(MemBio::new());
unsafe { try_ssl!(ffi::PEM_write_bio_DSA_PUBKEY(mem_bio.handle(), self.0)) };
unsafe { try_ssl!(ffi::PEM_write_bio_DSA_PUBKEY(mem_bio.as_ptr(), self.0)) };
Ok(mem_bio.get_buf().to_owned())
}

View File

@ -26,7 +26,7 @@ impl PKey {
}
}
pub unsafe fn from_handle(handle: *mut ffi::EVP_PKEY) -> PKey {
pub unsafe fn from_ptr(handle: *mut ffi::EVP_PKEY) -> PKey {
PKey(handle)
}
@ -35,11 +35,11 @@ impl PKey {
ffi::init();
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let evp = try_ssl_null!(ffi::PEM_read_bio_PrivateKey(mem_bio.handle(),
let evp = try_ssl_null!(ffi::PEM_read_bio_PrivateKey(mem_bio.as_ptr(),
ptr::null_mut(),
None,
ptr::null_mut()));
Ok(PKey::from_handle(evp))
Ok(PKey::from_ptr(evp))
}
}
@ -55,11 +55,11 @@ impl PKey {
let mut cb = CallbackState::new(pass_cb);
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let evp = try_ssl_null!(ffi::PEM_read_bio_PrivateKey(mem_bio.handle(),
let evp = try_ssl_null!(ffi::PEM_read_bio_PrivateKey(mem_bio.as_ptr(),
ptr::null_mut(),
Some(invoke_passwd_cb::<F>),
&mut cb as *mut _ as *mut c_void));
Ok(PKey::from_handle(evp))
Ok(PKey::from_ptr(evp))
}
}
@ -68,11 +68,11 @@ impl PKey {
ffi::init();
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let evp = try_ssl_null!(ffi::PEM_read_bio_PUBKEY(mem_bio.handle(),
let evp = try_ssl_null!(ffi::PEM_read_bio_PUBKEY(mem_bio.as_ptr(),
ptr::null_mut(),
None,
ptr::null_mut()));
Ok(PKey::from_handle(evp))
Ok(PKey::from_ptr(evp))
}
}
@ -91,7 +91,7 @@ impl PKey {
unsafe {
let rsa = try_ssl_null!(ffi::EVP_PKEY_get1_RSA(self.0));
// this is safe as the ffi increments a reference counter to the internal key
Ok(RSA::from_raw(rsa))
Ok(RSA::from_ptr(rsa))
}
}
@ -100,7 +100,7 @@ impl PKey {
pub fn private_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
let mem_bio = try!(MemBio::new());
unsafe {
try_ssl!(ffi::PEM_write_bio_PrivateKey(mem_bio.handle(),
try_ssl!(ffi::PEM_write_bio_PrivateKey(mem_bio.as_ptr(),
self.0,
ptr::null(),
ptr::null_mut(),
@ -115,11 +115,11 @@ impl PKey {
/// Stores public key as a PEM
pub fn public_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
let mem_bio = try!(MemBio::new());
unsafe { try_ssl!(ffi::PEM_write_bio_PUBKEY(mem_bio.handle(), self.0)) }
unsafe { try_ssl!(ffi::PEM_write_bio_PUBKEY(mem_bio.as_ptr(), self.0)) }
Ok(mem_bio.get_buf().to_owned())
}
pub fn handle(&self) -> *mut ffi::EVP_PKEY {
pub fn as_ptr(&self) -> *mut ffi::EVP_PKEY {
return self.0;
}

View File

@ -66,7 +66,7 @@ impl RSA {
}
}
pub unsafe fn from_raw(rsa: *mut ffi::RSA) -> RSA {
pub unsafe fn from_ptr(rsa: *mut ffi::RSA) -> RSA {
RSA(rsa)
}
@ -89,7 +89,7 @@ impl RSA {
pub fn private_key_from_pem(buf: &[u8]) -> Result<RSA, ErrorStack> {
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let rsa = try_ssl_null!(ffi::PEM_read_bio_RSAPrivateKey(mem_bio.handle(),
let rsa = try_ssl_null!(ffi::PEM_read_bio_RSAPrivateKey(mem_bio.as_ptr(),
ptr::null_mut(),
None,
ptr::null_mut()));
@ -106,7 +106,7 @@ impl RSA {
unsafe {
let cb_ptr = &mut cb as *mut _ as *mut c_void;
let rsa = try_ssl_null!(ffi::PEM_read_bio_RSAPrivateKey(mem_bio.handle(),
let rsa = try_ssl_null!(ffi::PEM_read_bio_RSAPrivateKey(mem_bio.as_ptr(),
ptr::null_mut(),
Some(invoke_passwd_cb::<F>),
cb_ptr));
@ -119,7 +119,7 @@ impl RSA {
pub fn public_key_from_pem(buf: &[u8]) -> Result<RSA, ErrorStack> {
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let rsa = try_ssl_null!(ffi::PEM_read_bio_RSA_PUBKEY(mem_bio.handle(),
let rsa = try_ssl_null!(ffi::PEM_read_bio_RSA_PUBKEY(mem_bio.as_ptr(),
ptr::null_mut(),
None,
ptr::null_mut()));
@ -132,7 +132,7 @@ impl RSA {
let mem_bio = try!(MemBio::new());
unsafe {
try_ssl!(ffi::PEM_write_bio_RSAPrivateKey(mem_bio.handle(),
try_ssl!(ffi::PEM_write_bio_RSAPrivateKey(mem_bio.as_ptr(),
self.0,
ptr::null(),
ptr::null_mut(),
@ -148,7 +148,7 @@ impl RSA {
let mem_bio = try!(MemBio::new());
unsafe {
try_ssl!(ffi::PEM_write_bio_RSA_PUBKEY(mem_bio.handle(), self.0))
try_ssl!(ffi::PEM_write_bio_RSA_PUBKEY(mem_bio.as_ptr(), self.0))
};
Ok(mem_bio.get_buf().to_owned())

View File

@ -21,7 +21,7 @@ impl DH {
pub fn from_pem(buf: &[u8]) -> Result<DH, ErrorStack> {
let mem_bio = try!(MemBioSlice::new(buf));
let dh = unsafe {
ffi::PEM_read_bio_DHparams(mem_bio.handle(), ptr::null_mut(), None, ptr::null_mut())
ffi::PEM_read_bio_DHparams(mem_bio.as_ptr(), ptr::null_mut(), None, ptr::null_mut())
};
try_ssl_null!(dh);
Ok(DH(dh))

View File

@ -529,14 +529,14 @@ impl<'a> SslContextRef<'a> {
/// Specifies the certificate
pub fn set_certificate(&mut self, cert: &X509Ref) -> Result<(), ErrorStack> {
wrap_ssl_result(unsafe { ffi::SSL_CTX_use_certificate(self.as_ptr(), cert.handle()) })
wrap_ssl_result(unsafe { ffi::SSL_CTX_use_certificate(self.as_ptr(), cert.as_ptr()) })
}
/// Adds a certificate to the certificate chain presented together with the
/// certificate specified using set_certificate()
pub fn add_extra_chain_cert(&mut self, cert: &X509Ref) -> Result<(), ErrorStack> {
wrap_ssl_result(unsafe {
ffi::SSL_CTX_add_extra_chain_cert(self.as_ptr(), cert.handle()) as c_int
ffi::SSL_CTX_add_extra_chain_cert(self.as_ptr(), cert.as_ptr()) as c_int
})
}
@ -555,7 +555,7 @@ impl<'a> SslContextRef<'a> {
/// Specifies the private key
pub fn set_private_key(&mut self, key: &PKey) -> Result<(), ErrorStack> {
wrap_ssl_result(unsafe { ffi::SSL_CTX_use_PrivateKey(self.as_ptr(), key.handle()) })
wrap_ssl_result(unsafe { ffi::SSL_CTX_use_PrivateKey(self.as_ptr(), key.as_ptr()) })
}
/// Check consistency of private key and certificate

View File

@ -300,24 +300,24 @@ impl X509Generator {
let x509 = try_ssl_null!(ffi::X509_new());
let x509 = X509::new(x509);
try_ssl!(ffi::X509_set_version(x509.handle(), 2));
try_ssl!(ffi::ASN1_INTEGER_set(ffi::X509_get_serialNumber(x509.handle()),
try_ssl!(ffi::X509_set_version(x509.as_ptr(), 2));
try_ssl!(ffi::ASN1_INTEGER_set(ffi::X509_get_serialNumber(x509.as_ptr()),
try!(X509Generator::random_serial())));
let not_before = try!(Asn1Time::days_from_now(0));
let not_after = try!(Asn1Time::days_from_now(self.days));
try_ssl!(ffi::X509_set_notBefore(x509.handle(), not_before.as_ptr() as *const _));
try_ssl!(ffi::X509_set_notBefore(x509.as_ptr(), not_before.as_ptr() as *const _));
// If prev line succeded - ownership should go to cert
mem::forget(not_before);
try_ssl!(ffi::X509_set_notAfter(x509.handle(), not_after.as_ptr() as *const _));
try_ssl!(ffi::X509_set_notAfter(x509.as_ptr(), not_after.as_ptr() as *const _));
// If prev line succeded - ownership should go to cert
mem::forget(not_after);
try_ssl!(ffi::X509_set_pubkey(x509.handle(), p_key.handle()));
try_ssl!(ffi::X509_set_pubkey(x509.as_ptr(), p_key.as_ptr()));
let name = try_ssl_null!(ffi::X509_get_subject_name(x509.handle()));
let name = try_ssl_null!(ffi::X509_get_subject_name(x509.as_ptr()));
let default = [("CN", "rust-openssl")];
let default_iter = &mut default.iter().map(|&(k, v)| (k, v));
@ -331,16 +331,16 @@ impl X509Generator {
for (key, val) in iter {
try!(X509Generator::add_name_internal(name, &key, &val));
}
try_ssl!(ffi::X509_set_issuer_name(x509.handle(), name));
try_ssl!(ffi::X509_set_issuer_name(x509.as_ptr(), name));
for (exttype, ext) in self.extensions.iter() {
try!(X509Generator::add_extension_internal(x509.handle(),
try!(X509Generator::add_extension_internal(x509.as_ptr(),
&exttype,
&ext.to_string()));
}
let hash_fn = self.hash_type.evp_md();
try_ssl!(ffi::X509_sign(x509.handle(), p_key.handle(), hash_fn));
try_ssl!(ffi::X509_sign(x509.as_ptr(), p_key.as_ptr(), hash_fn));
Ok(x509)
}
}
@ -356,16 +356,16 @@ impl X509Generator {
};
unsafe {
let req = ffi::X509_to_X509_REQ(cert.handle(), ptr::null_mut(), ptr::null());
let req = ffi::X509_to_X509_REQ(cert.as_ptr(), ptr::null_mut(), ptr::null());
try_ssl_null!(req);
let exts = ::c_helpers::rust_X509_get_extensions(cert.handle());
let exts = ::c_helpers::rust_X509_get_extensions(cert.as_ptr());
if exts != ptr::null_mut() {
try_ssl!(ffi::X509_REQ_add_extensions(req, exts));
}
let hash_fn = self.hash_type.evp_md();
try_ssl!(ffi::X509_REQ_sign(req, p_key.handle(), hash_fn));
try_ssl!(ffi::X509_REQ_sign(req, p_key.as_ptr(), hash_fn));
Ok(X509Req::new(req))
}
@ -381,7 +381,7 @@ impl<'a> X509Ref<'a> {
X509Ref(handle, PhantomData)
}
pub fn handle(&self) -> *mut ffi::X509 {
pub fn as_ptr(&self) -> *mut ffi::X509 {
self.0
}
@ -411,7 +411,7 @@ impl<'a> X509Ref<'a> {
pub fn public_key(&self) -> Result<PKey, ErrorStack> {
unsafe {
let pkey = try_ssl_null!(ffi::X509_get_pubkey(self.0));
Ok(PKey::from_handle(pkey))
Ok(PKey::from_ptr(pkey))
}
}
@ -431,7 +431,7 @@ impl<'a> X509Ref<'a> {
pub fn to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
let mem_bio = try!(MemBio::new());
unsafe {
try_ssl!(ffi::PEM_write_bio_X509(mem_bio.handle(), self.0));
try_ssl!(ffi::PEM_write_bio_X509(mem_bio.as_ptr(), self.0));
}
Ok(mem_bio.get_buf().to_owned())
}
@ -440,7 +440,7 @@ impl<'a> X509Ref<'a> {
pub fn to_der(&self) -> Result<Vec<u8>, ErrorStack> {
let mem_bio = try!(MemBio::new());
unsafe {
ffi::i2d_X509_bio(mem_bio.handle(), self.0);
ffi::i2d_X509_bio(mem_bio.as_ptr(), self.0);
}
Ok(mem_bio.get_buf().to_owned())
}
@ -459,7 +459,7 @@ impl X509 {
pub fn from_pem(buf: &[u8]) -> Result<X509, ErrorStack> {
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let handle = try_ssl_null!(ffi::PEM_read_bio_X509(mem_bio.handle(),
let handle = try_ssl_null!(ffi::PEM_read_bio_X509(mem_bio.as_ptr(),
ptr::null_mut(),
None,
ptr::null_mut()));
@ -481,15 +481,15 @@ impl Clone for X509 {
/// Requires the `x509_clone` feature.
fn clone(&self) -> X509 {
unsafe {
::c_helpers::rust_X509_clone(self.handle());
X509::new(self.handle())
::c_helpers::rust_X509_clone(self.as_ptr());
X509::new(self.as_ptr())
}
}
}
impl Drop for X509 {
fn drop(&mut self) {
unsafe { ffi::X509_free(self.handle()) };
unsafe { ffi::X509_free(self.as_ptr()) };
}
}
@ -536,7 +536,7 @@ impl X509Req {
X509Req(handle)
}
pub fn handle(&self) -> *mut ffi::X509_REQ {
pub fn as_ptr(&self) -> *mut ffi::X509_REQ {
self.0
}
@ -544,7 +544,7 @@ impl X509Req {
pub fn from_pem(buf: &[u8]) -> Result<X509Req, ErrorStack> {
let mem_bio = try!(MemBioSlice::new(buf));
unsafe {
let handle = try_ssl_null!(ffi::PEM_read_bio_X509_REQ(mem_bio.handle(),
let handle = try_ssl_null!(ffi::PEM_read_bio_X509_REQ(mem_bio.as_ptr(),
ptr::null_mut(),
None,
ptr::null_mut()));
@ -555,7 +555,7 @@ impl X509Req {
/// Writes CSR as PEM
pub fn to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
let mem_bio = try!(MemBio::new());
if unsafe { ffi::PEM_write_bio_X509_REQ(mem_bio.handle(), self.0) } != 1 {
if unsafe { ffi::PEM_write_bio_X509_REQ(mem_bio.as_ptr(), self.0) } != 1 {
return Err(ErrorStack::get());
}
Ok(mem_bio.get_buf().to_owned())
@ -565,7 +565,7 @@ impl X509Req {
pub fn to_der(&self) -> Result<Vec<u8>, ErrorStack> {
let mem_bio = try!(MemBio::new());
unsafe {
ffi::i2d_X509_REQ_bio(mem_bio.handle(), self.0);
ffi::i2d_X509_REQ_bio(mem_bio.as_ptr(), self.0);
}
Ok(mem_bio.get_buf().to_owned())
}