File
Blob: firmware/vendor/str0m/src/crypto/mod.rs
| 1 | use str0m_proto::crypto as provider; |
| 2 | |
| 3 | pub use provider::{AeadAes128Gcm, AeadAes128GcmCipher, AeadAes256Gcm, AeadAes256GcmCipher}; |
| 4 | pub use provider::{Aes128CmSha1_80, Aes128CmSha1_80Cipher, CryptoProvider, CryptoSafe}; |
| 5 | pub use provider::{Sha1HmacProvider, Sha256Provider}; |
| 6 | pub use provider::{SrtpProvider, SupportedAeadAes128Gcm}; |
| 7 | pub use provider::{SupportedAeadAes256Gcm, SupportedAes128CmSha1_80}; |
| 8 | |
| 9 | /// DTLS related types and traits. |
| 10 | pub mod dtls { |
| 11 | pub use super::provider::dtls::{DtlsInstance, DtlsProvider}; |
| 12 | |
| 13 | pub use dimpl::DtlsCertificate as DtlsCert; |
| 14 | pub use dimpl::KeyingMaterial; |
| 15 | pub use dimpl::ProtocolVersion; |
| 16 | pub use dimpl::SrtpProfile; |
| 17 | // Note: dimpl::Error is renamed to DtlsImplError to avoid conflict with str0m's DtlsError |
| 18 | pub use super::provider::DtlsVersion; |
| 19 | pub use dimpl::{Error as DtlsImplError, Output as DtlsOutput}; |
| 20 | } |
| 21 | |
| 22 | #[cfg(any(test, feature = "_internal_test_exports"))] |
| 23 | #[allow(unused)] |
| 24 | pub(crate) fn test_default_provider() -> &'static CryptoProvider { |
| 25 | use std::sync::OnceLock; |
| 26 | static TEST_PROVIDER: OnceLock<CryptoProvider> = OnceLock::new(); |
| 27 | TEST_PROVIDER.get_or_init(from_feature_flags) |
| 28 | } |
| 29 | |
| 30 | /// Create a crypto provider based on enabled feature flags. |
| 31 | /// |
| 32 | /// Priority order: aws-lc-rs, rust-crypto, openssl, wincrypto (Windows only) |
| 33 | /// |
| 34 | /// Note: For Apple platforms, use the separate `str0m-apple-crypto` crate |
| 35 | /// and call `str0m_apple_crypto::default_provider()` directly. |
| 36 | #[allow(unreachable_code, clippy::needless_return)] |
| 37 | pub fn from_feature_flags() -> CryptoProvider { |
| 38 | #[cfg(feature = "aws-lc-rs")] |
| 39 | return str0m_aws_lc_rs::default_provider(); |
| 40 | |
| 41 | #[cfg(feature = "rust-crypto")] |
| 42 | return str0m_rust_crypto::default_provider(); |
| 43 | |
| 44 | #[cfg(any(feature = "openssl", feature = "openssl-dimpl"))] |
| 45 | return str0m_openssl::default_provider(); |
| 46 | |
| 47 | #[cfg(all(feature = "apple-crypto", target_vendor = "apple"))] |
| 48 | return str0m_apple_crypto::default_provider(); |
| 49 | |
| 50 | #[cfg(all( |
| 51 | any(feature = "wincrypto", feature = "wincrypto-dimpl"), |
| 52 | target_os = "windows" |
| 53 | ))] |
| 54 | return str0m_wincrypto::default_provider(); |
| 55 | |
| 56 | panic!( |
| 57 | "No crypto provider available. Enable one of: aws-lc-rs, |
| 58 | rust-crypto, openssl, openssl-dimpl, wincrypto (Windows only), |
| 59 | wincrypto-dimpl (Windows only) or use str0m-apple-crypto crate" |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | mod finger; |
| 64 | pub use finger::Fingerprint; |
| 65 | |
| 66 | pub use str0m_proto::crypto::{CryptoError, DtlsError}; |