Update dependencies

In particular, this updates `foreign-types`, which had a lot of breaking changes.

- `ForeignType` is now an unsafe trait
- `*Ref` types no longer need a separate macro call, they're generated automatically
- Generated types now store `NonNull<T>` instead of `*mut T`
This commit is contained in:
Joshua Nelson 2021-08-09 16:35:27 -05:00 committed by Joshua Nelson
parent c037a438f8
commit e46378d4de
10 changed files with 36 additions and 37 deletions

View File

@ -13,12 +13,12 @@ edition = "2018"
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
foreign-types = "0.3.1" foreign-types = "0.5"
lazy_static = "1" lazy_static = "1"
libc = "0.2" libc = "0.2"
boring-sys = { version = "1.1.0", path = "../boring-sys" } boring-sys = { version = "1.1.0", path = "../boring-sys" }
[dev-dependencies] [dev-dependencies]
tempdir = "0.3" tempdir = "0.3"
hex = "0.3" hex = "0.4"
rusty-hook = "^0.10.1" rusty-hook = "^0.11"

View File

@ -80,7 +80,7 @@ impl BigNumContext {
pub fn new() -> Result<BigNumContext, ErrorStack> { pub fn new() -> Result<BigNumContext, ErrorStack> {
unsafe { unsafe {
ffi::init(); ffi::init();
cvt_p(ffi::BN_CTX_new()).map(BigNumContext) cvt_p(ffi::BN_CTX_new()).map(|p| BigNumContext::from_ptr(p))
} }
} }
} }

View File

@ -1,5 +1,6 @@
//! Interface for processing OpenSSL configuration files. //! Interface for processing OpenSSL configuration files.
use crate::ffi; use crate::ffi;
use foreign_types::ForeignType;
use libc::c_void; use libc::c_void;
use crate::cvt_p; use crate::cvt_p;
@ -34,6 +35,6 @@ foreign_type_and_impl_send_sync! {
impl Conf { impl Conf {
/// Create a configuration parser. /// Create a configuration parser.
pub fn new(method: ConfMethod) -> Result<Conf, ErrorStack> { pub fn new(method: ConfMethod) -> Result<Conf, ErrorStack> {
unsafe { cvt_p(ffi::NCONF_new(method.as_ptr())).map(Conf) } unsafe { cvt_p(ffi::NCONF_new(method.as_ptr())).map(|p| Conf::from_ptr(p)) }
} }
} }

View File

@ -122,7 +122,7 @@ impl EcGroup {
pub fn from_curve_name(nid: Nid) -> Result<EcGroup, ErrorStack> { pub fn from_curve_name(nid: Nid) -> Result<EcGroup, ErrorStack> {
unsafe { unsafe {
init(); init();
cvt_p(ffi::EC_GROUP_new_by_curve_name(nid.as_raw())).map(EcGroup) cvt_p(ffi::EC_GROUP_new_by_curve_name(nid.as_raw())).map(|p| EcGroup::from_ptr(p))
} }
} }
} }
@ -421,7 +421,9 @@ impl EcPointRef {
/// ///
/// [`EC_POINT_dup`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_POINT_dup.html /// [`EC_POINT_dup`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_POINT_dup.html
pub fn to_owned(&self, group: &EcGroupRef) -> Result<EcPoint, ErrorStack> { pub fn to_owned(&self, group: &EcGroupRef) -> Result<EcPoint, ErrorStack> {
unsafe { cvt_p(ffi::EC_POINT_dup(self.as_ptr(), group.as_ptr())).map(EcPoint) } unsafe {
cvt_p(ffi::EC_POINT_dup(self.as_ptr(), group.as_ptr())).map(|p| EcPoint::from_ptr(p))
}
} }
/// Determines if this point is equal to another. /// Determines if this point is equal to another.
@ -479,7 +481,7 @@ impl EcPoint {
/// ///
/// [`EC_POINT_new`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_POINT_new.html /// [`EC_POINT_new`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_POINT_new.html
pub fn new(group: &EcGroupRef) -> Result<EcPoint, ErrorStack> { pub fn new(group: &EcGroupRef) -> Result<EcPoint, ErrorStack> {
unsafe { cvt_p(ffi::EC_POINT_new(group.as_ptr())).map(EcPoint) } unsafe { cvt_p(ffi::EC_POINT_new(group.as_ptr())).map(|p| EcPoint::from_ptr(p)) }
} }
/// Creates point from a binary representation /// Creates point from a binary representation

View File

@ -145,19 +145,13 @@ macro_rules! foreign_type_and_impl_send_sync {
=> { => {
foreign_type! { foreign_type! {
$(#[$impl_attr])* $(#[$impl_attr])*
type CType = $ctype;
fn drop = $drop;
$(fn clone = $clone;)*
$(#[$owned_attr])* $(#[$owned_attr])*
pub struct $owned; pub unsafe type $owned: Send + Sync {
$(#[$borrowed_attr])* type CType = $ctype;
pub struct $borrowed; fn drop = $drop;
$(fn clone = $clone;)*
}
} }
unsafe impl Send for $owned{}
unsafe impl Send for $borrowed{}
unsafe impl Sync for $owned{}
unsafe impl Sync for $borrowed{}
}; };
} }
@ -177,7 +171,7 @@ macro_rules! generic_foreign_type_and_impl_send_sync {
pub struct $owned<T>(*mut $ctype, ::std::marker::PhantomData<T>); pub struct $owned<T>(*mut $ctype, ::std::marker::PhantomData<T>);
$(#[$impl_attr])* $(#[$impl_attr])*
impl<T> ::foreign_types::ForeignType for $owned<T> { unsafe impl<T> ::foreign_types::ForeignType for $owned<T> {
type CType = $ctype; type CType = $ctype;
type Ref = $borrowed<T>; type Ref = $borrowed<T>;
@ -257,7 +251,7 @@ macro_rules! generic_foreign_type_and_impl_send_sync {
pub struct $borrowed<T>(::foreign_types::Opaque, ::std::marker::PhantomData<T>); pub struct $borrowed<T>(::foreign_types::Opaque, ::std::marker::PhantomData<T>);
$(#[$impl_attr])* $(#[$impl_attr])*
impl<T> ::foreign_types::ForeignTypeRef for $borrowed<T> { unsafe impl<T> ::foreign_types::ForeignTypeRef for $borrowed<T> {
type CType = $ctype; type CType = $ctype;
} }

View File

@ -196,7 +196,7 @@ impl Pkcs12Builder {
self.mac_iter, self.mac_iter,
keytype, keytype,
)) ))
.map(Pkcs12) .map(|p| Pkcs12::from_ptr(p))
} }
} }
} }

View File

@ -73,7 +73,7 @@ use std::mem::{self, ManuallyDrop};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::panic::resume_unwind; use std::panic::resume_unwind;
use std::path::Path; use std::path::Path;
use std::ptr; use std::ptr::{self, NonNull};
use std::slice; use std::slice;
use std::str; use std::str;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -1829,7 +1829,7 @@ impl ClientHello {
/// Information about a cipher. /// Information about a cipher.
pub struct SslCipher(*mut ffi::SSL_CIPHER); pub struct SslCipher(*mut ffi::SSL_CIPHER);
impl ForeignType for SslCipher { unsafe impl ForeignType for SslCipher {
type CType = ffi::SSL_CIPHER; type CType = ffi::SSL_CIPHER;
type Ref = SslCipherRef; type Ref = SslCipherRef;
@ -1863,7 +1863,7 @@ impl DerefMut for SslCipher {
/// [`SslCipher`]: struct.SslCipher.html /// [`SslCipher`]: struct.SslCipher.html
pub struct SslCipherRef(Opaque); pub struct SslCipherRef(Opaque);
impl ForeignTypeRef for SslCipherRef { unsafe impl ForeignTypeRef for SslCipherRef {
type CType = ffi::SSL_CIPHER; type CType = ffi::SSL_CIPHER;
} }
@ -1997,7 +1997,7 @@ impl ToOwned for SslSessionRef {
fn to_owned(&self) -> SslSession { fn to_owned(&self) -> SslSession {
unsafe { unsafe {
SSL_SESSION_up_ref(self.as_ptr()); SSL_SESSION_up_ref(self.as_ptr());
SslSession(self.as_ptr()) SslSession(NonNull::new_unchecked(self.as_ptr()))
} }
} }
} }

View File

@ -89,7 +89,7 @@ impl<T: Stackable> Borrow<StackRef<T>> for Stack<T> {
} }
} }
impl<T: Stackable> ForeignType for Stack<T> { unsafe impl<T: Stackable> ForeignType for Stack<T> {
type CType = T::StackType; type CType = T::StackType;
type Ref = StackRef<T>; type Ref = StackRef<T>;
@ -170,7 +170,7 @@ pub struct StackRef<T: Stackable>(Opaque, PhantomData<T>);
unsafe impl<T: Stackable + Send> Send for StackRef<T> {} unsafe impl<T: Stackable + Send> Send for StackRef<T> {}
unsafe impl<T: Stackable + Sync> Sync for StackRef<T> {} unsafe impl<T: Stackable + Sync> Sync for StackRef<T> {}
impl<T: Stackable> ForeignTypeRef for StackRef<T> { unsafe impl<T: Stackable> ForeignTypeRef for StackRef<T> {
type CType = T::StackType; type CType = T::StackType;
} }

View File

@ -67,7 +67,7 @@ impl X509StoreContext {
pub fn new() -> Result<X509StoreContext, ErrorStack> { pub fn new() -> Result<X509StoreContext, ErrorStack> {
unsafe { unsafe {
ffi::init(); ffi::init();
cvt_p(ffi::X509_STORE_CTX_new()).map(X509StoreContext) cvt_p(ffi::X509_STORE_CTX_new()).map(|p| X509StoreContext::from_ptr(p))
} }
} }
} }
@ -226,7 +226,7 @@ impl X509Builder {
pub fn new() -> Result<X509Builder, ErrorStack> { pub fn new() -> Result<X509Builder, ErrorStack> {
unsafe { unsafe {
ffi::init(); ffi::init();
cvt_p(ffi::X509_new()).map(|p| X509Builder(X509(p))) cvt_p(ffi::X509_new()).map(|p| X509Builder(X509::from_ptr(p)))
} }
} }
@ -664,7 +664,7 @@ impl X509 {
return Err(ErrorStack::get()); return Err(ErrorStack::get());
} else { } else {
certs.push(X509(r)); certs.push(X509::from_ptr(r));
} }
} }
@ -764,7 +764,8 @@ impl X509Extension {
let name = name.as_ptr() as *mut _; let name = name.as_ptr() as *mut _;
let value = value.as_ptr() as *mut _; let value = value.as_ptr() as *mut _;
cvt_p(ffi::X509V3_EXT_nconf(conf, context, name, value)).map(X509Extension) cvt_p(ffi::X509V3_EXT_nconf(conf, context, name, value))
.map(|p| X509Extension::from_ptr(p))
} }
} }
@ -789,7 +790,8 @@ impl X509Extension {
let name = name.as_raw(); let name = name.as_raw();
let value = value.as_ptr() as *mut _; let value = value.as_ptr() as *mut _;
cvt_p(ffi::X509V3_EXT_nconf_nid(conf, context, name, value)).map(X509Extension) cvt_p(ffi::X509V3_EXT_nconf_nid(conf, context, name, value))
.map(|p| X509Extension::from_ptr(p))
} }
} }
} }
@ -802,7 +804,7 @@ impl X509NameBuilder {
pub fn new() -> Result<X509NameBuilder, ErrorStack> { pub fn new() -> Result<X509NameBuilder, ErrorStack> {
unsafe { unsafe {
ffi::init(); ffi::init();
cvt_p(ffi::X509_NAME_new()).map(|p| X509NameBuilder(X509Name(p))) cvt_p(ffi::X509_NAME_new()).map(|p| X509NameBuilder(X509Name::from_ptr(p)))
} }
} }
@ -1003,7 +1005,7 @@ impl X509ReqBuilder {
pub fn new() -> Result<X509ReqBuilder, ErrorStack> { pub fn new() -> Result<X509ReqBuilder, ErrorStack> {
unsafe { unsafe {
ffi::init(); ffi::init();
cvt_p(ffi::X509_REQ_new()).map(|p| X509ReqBuilder(X509Req(p))) cvt_p(ffi::X509_REQ_new()).map(|p| X509ReqBuilder(X509Req::from_ptr(p)))
} }
} }

View File

@ -35,7 +35,7 @@
//! ``` //! ```
use crate::ffi; use crate::ffi;
use foreign_types::ForeignTypeRef; use foreign_types::{ForeignType, ForeignTypeRef};
use std::mem; use std::mem;
use crate::error::ErrorStack; use crate::error::ErrorStack;
@ -61,7 +61,7 @@ impl X509StoreBuilder {
unsafe { unsafe {
ffi::init(); ffi::init();
cvt_p(ffi::X509_STORE_new()).map(X509StoreBuilder) cvt_p(ffi::X509_STORE_new()).map(|p| X509StoreBuilder::from_ptr(p))
} }
} }