xmtp_cryptography/lib.rs
1pub mod post_quantum;
2pub use post_quantum::{GeneratePostQuantumKeyError, generate_post_quantum_key};
3pub mod basic_credential;
4pub mod configuration;
5pub mod ethereum;
6pub mod hash;
7pub mod rand;
8pub mod signature;
9pub mod utils;
10
11pub use basic_credential::*;
12pub use openmls;
13
14pub type Secret = tls_codec::SecretVLBytes; // Byte array with ZeroizeOnDrop
15
16// When upgrading to reqwest 0.13 and disabling the default aws-lc-rs crypto provider
17// some tests fail without initializing the ring crypto provider. Doing this here because
18// it is crypto related and all crates depend on this crate.
19//
20// Installs the process-default rustls crypto provider. Idempotent: subsequent calls are
21// cheap no-ops via `Once`, and `install_default` returning `Err` (provider already set) is
22// ignored, so it is safe to call even when a host process pre-installs its own provider.
23//
24// This is exposed publicly and must be called explicitly from binding entry points because
25// the `#[ctor::ctor(unsafe)]` below does not run on Apple platforms: `ctor` relies on the
26// `__DATA,__mod_init_func` Mach-O link section, which Apple no longer supports. When
27// `libxmtpv3.a` is statically linked into a Swift binary the constructor record is orphaned
28// and never fires, leaving the provider uninstalled and causing `reqwest` (rustls-no-provider)
29// to `panic!("No provider set")` on the first HTTP client build. See issue #3846.
30#[cfg(not(target_arch = "wasm32"))]
31pub fn install_crypto_provider() {
32 use std::sync::Once;
33 static INSTALL: Once = Once::new();
34 INSTALL.call_once(|| {
35 let _ = rustls::crypto::ring::default_provider().install_default();
36 });
37}
38
39#[cfg(not(target_arch = "wasm32"))]
40#[ctor::ctor(unsafe)]
41fn install_rustls_crypto_provider() {
42 install_crypto_provider();
43}