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::cast_possible_wrap,
62    clippy::default_trait_access,
63    clippy::missing_safety_doc,
64    clippy::must_use_candidate,
65    clippy::not_unsafe_ptr_arg_deref,
66    clippy::ptr_as_ptr,
67    clippy::ptr_offset_with_cast,
68    clippy::pub_underscore_fields,
69    clippy::semicolon_if_nothing_returned,
70    clippy::too_many_lines,
71    clippy::unreadable_literal,
72    clippy::used_underscore_binding,
73    clippy::useless_transmute,
74    dead_code,
75    improper_ctypes,
76    non_camel_case_types,
77    non_snake_case,
78    non_upper_case_globals,
79    unpredictable_function_pointer_comparisons,
80    unused_imports
81)]
82mod generated {
83    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
84}
85#[cfg(use_bindgen_generated)]
86pub use generated::*;
87
88#[allow(non_snake_case)]
89#[must_use]
90pub fn ERR_GET_LIB(packed_error: u32) -> i32 {
91    unsafe { ERR_GET_LIB_RUST(packed_error) }
92}
93
94#[allow(non_snake_case)]
95#[must_use]
96pub fn ERR_GET_REASON(packed_error: u32) -> i32 {
97    unsafe { ERR_GET_REASON_RUST(packed_error) }
98}
99
100#[allow(non_snake_case)]
101#[must_use]
102pub fn ERR_GET_FUNC(packed_error: u32) -> i32 {
103    unsafe { ERR_GET_FUNC_RUST(packed_error) }
104}
105
106#[allow(non_snake_case)]
107#[must_use]
108pub fn CFG_CPU_JITTER_ENTROPY() -> bool {
109    cfg!(cpu_jitter_entropy)
110}
111
112#[allow(non_snake_case, clippy::not_unsafe_ptr_arg_deref)]
113pub fn BIO_get_mem_data(b: *mut BIO, pp: *mut *mut c_char) -> c_long {
114    unsafe { BIO_ctrl(b, BIO_CTRL_INFO, 0, pp.cast::<c_void>()) }
115}
116
117pub fn init() {
118    unsafe { CRYPTO_library_init() }
119}