aws_lc_fips_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_apple_darwin,
28    aarch64_apple_darwin_crypto,
29    aarch64_apple_darwin_crypto_ssl
30);
31platform_binding!(
32    aarch64_unknown_linux_gnu,
33    aarch64_unknown_linux_gnu_crypto,
34    aarch64_unknown_linux_gnu_crypto_ssl
35);
36platform_binding!(
37    aarch64_unknown_linux_musl,
38    aarch64_unknown_linux_musl_crypto,
39    aarch64_unknown_linux_musl_crypto_ssl
40);
41platform_binding!(
42    x86_64_apple_darwin,
43    x86_64_apple_darwin_crypto,
44    x86_64_apple_darwin_crypto_ssl
45);
46platform_binding!(
47    x86_64_unknown_linux_gnu,
48    x86_64_unknown_linux_gnu_crypto,
49    x86_64_unknown_linux_gnu_crypto_ssl
50);
51platform_binding!(
52    x86_64_unknown_linux_musl,
53    x86_64_unknown_linux_musl_crypto,
54    x86_64_unknown_linux_musl_crypto_ssl
55);
56
57#[cfg(use_bindgen_generated)]
58#[allow(
59    clippy::cast_lossless,
60    clippy::cast_possible_truncation,
61    clippy::default_trait_access,
62    clippy::must_use_candidate,
63    clippy::not_unsafe_ptr_arg_deref,
64    clippy::ptr_as_ptr,
65    clippy::pub_underscore_fields,
66    clippy::semicolon_if_nothing_returned,
67    clippy::too_many_lines,
68    clippy::unreadable_literal,
69    clippy::used_underscore_binding,
70    clippy::useless_transmute,
71    dead_code,
72    improper_ctypes,
73    non_camel_case_types,
74    non_snake_case,
75    non_upper_case_globals,
76    unused_imports
77)]
78mod generated {
79    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
80}
81#[cfg(use_bindgen_generated)]
82pub use generated::*;
83
84#[allow(non_snake_case)]
85#[must_use]
86pub fn ERR_GET_LIB(packed_error: u32) -> i32 {
87    unsafe { ERR_GET_LIB_RUST(packed_error) }
88}
89
90#[allow(non_snake_case)]
91#[must_use]
92pub fn ERR_GET_REASON(packed_error: u32) -> i32 {
93    unsafe { ERR_GET_REASON_RUST(packed_error) }
94}
95
96#[allow(non_snake_case)]
97#[must_use]
98pub fn ERR_GET_FUNC(packed_error: u32) -> i32 {
99    unsafe { ERR_GET_FUNC_RUST(packed_error) }
100}
101
102#[allow(non_snake_case)]
103#[must_use]
104pub fn CFG_CPU_JITTER_ENTROPY() -> bool {
105    cfg!(cpu_jitter_entropy)
106}
107
108#[allow(non_snake_case, clippy::not_unsafe_ptr_arg_deref)]
109pub fn BIO_get_mem_data(b: *mut BIO, pp: *mut *mut c_char) -> c_long {
110    unsafe { BIO_ctrl(b, BIO_CTRL_INFO, 0, pp.cast::<c_void>()) }
111}
112
113pub fn init() {
114    unsafe { CRYPTO_library_init() }
115}