Skip to main content

datasynth_server/
tls.rs

1//! Optional TLS configuration for the REST server.
2//!
3//! Enabled with the `tls` feature flag.
4
5#[cfg(feature = "tls")]
6use std::path::PathBuf;
7
8/// TLS configuration.
9#[cfg(feature = "tls")]
10#[derive(Clone, Debug)]
11pub struct TlsConfig {
12    /// Path to the TLS certificate file (PEM format).
13    pub cert_path: PathBuf,
14    /// Path to the TLS private key file (PEM format).
15    pub key_path: PathBuf,
16}
17
18#[cfg(feature = "tls")]
19impl TlsConfig {
20    /// Create a new TLS configuration.
21    pub fn new(cert_path: impl Into<PathBuf>, key_path: impl Into<PathBuf>) -> Self {
22        Self {
23            cert_path: cert_path.into(),
24            key_path: key_path.into(),
25        }
26    }
27
28    /// Build a `RustlsConfig` from the certificate and key files.
29    pub async fn build_rustls_config(
30        &self,
31    ) -> Result<axum_server::tls_rustls::RustlsConfig, std::io::Error> {
32        axum_server::tls_rustls::RustlsConfig::from_pem_file(&self.cert_path, &self.key_path).await
33    }
34}