Debian Codegraph @

third_party/rust/neqo-crypto/src/exp.rs

raw
1 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4 // option. This file may not be copied, modified, or distributed
5 // except according to those terms.
6
7 #[macro_export]
8 macro_rules! experimental_api {
9 ( $n:ident ( $( $a:ident : $t:ty ),* $(,)? ) ) => {
10 #[expect(non_snake_case, reason = "Inherent in macro use.")]
11 #[allow(clippy::allow_attributes, clippy::too_many_arguments, reason = "Inherent in macro use.")]
12 #[allow(clippy::allow_attributes, clippy::missing_safety_doc, reason = "Inherent in macro use.")]
13 #[allow(clippy::allow_attributes, clippy::missing_errors_doc, reason = "Inherent in macro use.")]
14 pub unsafe fn $n ( $( $a : $t ),* ) -> Result<(), $crate::err::Error> {
15 struct ExperimentalAPI(*mut std::ffi::c_void);
16 unsafe impl Send for ExperimentalAPI {}
17 unsafe impl Sync for ExperimentalAPI {}
18 static EXP_API: ::std::sync::OnceLock<ExperimentalAPI> = ::std::sync::OnceLock::new();
19 let f = EXP_API.get_or_init(|| {
20 const EXP_FUNCTION: &str = stringify!($n);
21 let Ok(n) = ::std::ffi::CString::new(EXP_FUNCTION) else { return ExperimentalAPI(std::ptr::null_mut()); };
22 ExperimentalAPI($crate::ssl::SSL_GetExperimentalAPI(n.as_ptr()))
23 });
24 if f.0.is_null() {
25 return Err($crate::err::Error::InternalError);
26 }
27 let f: unsafe extern "C" fn( $( $t ),* ) -> $crate::ssl::SECStatus = ::std::mem::transmute(f.0);
28 let rv = f( $( $a ),* );
29 $crate::err::secstatus_to_res(rv)
30 }
31 };
32 }