1#![allow(
2 clippy::missing_safety_doc,
3 clippy::redundant_static_lifetimes,
4 clippy::too_many_arguments,
5 clippy::unreadable_literal,
6 clippy::upper_case_acronyms,
7 improper_ctypes,
8 non_camel_case_types,
9 non_snake_case,
10 non_upper_case_globals,
11 unused_imports
12)]
13#![cfg_attr(docsrs, feature(doc_auto_cfg))]
14
15use std::convert::TryInto;
16use std::ffi::c_void;
17use std::os::raw::{c_char, c_int, c_uint, c_ulong};
18
19#[allow(dead_code)]
20#[allow(clippy::all)]
21#[rustfmt::skip]
22mod generated {
23 include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
24}
25pub use generated::*;
26
27#[cfg(target_pointer_width = "64")]
28pub type BN_ULONG = u64;
29#[cfg(target_pointer_width = "32")]
30pub type BN_ULONG = u32;
31
32pub const fn ERR_PACK(l: c_int, f: c_int, r: c_int) -> c_ulong {
33 ((l as c_ulong & 0x0FF) << 24) | ((f as c_ulong & 0xFFF) << 12) | (r as c_ulong & 0xFFF)
34}
35
36pub const fn ERR_GET_LIB(l: c_uint) -> c_int {
37 ((l >> 24) & 0x0FF) as c_int
38}
39
40pub const fn ERR_GET_FUNC(l: c_uint) -> c_int {
41 ((l >> 12) & 0xFFF) as c_int
42}
43
44pub const fn ERR_GET_REASON(l: c_uint) -> c_int {
45 (l & 0xFFF) as c_int
46}
47
48pub fn init() {
49 use std::ptr;
50 use std::sync::Once;
51
52 static INIT: Once = Once::new();
54
55 let init_options = OPENSSL_INIT_LOAD_SSL_STRINGS;
56
57 INIT.call_once(|| {
58 assert_eq!(
59 unsafe { OPENSSL_init_ssl(init_options.try_into().unwrap(), ptr::null_mut()) },
60 1
61 )
62 });
63}