aws_lc_sys/
lib.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0 OR ISC
3
4#![cfg_attr(not(clippy), allow(unexpected_cfgs))]
5#![cfg_attr(not(clippy), allow(unknown_lints))]
6
7use std::os::raw::{c_char, c_long, c_void};
8
9#[allow(unused_macros)]
10macro_rules! use_bindings {
11    ($bindings:ident) => {
12        mod $bindings;
13        pub use $bindings::*;
14    };
15}
16
17macro_rules! platform_binding {
18    ($platform:ident, $platform_crypto:ident, $platform_ssl:ident) => {
19        #[cfg(all($platform, not(feature = "ssl"), not(use_bindgen_generated)))]
20        use_bindings!($platform_crypto);
21        #[cfg(all($platform, feature = "ssl", not(use_bindgen_generated)))]
22        use_bindings!($platform_ssl);
23    };
24}
25
26platform_binding!(
27    aarch64_linux_android,
28    aarch64_linux_android_crypto,
29    aarch64_linux_android_crypto_ssl
30);
31platform_binding!(
32    aarch64_apple_darwin,
33    aarch64_apple_darwin_crypto,
34    aarch64_apple_darwin_crypto_ssl
35);
36platform_binding!(
37    aarch64_pc_windows_msvc,
38    aarch64_pc_windows_msvc_crypto,
39    aarch64_pc_windows_msvc_crypto_ssl
40);
41platform_binding!(
42    aarch64_unknown_linux_gnu,
43    aarch64_unknown_linux_gnu_crypto,
44    aarch64_unknown_linux_gnu_crypto_ssl
45);
46platform_binding!(
47    aarch64_unknown_linux_musl,
48    aarch64_unknown_linux_musl_crypto,
49    aarch64_unknown_linux_musl_crypto_ssl
50);
51platform_binding!(
52    i686_pc_windows_msvc,
53    i686_pc_windows_msvc_crypto,
54    i686_pc_windows_msvc_crypto_ssl
55);
56platform_binding!(
57    i686_unknown_linux_gnu,
58    i686_unknown_linux_gnu_crypto,
59    i686_unknown_linux_gnu_crypto_ssl
60);
61platform_binding!(
62    riscv64gc_unknown_linux_gnu,
63    riscv64gc_unknown_linux_gnu_crypto,
64    riscv64gc_unknown_linux_gnu_crypto_ssl
65);
66platform_binding!(
67    x86_64_apple_darwin,
68    x86_64_apple_darwin_crypto,
69    x86_64_apple_darwin_crypto_ssl
70);
71platform_binding!(
72    x86_64_pc_windows_gnu,
73    x86_64_pc_windows_gnu_crypto,
74    x86_64_pc_windows_gnu_crypto_ssl
75);
76platform_binding!(
77    x86_64_pc_windows_msvc,
78    x86_64_pc_windows_msvc_crypto,
79    x86_64_pc_windows_msvc_crypto_ssl
80);
81platform_binding!(
82    x86_64_unknown_linux_gnu,
83    x86_64_unknown_linux_gnu_crypto,
84    x86_64_unknown_linux_gnu_crypto_ssl
85);
86platform_binding!(
87    x86_64_unknown_linux_musl,
88    x86_64_unknown_linux_musl_crypto,
89    x86_64_unknown_linux_musl_crypto_ssl
90);
91
92#[cfg(use_bindgen_generated)]
93#[allow(
94    clippy::cast_lossless,
95    clippy::cast_possible_truncation,
96    clippy::default_trait_access,
97    clippy::must_use_candidate,
98    clippy::not_unsafe_ptr_arg_deref,
99    clippy::ptr_as_ptr,
100    clippy::pub_underscore_fields,
101    clippy::semicolon_if_nothing_returned,
102    clippy::too_many_lines,
103    clippy::unreadable_literal,
104    clippy::used_underscore_binding,
105    clippy::useless_transmute,
106    dead_code,
107    improper_ctypes,
108    non_camel_case_types,
109    non_snake_case,
110    non_upper_case_globals,
111    unused_imports
112)]
113mod generated {
114
115    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
116}
117#[cfg(use_bindgen_generated)]
118pub use generated::*;
119
120#[allow(non_snake_case)]
121#[must_use]
122pub fn ERR_GET_LIB(packed_error: u32) -> i32 {
123    unsafe { ERR_GET_LIB_RUST(packed_error) }
124}
125
126#[allow(non_snake_case)]
127#[must_use]
128pub fn ERR_GET_REASON(packed_error: u32) -> i32 {
129    unsafe { ERR_GET_REASON_RUST(packed_error) }
130}
131
132#[allow(non_snake_case)]
133#[must_use]
134pub fn ERR_GET_FUNC(packed_error: u32) -> i32 {
135    unsafe { ERR_GET_FUNC_RUST(packed_error) }
136}
137
138#[allow(non_snake_case, clippy::not_unsafe_ptr_arg_deref)]
139pub fn BIO_get_mem_data(b: *mut BIO, pp: *mut *mut c_char) -> c_long {
140    unsafe { BIO_ctrl(b, BIO_CTRL_INFO, 0, pp.cast::<c_void>()) }
141}
142
143pub fn init() {
144    unsafe { CRYPTO_library_init() }
145}