trillium_rustls/
crypto_provider.rs1use futures_rustls::rustls::crypto::CryptoProvider;
2use std::sync::Arc;
3
4#[cfg(feature = "aws-lc-rs")]
5pub(crate) fn crypto_provider() -> Arc<CryptoProvider> {
6 #[cfg(any(feature = "ring", feature = "custom-crypto-provider"))]
7 log::error!("multiple crypto provider features enabled, choosing aws-lc-rs");
8
9 futures_rustls::rustls::crypto::aws_lc_rs::default_provider().into()
10}
11
12#[cfg(all(not(feature = "aws-lc-rs"), feature = "ring"))]
13pub(crate) fn crypto_provider() -> Arc<CryptoProvider> {
14 #[cfg(feature = "custom-crypto-provider")]
15 log::error!("multiple crypto provider features enabled, choosing ring");
16 futures_rustls::rustls::crypto::ring::default_provider().into()
17}
18
19#[cfg(all(
20 not(any(feature = "aws-lc-rs", feature = "ring")),
21 feature = "custom-crypto-provider"
22))]
23pub(crate) fn crypto_provider() -> Arc<CryptoProvider> {
24 CryptoProvider::get_default()
25 .expect(concat!(
26 "`custom-crypto-provider` feature was enabled, but no default crypto ",
27 "provider was found. Either configure a ClientConfig::builder_with_provider and pass",
28 "it to `trillium_rustls::RustlsConfig::new` or use `CryptoProvider::install_default`."
29 ))
30 .clone()
31}
32
33#[cfg(not(any(
34 feature = "ring",
35 feature = "aws-lc-rs",
36 feature = "custom-crypto-provider"
37)))]
38pub(crate) fn crypto_provider() -> Arc<CryptoProvider> {
39 compile_error!(
40 "\n\n`trillium-rustls` cannot compile without a crypto provider feature enabled.
41Please enable `ring`, `aws-lc-rs`, or `custom-crypto-provider`.
42
43To use ring or aws-lc-rs, nothing further is needed than enabling the feature.
44To use `custom-crypto-provider`, either configure a `ClientConfig::builder_with_provider` \
45and pass it to `trillium_rustls::RustlsConfig::new` or use \
46`CryptoProvider::install_default` before building the trillium_rustls::RustlsConfig::default().\n\n"
47 )
48}