Skip to main content

variant_ssl_sys/
lib.rs

1#![allow(
2    clippy::missing_safety_doc,
3    dead_code,
4    non_camel_case_types,
5    non_snake_case,
6    non_upper_case_globals,
7    unused_imports
8)]
9#![doc(html_root_url = "https://docs.rs/variant-ssl-sys/0.15")]
10#![recursion_limit = "128"] // configure fixed limit across all rust versions
11
12extern crate libc;
13pub use libc::c_int;
14
15#[cfg(feature = "boringssl")]
16extern crate bssl_sys;
17#[cfg(feature = "boringssl")]
18pub use bssl_sys::*;
19
20#[cfg(feature = "aws-lc")]
21extern crate aws_lc_sys;
22
23#[cfg(awslc)]
24#[path = "."]
25#[allow(unpredictable_function_pointer_comparisons)]
26mod aws_lc {
27    #[cfg(all(feature = "aws-lc", not(feature = "aws-lc-fips")))]
28    pub use aws_lc_sys::*;
29
30    #[cfg(feature = "aws-lc-fips")]
31    pub use aws_lc_fips_sys::*;
32
33    #[cfg(not(any(feature = "aws-lc", feature = "aws-lc-fips")))]
34    include!(concat!(env!("OUT_DIR"), "/bindgen.rs"));
35
36    use libc::{c_char, c_long, c_void};
37
38    pub fn init() {
39        unsafe { CRYPTO_library_init() }
40    }
41
42    // BIO_get_mem_data is a C preprocessor macro by definition
43    #[allow(non_snake_case, clippy::not_unsafe_ptr_arg_deref)]
44    pub fn BIO_get_mem_data(b: *mut BIO, pp: *mut *mut c_char) -> c_long {
45        unsafe { BIO_ctrl(b, BIO_CTRL_INFO, 0, pp.cast::<c_void>()) }
46    }
47
48    // ERR_GET_{LIB,REASON,FUNC} are macros/static inlines in AWS-LC and
49    // therefore not emitted by pregenerated bindings. We provide pure-Rust
50    // implementations matching the logic in aws-lc-sys.
51    //
52    // When aws-lc-sys is used (feature = "aws-lc" or "aws-lc-fips"), these
53    // come from the glob import instead. When normal bindgen runs
54    // (wrap_static_fns), they're in the generated output.
55    #[cfg(awslc_pregenerated)]
56    #[allow(non_snake_case, clippy::cast_possible_wrap)]
57    pub fn ERR_GET_LIB(packed_error: ::libc::c_uint) -> ::libc::c_int {
58        ((packed_error >> 24) & 0xFF) as ::libc::c_int
59    }
60
61    #[cfg(awslc_pregenerated)]
62    #[allow(non_snake_case, clippy::cast_possible_wrap)]
63    pub fn ERR_GET_REASON(packed_error: ::libc::c_uint) -> ::libc::c_int {
64        (packed_error & 0xFFF) as ::libc::c_int
65    }
66
67    #[cfg(awslc_pregenerated)]
68    #[allow(non_snake_case)]
69    pub fn ERR_GET_FUNC(_packed_error: ::libc::c_uint) -> ::libc::c_int {
70        0
71    }
72}
73#[cfg(awslc)]
74pub use aws_lc::*;
75
76#[cfg(openssl)]
77#[path = "."]
78mod openssl {
79    use libc::*;
80
81    #[cfg(feature = "bindgen")]
82    include!(concat!(env!("OUT_DIR"), "/bindgen.rs"));
83
84    pub use self::aes::*;
85    pub use self::asn1::*;
86    pub use self::bio::*;
87    pub use self::bn::*;
88    pub use self::cms::*;
89    #[cfg(ossl300)]
90    pub use self::core_dispatch::*;
91    pub use self::crypto::*;
92    pub use self::dh::*;
93    pub use self::dsa::*;
94    pub use self::dtls1::*;
95    pub use self::ec::*;
96    pub use self::err::*;
97    pub use self::evp::*;
98    #[cfg(not(feature = "bindgen"))]
99    pub use self::handwritten::*;
100    #[cfg(tongsuo)]
101    pub use self::ntls::*;
102    pub use self::obj_mac::*;
103    pub use self::ocsp::*;
104    pub use self::pem::*;
105    pub use self::pkcs7::*;
106    pub use self::rsa::*;
107    pub use self::sha::*;
108    pub use self::srtp::*;
109    pub use self::ssl::*;
110    pub use self::ssl3::*;
111    pub use self::tls1::*;
112    pub use self::types::*;
113    pub use self::x509::*;
114    pub use self::x509_vfy::*;
115    pub use self::x509v3::*;
116
117    #[macro_use]
118    mod macros;
119
120    mod aes;
121    mod asn1;
122    mod bio;
123    mod bn;
124    mod cms;
125    #[cfg(ossl300)]
126    mod core_dispatch;
127    mod crypto;
128    mod dh;
129    mod dsa;
130    mod dtls1;
131    mod ec;
132    mod err;
133    mod evp;
134    #[cfg(not(feature = "bindgen"))]
135    mod handwritten;
136    #[cfg(tongsuo)]
137    mod ntls;
138    mod obj_mac;
139    mod ocsp;
140    mod pem;
141    mod pkcs7;
142    mod rsa;
143    mod sha;
144    mod srtp;
145    mod ssl;
146    mod ssl3;
147    mod tls1;
148    mod types;
149    mod x509;
150    mod x509_vfy;
151    mod x509v3;
152
153    use std::sync::Once;
154    // explicitly initialize to work around https://github.com/openssl/openssl/issues/3505
155    static INIT: Once = Once::new();
156
157    // FIXME remove
158    pub type PasswordCallback = unsafe extern "C" fn(
159        buf: *mut c_char,
160        size: c_int,
161        rwflag: c_int,
162        user_data: *mut c_void,
163    ) -> c_int;
164
165    #[cfg(ossl110)]
166    pub fn init() {
167        use std::ptr;
168
169        #[cfg(not(ossl111b))]
170        let init_options = OPENSSL_INIT_LOAD_SSL_STRINGS;
171        #[cfg(ossl111b)]
172        let init_options = OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_NO_ATEXIT;
173
174        INIT.call_once(|| unsafe {
175            OPENSSL_init_ssl(init_options, ptr::null_mut());
176        })
177    }
178
179    #[cfg(libressl)]
180    pub fn init() {}
181
182    /// Disable explicit initialization of the openssl libs.
183    ///
184    /// This is only appropriate to use if the openssl crate is being consumed by an application
185    /// that will be performing the initialization explicitly.
186    ///
187    /// # Safety
188    ///
189    /// In some versions of openssl, skipping initialization will fall back to the default procedure
190    /// while other will cause difficult to debug errors so care must be taken when calling this.
191    pub unsafe fn assume_init() {
192        INIT.call_once(|| {});
193    }
194}
195#[cfg(openssl)]
196pub use openssl::*;