aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/pkey.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-10-31 20:12:55 -0700
committerSteven Fackler <[email protected]>2016-10-31 20:12:55 -0700
commitf640613863f0b66bc004f9d9d89f73a31701d396 (patch)
tree923728c8959f6582e5f6da5b7472b304ed387e1e /openssl/src/pkey.rs
parentUpdate EcKey (diff)
downloadrust-openssl-f640613863f0b66bc004f9d9d89f73a31701d396.tar.xz
rust-openssl-f640613863f0b66bc004f9d9d89f73a31701d396.zip
Update PKey
Diffstat (limited to 'openssl/src/pkey.rs')
-rw-r--r--openssl/src/pkey.rs41
1 files changed, 4 insertions, 37 deletions
diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs
index 8e4041b1..2561ab29 100644
--- a/openssl/src/pkey.rs
+++ b/openssl/src/pkey.rs
@@ -1,7 +1,6 @@
use libc::{c_void, c_char, c_int};
use std::ptr;
use std::mem;
-use std::ops::Deref;
use ffi;
use {cvt, cvt_p};
@@ -10,20 +9,11 @@ use dsa::Dsa;
use rsa::{Rsa, RsaRef};
use error::ErrorStack;
use util::{CallbackState, invoke_passwd_cb};
-use opaque::Opaque;
+use types::{OpenSslType, Ref};
-/// A borrowed `PKey`.
-pub struct PKeyRef(Opaque);
-
-impl PKeyRef {
- pub unsafe fn from_ptr<'a>(ptr: *mut ffi::EVP_PKEY) -> &'a PKeyRef {
- &*(ptr as *mut _)
- }
-
- pub fn as_ptr(&self) -> *mut ffi::EVP_PKEY {
- self as *const _ as *mut _
- }
+type_!(PKey, ffi::EVP_PKEY, ffi::EVP_PKEY_free);
+impl Ref<PKey> {
/// Get a reference to the interal RSA key for direct access to the key components
pub fn rsa(&self) -> Result<Rsa, ErrorStack> {
unsafe {
@@ -59,14 +49,11 @@ impl PKeyRef {
Ok(mem_bio.get_buf().to_owned())
}
- pub fn public_eq(&self, other: &PKeyRef) -> bool {
+ pub fn public_eq(&self, other: &Ref<PKey>) -> bool {
unsafe { ffi::EVP_PKEY_cmp(self.as_ptr(), other.as_ptr()) == 1 }
}
}
-/// Represents a public key, optionally with a private key attached.
-pub struct PKey(*mut ffi::EVP_PKEY);
-
unsafe impl Send for PKey {}
unsafe impl Sync for PKey {}
@@ -105,10 +92,6 @@ impl PKey {
}
}
- pub unsafe fn from_ptr(handle: *mut ffi::EVP_PKEY) -> PKey {
- PKey(handle)
- }
-
/// Reads private key from PEM, takes ownership of handle
pub fn private_key_from_pem(buf: &[u8]) -> Result<PKey, ErrorStack> {
ffi::init();
@@ -166,22 +149,6 @@ impl PKey {
}
}
-impl Drop for PKey {
- fn drop(&mut self) {
- unsafe {
- ffi::EVP_PKEY_free(self.0);
- }
- }
-}
-
-impl Deref for PKey {
- type Target = PKeyRef;
-
- fn deref(&self) -> &PKeyRef {
- unsafe { PKeyRef::from_ptr(self.0) }
- }
-}
-
#[cfg(test)]
mod tests {
#[test]