diff --git a/openssl/src/asn1.rs b/openssl/src/asn1.rs index 27913aa6f24a023c19dc86c8640493bfd4e54054..d129235ae633dad11fe990b6359de76ead0b6fc9 100644 --- a/openssl/src/asn1.rs +++ b/openssl/src/asn1.rs @@ -38,7 +38,7 @@ use error::ErrorStack; use nid::Nid; use string::OpensslString; -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::ASN1_GENERALIZEDTIME; fn drop = ffi::ASN1_GENERALIZEDTIME_free; @@ -73,7 +73,7 @@ impl fmt::Display for Asn1GeneralizedTimeRef { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::ASN1_TIME; fn drop = ffi::ASN1_TIME_free; /// Time storage and comparison @@ -119,7 +119,7 @@ impl Asn1Time { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::ASN1_STRING; fn drop = ffi::ASN1_STRING_free; /// Primary ASN.1 type used by OpenSSL @@ -170,7 +170,7 @@ impl Asn1StringRef { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::ASN1_INTEGER; fn drop = ffi::ASN1_INTEGER_free; @@ -211,7 +211,7 @@ impl Asn1IntegerRef { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::ASN1_BIT_STRING; fn drop = ffi::ASN1_BIT_STRING_free; /// Sequence of bytes @@ -238,7 +238,7 @@ impl Asn1BitStringRef { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::ASN1_OBJECT; fn drop = ffi::ASN1_OBJECT_free; diff --git a/openssl/src/bn.rs b/openssl/src/bn.rs index 7743228b9b13e232c7f23a52bac0d15e38a71987..fc6e0bb852272bc575664f28bfc7769d12dbb507 100644 --- a/openssl/src/bn.rs +++ b/openssl/src/bn.rs @@ -67,7 +67,7 @@ pub const MSB_ONE: MsbOption = MsbOption(0); /// of bits in the original numbers. pub const TWO_MSB_ONE: MsbOption = MsbOption(1); -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::BN_CTX; fn drop = ffi::BN_CTX_free; @@ -99,7 +99,7 @@ impl BigNumContext { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::BIGNUM; fn drop = ffi::BN_free; diff --git a/openssl/src/cms.rs b/openssl/src/cms.rs index 59866df1fba8f5638be96c84f5d620d9ccbe88e0..160d2daf355279080e0b861bae01af7af7fa8417 100644 --- a/openssl/src/cms.rs +++ b/openssl/src/cms.rs @@ -18,7 +18,7 @@ use pkey::PKeyRef; use cvt; use cvt_p; -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::CMS_ContentInfo; fn drop = ffi::CMS_ContentInfo_free; diff --git a/openssl/src/conf.rs b/openssl/src/conf.rs index 56654ecbcc9bcc7b5506ebac23f44a4498516eaf..fb5d4f3c0570306598ec549b16a8ed545cad609a 100644 --- a/openssl/src/conf.rs +++ b/openssl/src/conf.rs @@ -28,7 +28,7 @@ impl ConfMethod { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::CONF; fn drop = ffi::NCONF_free; diff --git a/openssl/src/dh.rs b/openssl/src/dh.rs index 2d6583a20b8a9c6c7633e7f85eb3ae7ac9ccc7bc..50d9da7b2fca3af71e26e551f681e736e13d4a8d 100644 --- a/openssl/src/dh.rs +++ b/openssl/src/dh.rs @@ -7,7 +7,7 @@ use std::ptr; use {cvt, cvt_p}; use bn::BigNum; -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::DH; fn drop = ffi::DH_free; diff --git a/openssl/src/dsa.rs b/openssl/src/dsa.rs index aaada1291dd1479d68be39b010d209bb2c268ade..c687531e9309003d2744433aea8fe0f041510871 100644 --- a/openssl/src/dsa.rs +++ b/openssl/src/dsa.rs @@ -17,7 +17,7 @@ use bn::BigNumRef; use error::ErrorStack; use util::{CallbackState, invoke_passwd_cb_old}; -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::DSA; fn drop = ffi::DSA_free; diff --git a/openssl/src/ec.rs b/openssl/src/ec.rs index ddf8c0290c7bc3f860ccea84a856e8997264ed2e..97b095d093bb645fd6700e7b4991795830709507 100644 --- a/openssl/src/ec.rs +++ b/openssl/src/ec.rs @@ -98,7 +98,7 @@ pub struct PointConversionForm(ffi::point_conversion_form_t); #[derive(Copy, Clone)] pub struct Asn1Flag(c_int); -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::EC_GROUP; fn drop = ffi::EC_GROUP_free; @@ -233,7 +233,7 @@ impl EcGroupRef { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::EC_POINT; fn drop = ffi::EC_POINT_free; @@ -498,7 +498,7 @@ impl EcPoint { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::EC_KEY; fn drop = ffi::EC_KEY_free; @@ -646,7 +646,7 @@ impl EcKey { } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::EC_KEY; fn drop = ffi::EC_KEY_free; diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index a6b7885c890e37fe2b92076f764fad06f56ff3ff..5c3e7cc884e7b22939bd1f3abde23391dcdfb3df 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -27,6 +27,7 @@ use error::ErrorStack; mod macros; mod bio; +#[macro_use] mod util; pub mod aes; pub mod asn1; diff --git a/openssl/src/macros.rs b/openssl/src/macros.rs index b2fe0c18a9e4715ae906b13fb934f5279c7de485..721f4b0c44f51624ce2426e98d4a12f1c22836bb 100644 --- a/openssl/src/macros.rs +++ b/openssl/src/macros.rs @@ -214,3 +214,35 @@ macro_rules! from_pem { from_pem, $t, $f); } } + + +macro_rules! foreign_type_and_impl_send_sync { + ( + $(#[$impl_attr:meta])* + type CType = $ctype:ty; + fn drop = $drop:expr; + $(fn clone = $clone:expr;)* + + $(#[$owned_attr:meta])* + pub struct $owned:ident; + $(#[$borrowed_attr:meta])* + pub struct $borrowed:ident; + ) + => { + foreign_type! { + $(#[$impl_attr])* + type CType = $ctype; + fn drop = $drop; + $(fn clone = $clone;)* + $(#[$owned_attr])* + pub struct $owned; + $(#[$borrowed_attr])* + pub struct $borrowed; + } + + unsafe impl Send for $owned{} + unsafe impl Send for $borrowed{} + unsafe impl Sync for $owned{} + unsafe impl Sync for $borrowed{} + }; +} diff --git a/openssl/src/ocsp.rs b/openssl/src/ocsp.rs index 1968bcf6d3b8fc502416cac5125accf0864207ab..65436a4c4081a98c96cd255625a9fb12eb43d396 100644 --- a/openssl/src/ocsp.rs +++ b/openssl/src/ocsp.rs @@ -136,7 +136,7 @@ impl<'a> Status<'a> { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::OCSP_BASICRESP; fn drop = ffi::OCSP_BASICRESP_free; @@ -203,7 +203,7 @@ impl OcspBasicResponseRef { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::OCSP_CERTID; fn drop = ffi::OCSP_CERTID_free; @@ -228,7 +228,7 @@ impl OcspCertId { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::OCSP_RESPONSE; fn drop = ffi::OCSP_RESPONSE_free; @@ -273,7 +273,7 @@ impl OcspResponseRef { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::OCSP_REQUEST; fn drop = ffi::OCSP_REQUEST_free; @@ -305,7 +305,7 @@ impl OcspRequestRef { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::OCSP_ONEREQ; fn drop = ffi::OCSP_ONEREQ_free; diff --git a/openssl/src/pkcs12.rs b/openssl/src/pkcs12.rs index 6e42f73be9e20ddfdda36651df8577edc87adcf6..86111280c6180066d459b3462e4609eeab9a6f44 100644 --- a/openssl/src/pkcs12.rs +++ b/openssl/src/pkcs12.rs @@ -13,7 +13,7 @@ use x509::X509; use stack::Stack; use nid; -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::PKCS12; fn drop = ffi::PKCS12_free; diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index f4e36892c7822c865092316db07133a4b491839d..9ef7e8854a35077e8c08c009f35b011029ef3e9a 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -14,7 +14,7 @@ use rsa::{Rsa, Padding}; use error::ErrorStack; use util::{CallbackState, invoke_passwd_cb, invoke_passwd_cb_old}; -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::EVP_PKEY; fn drop = ffi::EVP_PKEY_free; @@ -75,9 +75,6 @@ impl PKeyRef { } } -unsafe impl Send for PKey {} -unsafe impl Sync for PKey {} - impl PKey { /// Creates a new `PKey` containing an RSA key. pub fn from_rsa(rsa: Rsa) -> Result { @@ -226,7 +223,7 @@ impl PKey { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::EVP_PKEY_CTX; fn drop = ffi::EVP_PKEY_CTX_free; @@ -234,9 +231,6 @@ foreign_type! { pub struct PKeyCtxRef; } -unsafe impl Send for PKeyCtx {} -unsafe impl Sync for PKeyCtx {} - impl PKeyCtx { pub fn from_pkey(pkey: &PKeyRef) -> Result { unsafe { diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index d3d118eddce7ac639488a0ef434a306faa99fbcc..3f4e80147540c749446dc5552edf9400518ad345 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -29,7 +29,7 @@ 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); -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::RSA; fn drop = ffi::RSA_free; diff --git a/openssl/src/string.rs b/openssl/src/string.rs index 0324d57760a7052df1eb95ba2f24b2ec1770ec6f..af58130e048038cb02b9543ee54948f856b8f200 100644 --- a/openssl/src/string.rs +++ b/openssl/src/string.rs @@ -8,7 +8,7 @@ use std::str; use stack::Stackable; -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = c_char; fn drop = free; diff --git a/openssl/src/verify.rs b/openssl/src/verify.rs index 7b2fa612e8068ac64ac26a26ee93964c43e58877..65315e473ae76c601d452b041e053f1e8161ba31 100644 --- a/openssl/src/verify.rs +++ b/openssl/src/verify.rs @@ -20,7 +20,7 @@ bitflags! { } } -foreign_type! { +foreign_type_and_impl_send_sync! { type CType = ffi::X509_VERIFY_PARAM; fn drop = ffi::X509_VERIFY_PARAM_free;