Debian Codegraph @

third_party/rust/neqo-crypto/tests/init.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 // This uses external interfaces to neqo_crypto rather than being a module
8 // inside of lib.rs. Because all other code uses the test_fixture module,
9 // they will be calling into the public version of init_db(). Calling into
10 // the version exposed to an inner module in lib.rs would result in calling
11 // a different version of init_db. That causes explosions as they get
12 // different versions of the Once instance they use and they initialize NSS
13 // twice, probably likely in parallel. That doesn't work out well.
14 use neqo_crypto::{assert_initialized, init_db};
15
16 // Pull in the NSS internals so that we can ask NSS if it thinks that
17 // it is properly initialized.
18 #[expect(
19 non_upper_case_globals,
20 dead_code,
21 reason = "Code is bindgen-generated."
22 )]
23 mod nss {
24 include!(concat!(env!("OUT_DIR"), "/nss_init.rs"));
25 }
26
27 #[cfg(nss_nodb)]
28 #[test]
29 fn init_nodb() {
30 neqo_crypto::init().unwrap();
31 assert_initialized();
32 unsafe {
33 assert_ne!(nss::NSS_IsInitialized(), 0);
34 }
35 }
36
37 #[cfg(not(nss_nodb))]
38 #[test]
39 fn init_withdb() {
40 init_db(::test_fixture::NSS_DB_PATH).unwrap();
41 assert_initialized();
42 unsafe {
43 assert_ne!(nss::NSS_IsInitialized(), 0);
44 }
45 }