Unverified Commit 75b0978b authored by Steven Fackler's avatar Steven Fackler Committed by GitHub
Browse files

Merge pull request #1345 from stbuehler/from-const-ptr

Add and use ForeignTypeRefExt::from_const_ptr
parents 8341d79c b2caf477
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ use std::ptr;
use bn::{BigNum, BigNumRef};
use error::ErrorStack;
use pkey::{HasParams, HasPrivate, HasPublic, Private, Public};
use util::ForeignTypeRefExt;
use {cvt, cvt_p};

generic_foreign_type_and_impl_send_sync! {
@@ -107,7 +108,7 @@ where
        unsafe {
            let mut pub_key = ptr::null();
            DSA_get0_key(self.as_ptr(), &mut pub_key, ptr::null_mut());
            BigNumRef::from_ptr(pub_key as *mut _)
            BigNumRef::from_const_ptr(pub_key)
        }
    }
}
@@ -141,7 +142,7 @@ where
        unsafe {
            let mut priv_key = ptr::null();
            DSA_get0_key(self.as_ptr(), ptr::null_mut(), &mut priv_key);
            BigNumRef::from_ptr(priv_key as *mut _)
            BigNumRef::from_const_ptr(priv_key)
        }
    }
}
@@ -164,7 +165,7 @@ where
        unsafe {
            let mut p = ptr::null();
            DSA_get0_pqg(self.as_ptr(), &mut p, ptr::null_mut(), ptr::null_mut());
            BigNumRef::from_ptr(p as *mut _)
            BigNumRef::from_const_ptr(p)
        }
    }

@@ -173,7 +174,7 @@ where
        unsafe {
            let mut q = ptr::null();
            DSA_get0_pqg(self.as_ptr(), ptr::null_mut(), &mut q, ptr::null_mut());
            BigNumRef::from_ptr(q as *mut _)
            BigNumRef::from_const_ptr(q)
        }
    }

@@ -182,7 +183,7 @@ where
        unsafe {
            let mut g = ptr::null();
            DSA_get0_pqg(self.as_ptr(), ptr::null_mut(), ptr::null_mut(), &mut g);
            BigNumRef::from_ptr(g as *mut _)
            BigNumRef::from_const_ptr(g)
        }
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ use bn::{BigNumContextRef, BigNumRef};
use error::ErrorStack;
use nid::Nid;
use pkey::{HasParams, HasPrivate, HasPublic, Params, Private, Public};
use util::ForeignTypeRefExt;
use {cvt, cvt_n, cvt_p, init};

/// Compressed or Uncompressed conversion
@@ -230,7 +231,7 @@ impl EcGroupRef {
    pub fn generator(&self) -> &EcPointRef {
        unsafe {
            let ptr = ffi::EC_GROUP_get0_generator(self.as_ptr());
            EcPointRef::from_ptr(ptr as *mut _)
            EcPointRef::from_const_ptr(ptr)
        }
    }

@@ -622,7 +623,7 @@ where
    pub fn private_key(&self) -> &BigNumRef {
        unsafe {
            let ptr = ffi::EC_KEY_get0_private_key(self.as_ptr());
            BigNumRef::from_ptr(ptr as *mut _)
            BigNumRef::from_const_ptr(ptr)
        }
    }
}
@@ -639,7 +640,7 @@ where
    pub fn public_key(&self) -> &EcPointRef {
        unsafe {
            let ptr = ffi::EC_KEY_get0_public_key(self.as_ptr());
            EcPointRef::from_ptr(ptr as *mut _)
            EcPointRef::from_const_ptr(ptr)
        }
    }

@@ -678,7 +679,7 @@ where
    pub fn group(&self) -> &EcGroupRef {
        unsafe {
            let ptr = ffi::EC_KEY_get0_group(self.as_ptr());
            EcGroupRef::from_ptr(ptr as *mut _)
            EcGroupRef::from_const_ptr(ptr)
        }
    }

+5 −4
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use bn::{BigNum, BigNumRef};
use ec::EcKeyRef;
use error::ErrorStack;
use pkey::{HasPrivate, HasPublic};
use util::ForeignTypeRefExt;
use {cvt_n, cvt_p};

foreign_type_and_impl_send_sync! {
@@ -45,7 +46,7 @@ impl EcdsaSig {
                data.len() as c_int,
                eckey.as_ptr(),
            ))?;
            Ok(EcdsaSig::from_ptr(sig as *mut _))
            Ok(EcdsaSig::from_ptr(sig))
        }
    }

@@ -60,7 +61,7 @@ impl EcdsaSig {
            let sig = cvt_p(ffi::ECDSA_SIG_new())?;
            ECDSA_SIG_set0(sig, r.as_ptr(), s.as_ptr());
            mem::forget((r, s));
            Ok(EcdsaSig::from_ptr(sig as *mut _))
            Ok(EcdsaSig::from_ptr(sig))
        }
    }

@@ -117,7 +118,7 @@ impl EcdsaSigRef {
        unsafe {
            let mut r = ptr::null();
            ECDSA_SIG_get0(self.as_ptr(), &mut r, ptr::null_mut());
            BigNumRef::from_ptr(r as *mut _)
            BigNumRef::from_const_ptr(r)
        }
    }

@@ -130,7 +131,7 @@ impl EcdsaSigRef {
        unsafe {
            let mut s = ptr::null();
            ECDSA_SIG_get0(self.as_ptr(), ptr::null_mut(), &mut s);
            BigNumRef::from_ptr(s as *mut _)
            BigNumRef::from_const_ptr(s)
        }
    }
}
+2 −5
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use asn1::Asn1GeneralizedTimeRef;
use error::ErrorStack;
use hash::MessageDigest;
use stack::StackRef;
use util::ForeignTypeRefExt;
use x509::store::X509StoreRef;
use x509::{X509Ref, X509};
use {cvt, cvt_p};
@@ -188,11 +189,7 @@ impl OcspBasicResponseRef {
                &mut next_update,
            );
            if r == 1 {
                let revocation_time = if revocation_time.is_null() {
                    None
                } else {
                    Some(Asn1GeneralizedTimeRef::from_ptr(revocation_time))
                };
                let revocation_time = Asn1GeneralizedTimeRef::from_const_ptr_opt(revocation_time);

                Some(OcspStatus {
                    status: OcspCertStatus(status),
+2 −5
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use error::ErrorStack;
use nid::Nid;
use pkey::{HasPrivate, PKey, PKeyRef, Private};
use stack::Stack;
use util::ForeignTypeExt;
use x509::{X509Ref, X509};
use {cvt, cvt_p};

@@ -52,11 +53,7 @@ impl Pkcs12Ref {
            let pkey = PKey::from_ptr(pkey);
            let cert = X509::from_ptr(cert);

            let chain = if chain.is_null() {
                None
            } else {
                Some(Stack::from_ptr(chain))
            };
            let chain = Stack::from_ptr_opt(chain);

            Ok(ParsedPkcs12 { pkey, cert, chain })
        }
Loading