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

Update Rsa

parent f6406138
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ use ffi;
use {cvt, cvt_p};
use bio::{MemBio, MemBioSlice};
use dsa::Dsa;
use rsa::{Rsa, RsaRef};
use rsa::Rsa;
use error::ErrorStack;
use util::{CallbackState, invoke_passwd_cb};
use types::{OpenSslType, Ref};
@@ -139,7 +139,7 @@ impl PKey {
    }

    /// Assign an RSA key to this pkey.
    pub fn set_rsa(&mut self, rsa: &RsaRef) -> Result<(), ErrorStack> {
    pub fn set_rsa(&mut self, rsa: &Ref<Rsa>) -> Result<(), ErrorStack> {
        unsafe {
            // this needs to be a reference as the set1_RSA ups the reference count
            let rsa_ptr = rsa.as_ptr();
+2 −34
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ use ffi;
use std::fmt;
use std::ptr;
use std::mem;
use std::ops::Deref;
use libc::{c_int, c_void, c_char};

use {cvt, cvt_p, cvt_n};
@@ -11,7 +10,6 @@ use bio::{MemBio, MemBioSlice};
use error::ErrorStack;
use util::{CallbackState, invoke_passwd_cb};
use types::{OpenSslType, Ref};
use opaque::Opaque;

/// Type of encryption padding to use.
#[derive(Copy, Clone)]
@@ -21,17 +19,9 @@ pub const NO_PADDING: Padding = Padding(ffi::RSA_NO_PADDING);
pub const PKCS1_PADDING: Padding = Padding(ffi::RSA_PKCS1_PADDING);
pub const PKCS1_OAEP_PADDING: Padding = Padding(ffi::RSA_PKCS1_OAEP_PADDING);

pub struct RsaRef(Opaque);

impl RsaRef {
    pub unsafe fn from_ptr<'a>(ptr: *mut ffi::RSA) -> &'a RsaRef {
        &*(ptr as *mut _)
    }

    pub fn as_ptr(&self) -> *mut ffi::RSA {
        self as *const _ as *mut _
    }
type_!(Rsa, ffi::RSA, ffi::RSA_free);

impl Ref<Rsa> {
    /// Writes an RSA private key as unencrypted PEM formatted data
    pub fn private_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
        let mem_bio = try!(MemBio::new());
@@ -219,16 +209,6 @@ impl RsaRef {
    }
}

pub struct Rsa(*mut ffi::RSA);

impl Drop for Rsa {
    fn drop(&mut self) {
        unsafe {
            ffi::RSA_free(self.0);
        }
    }
}

impl Rsa {
    /// only useful for associating the key material directly with the key, it's safer to use
    /// the supplied load and save methods for DER formatted keys.
@@ -266,10 +246,6 @@ impl Rsa {
        }
    }

    pub unsafe fn from_ptr(rsa: *mut ffi::RSA) -> Rsa {
        Rsa(rsa)
    }

    /// Generates a public/private key pair with the specified size.
    ///
    /// The public exponent will be 65537.
@@ -330,14 +306,6 @@ impl fmt::Debug for Rsa {
    }
}

impl Deref for Rsa {
    type Target = RsaRef;

    fn deref(&self) -> &RsaRef {
        unsafe { RsaRef::from_ptr(self.0) }
    }
}

#[cfg(ossl110)]
mod compat {
    use std::ptr;