Skip to main content

rtc_crypto/
provider.rs

1use std::sync::Arc;
2
3use crate::{CryptoError, RTCCryptoProvider};
4
5/// Constructs the built-in default provider.
6///
7/// Ring remains the default whenever its feature is enabled. AWS-LC-RS is selected only when it is
8/// the sole built-in. With no built-in features this returns [`CryptoError::NoDefaultProvider`].
9pub fn default_provider() -> Result<Arc<dyn RTCCryptoProvider>, CryptoError> {
10    #[cfg(feature = "crypto-ring")]
11    {
12        Ok(Arc::new(crate::providers::RingProvider::new()))
13    }
14
15    #[cfg(all(not(feature = "crypto-ring"), feature = "crypto-aws-lc-rs"))]
16    {
17        Ok(Arc::new(crate::providers::AwsLcRsProvider::new()))
18    }
19
20    #[cfg(not(any(feature = "crypto-ring", feature = "crypto-aws-lc-rs")))]
21    {
22        Err(CryptoError::NoDefaultProvider)
23    }
24}