use axum_server::tls_rustls::RustlsConfig;
use crate::errors::OrionError;
fn ensure_crypto_provider() {
if rustls::crypto::CryptoProvider::get_default().is_none() {
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
}
}
pub async fn load_rustls_config(
cert_path: &str,
key_path: &str,
) -> Result<RustlsConfig, OrionError> {
ensure_crypto_provider();
RustlsConfig::from_pem_file(cert_path, key_path)
.await
.map_err(|e| OrionError::Internal {
context: format!(
"Failed to initialize TLS from cert='{cert_path}' key='{key_path}'. \
Verify that both are valid PEM-encoded files."
),
source: Some(Box::new(e)),
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn installs_a_process_level_crypto_provider() {
ensure_crypto_provider();
assert!(
rustls::crypto::CryptoProvider::get_default().is_some(),
"rustls cannot pick a provider from features alone in this tree"
);
}
}