use std::fmt;
use super::service::TlsAcceptor;
use crate::transport::tls::{Certificate, Identity};
#[derive(Clone, Default)]
pub struct ServerTlsConfig {
identity: Option<Identity>,
client_ca_root: Option<Certificate>,
client_auth_optional: bool,
}
impl fmt::Debug for ServerTlsConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ServerTlsConfig").finish()
}
}
impl ServerTlsConfig {
pub fn new() -> Self {
ServerTlsConfig {
identity: None,
client_ca_root: None,
client_auth_optional: false,
}
}
pub fn identity(self, identity: Identity) -> Self {
ServerTlsConfig {
identity: Some(identity),
..self
}
}
pub fn client_ca_root(self, cert: Certificate) -> Self {
ServerTlsConfig {
client_ca_root: Some(cert),
..self
}
}
pub fn client_auth_optional(self, optional: bool) -> Self {
ServerTlsConfig {
client_auth_optional: optional,
..self
}
}
pub(crate) fn tls_acceptor(&self) -> Result<TlsAcceptor, crate::Error> {
TlsAcceptor::new(
self.identity.clone().unwrap(),
self.client_ca_root.clone(),
self.client_auth_optional,
)
}
}