Skip to main content

agentmux_common/
tls_provider.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The TLS crypto provider every reqwest client needs.
5//!
6//! reqwest 0.13 is built with `rustls-no-provider` so the tree keeps ring (no aws-lc build), and
7//! it refuses to build a client, even one for plain http, until a provider is installed for the
8//! process. Call [`install_ring_provider`] first thing in each binary that builds a client, and
9//! once in each test binary that does.
10
11use std::sync::Once;
12
13/// Installs ring as the process-wide rustls provider. Safe to call more than once, and a provider
14/// installed earlier by anything else is left alone.
15pub fn install_ring_provider() {
16    static ONCE: Once = Once::new();
17    ONCE.call_once(|| {
18        let _ = rustls::crypto::ring::default_provider().install_default();
19    });
20}
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25
26    #[test]
27    fn installing_twice_leaves_ring_as_the_default() {
28        install_ring_provider();
29        install_ring_provider();
30        assert!(rustls::crypto::CryptoProvider::get_default().is_some());
31    }
32}