Commit 084cf3c6 authored by Steven Fackler's avatar Steven Fackler Committed by GitHub
Browse files

Merge pull request #572 from sfackler/foreign-types

Switch to foreign_types
parents 3ee2f4c6 12ae31ad
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ v110 = []

[dependencies]
bitflags = "0.7"
foreign-types = "0.1"
lazy_static = "0.2"
libc = "0.2"
openssl-sys = { version = "0.9.6", path = "../openssl-sys" }
+22 −4
Original line number Diff line number Diff line
use ffi;
use foreign_types::{ForeignType, ForeignTypeRef};
use libc::{c_long, c_char};
use std::fmt;
use std::ptr;
@@ -8,10 +9,15 @@ use std::str;
use {cvt, cvt_p};
use bio::MemBio;
use error::ErrorStack;
use types::{OpenSslType, OpenSslTypeRef};
use string::OpensslString;

type_!(Asn1GeneralizedTime, Asn1GeneralizedTimeRef, ffi::ASN1_GENERALIZEDTIME, ffi::ASN1_GENERALIZEDTIME_free);
foreign_type! {
    type CType = ffi::ASN1_GENERALIZEDTIME;
    fn drop = ffi::ASN1_GENERALIZEDTIME_free;

    pub struct Asn1GeneralizedTime;
    pub struct Asn1GeneralizedTimeRef;
}

impl fmt::Display for Asn1GeneralizedTimeRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -23,7 +29,13 @@ impl fmt::Display for Asn1GeneralizedTimeRef {
    }
}

type_!(Asn1Time, Asn1TimeRef, ffi::ASN1_TIME, ffi::ASN1_TIME_free);
foreign_type! {
    type CType = ffi::ASN1_TIME;
    fn drop = ffi::ASN1_TIME_free;

    pub struct Asn1Time;
    pub struct Asn1TimeRef;
}

impl fmt::Display for Asn1TimeRef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -51,7 +63,13 @@ impl Asn1Time {
    }
}

type_!(Asn1String, Asn1StringRef, ffi::ASN1_STRING, ffi::ASN1_STRING_free);
foreign_type! {
    type CType = ffi::ASN1_STRING;
    fn drop = ffi::ASN1_STRING_free;

    pub struct Asn1String;
    pub struct Asn1StringRef;
}

impl Asn1StringRef {
    pub fn as_utf8(&self) -> Result<OpensslString, ErrorStack> {
+15 −3
Original line number Diff line number Diff line
use ffi;
use foreign_types::{ForeignType, ForeignTypeRef};
use libc::c_int;
use std::cmp::Ordering;
use std::ffi::CString;
@@ -8,7 +9,6 @@ use std::ops::{Add, Div, Mul, Neg, Rem, Shl, Shr, Sub, Deref};
use {cvt, cvt_p, cvt_n};
use error::ErrorStack;
use string::OpensslString;
use types::{OpenSslType, OpenSslTypeRef};

#[cfg(ossl10x)]
use ffi::{get_rfc2409_prime_768 as BN_get_rfc2409_prime_768,
@@ -40,7 +40,13 @@ pub const MSB_ONE: MsbOption = MsbOption(0);
/// of bits in the original numbers.
pub const TWO_MSB_ONE: MsbOption = MsbOption(1);

type_!(BigNumContext, BigNumContextRef, ffi::BN_CTX, ffi::BN_CTX_free);
foreign_type! {
    type CType = ffi::BN_CTX;
    fn drop = ffi::BN_CTX_free;

    pub struct BigNumContext;
    pub struct BigNumContextRef;
}

impl BigNumContext {
    /// Returns a new `BigNumContext`.
@@ -509,7 +515,13 @@ impl BigNumRef {
    }
}

type_!(BigNum, BigNumRef, ffi::BIGNUM, ffi::BN_free);
foreign_type! {
    type CType = ffi::BIGNUM;
    fn drop = ffi::BN_free;

    pub struct BigNum;
    pub struct BigNumRef;
}

impl BigNum {
    /// Creates a new `BigNum` with the value 0.
+9 −2
Original line number Diff line number Diff line
use error::ErrorStack;
use ffi;
use foreign_types::ForeignTypeRef;
use std::mem;
use std::ptr;

use {cvt, cvt_p, init};
use bn::BigNum;
use types::OpenSslTypeRef;

type_!(Dh, DhRef, ffi::DH, ffi::DH_free);
foreign_type! {
    type CType = ffi::DH;
    fn drop = ffi::DH_free;

    pub struct Dh;

    pub struct DhRef;
}

impl DhRef {
    to_pem!(ffi::PEM_write_bio_DHparams);
+10 −4
Original line number Diff line number Diff line
use error::ErrorStack;
use ffi;
use foreign_types::ForeignTypeRef;
use libc::{c_int, c_char, c_void};
use std::fmt;
use std::ptr;

use {cvt, cvt_p};
use bio::MemBioSlice;
use bn::BigNumRef;
use {cvt, cvt_p};
use types::OpenSslTypeRef;
use error::ErrorStack;
use util::{CallbackState, invoke_passwd_cb_old};

type_!(Dsa, DsaRef, ffi::DSA, ffi::DSA_free);
foreign_type! {
    type CType = ffi::DSA;
    fn drop = ffi::DSA_free;

    pub struct Dsa;
    pub struct DsaRef;
}

impl DsaRef {
    private_key_to_pem!(ffi::PEM_write_bio_DSAPrivateKey);
Loading