From a6fcef01c0aa71359f583342c813b8db5835178d Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 20 May 2018 11:27:45 -0700 Subject: Overhaul openssl cfgs Also expose hostname verification on libressl --- openssl/src/stack.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'openssl/src/stack.rs') diff --git a/openssl/src/stack.rs b/openssl/src/stack.rs index d8589352..4d5c0a13 100644 --- a/openssl/src/stack.rs +++ b/openssl/src/stack.rs @@ -1,23 +1,30 @@ -use foreign_types::{ForeignTypeRef, ForeignType, Opaque}; +use ffi; +use foreign_types::{ForeignType, ForeignTypeRef, Opaque}; use libc::c_int; use std::borrow::Borrow; use std::convert::AsRef; use std::iter; use std::marker::PhantomData; use std::mem; -use ffi; -use {cvt, cvt_p}; use error::ErrorStack; use std::ops::{Deref, DerefMut, Index, IndexMut}; +use {cvt, cvt_p}; -#[cfg(ossl10x)] -use ffi::{sk_pop as OPENSSL_sk_pop, sk_free as OPENSSL_sk_free, sk_num as OPENSSL_sk_num, - sk_value as OPENSSL_sk_value, _STACK as OPENSSL_STACK, - sk_new_null as OPENSSL_sk_new_null, sk_push as OPENSSL_sk_push}; -#[cfg(ossl110)] -use ffi::{OPENSSL_sk_pop, OPENSSL_sk_free, OPENSSL_sk_num, OPENSSL_sk_value, OPENSSL_STACK, - OPENSSL_sk_new_null, OPENSSL_sk_push}; +cfg_if! { + if #[cfg(ossl110)] { + use ffi::{ + OPENSSL_sk_pop, OPENSSL_sk_free, OPENSSL_sk_num, OPENSSL_sk_value, OPENSSL_STACK, + OPENSSL_sk_new_null, OPENSSL_sk_push, + }; + } else { + use ffi::{ + sk_pop as OPENSSL_sk_pop, sk_free as OPENSSL_sk_free, sk_num as OPENSSL_sk_num, + sk_value as OPENSSL_sk_value, _STACK as OPENSSL_STACK, + sk_new_null as OPENSSL_sk_new_null, sk_push as OPENSSL_sk_push, + }; + } +} /// Trait implemented by types which can be placed in a stack. /// @@ -87,7 +94,7 @@ impl ForeignType for Stack { assert!( !ptr.is_null(), "Must not instantiate a Stack from a null-ptr - use Stack::new() in \ - that case" + that case" ); Stack(ptr) } @@ -218,9 +225,7 @@ impl StackRef { /// Pushes a value onto the top of the stack. pub fn push(&mut self, data: T) -> Result<(), ErrorStack> { unsafe { - cvt( - OPENSSL_sk_push(self.as_stack(), data.as_ptr() as *mut _), - )?; + cvt(OPENSSL_sk_push(self.as_stack(), data.as_ptr() as *mut _))?; mem::forget(data); Ok(()) } -- cgit v1.2.3 From 3ab1cc7a8f259ecc858bbc6fe28d9611802d0591 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 20 May 2018 15:24:38 -0700 Subject: Make Stack Sync + Send --- openssl/src/stack.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'openssl/src/stack.rs') diff --git a/openssl/src/stack.rs b/openssl/src/stack.rs index 4d5c0a13..ac1e2a13 100644 --- a/openssl/src/stack.rs +++ b/openssl/src/stack.rs @@ -40,15 +40,8 @@ pub trait Stackable: ForeignType { /// An owned stack of `T`. pub struct Stack(*mut T::StackType); -impl Stack { - pub fn new() -> Result, ErrorStack> { - unsafe { - ffi::init(); - let ptr = cvt_p(OPENSSL_sk_new_null())?; - Ok(Stack(ptr as *mut _)) - } - } -} +unsafe impl Send for Stack {} +unsafe impl Sync for Stack {} impl Drop for Stack { fn drop(&mut self) { @@ -59,6 +52,16 @@ impl Drop for Stack { } } +impl Stack { + pub fn new() -> Result, ErrorStack> { + unsafe { + ffi::init(); + let ptr = cvt_p(OPENSSL_sk_new_null())?; + Ok(Stack(ptr as *mut _)) + } + } +} + impl iter::IntoIterator for Stack { type IntoIter = IntoIter; type Item = T; @@ -164,6 +167,9 @@ impl ExactSizeIterator for IntoIter {} pub struct StackRef(Opaque, PhantomData); +unsafe impl Send for StackRef {} +unsafe impl Sync for StackRef {} + impl ForeignTypeRef for StackRef { type CType = T::StackType; } -- cgit v1.2.3