wireman_core/client/
tls.rs1#![allow(clippy::module_name_repetitions)]
2use crate::error::{Error, Result};
3use tonic::transport::{Certificate, ClientTlsConfig};
4
5#[derive(Debug, Clone)]
7pub struct TlsConfig(pub(super) ClientTlsConfig);
8
9impl TlsConfig {
10 #[must_use]
12 pub fn native() -> Self {
13 Self(ClientTlsConfig::new().with_enabled_roots())
14 }
15
16 pub fn custom(cert_path: String) -> Result<Self> {
22 let pem = std::fs::read_to_string(cert_path).map_err(Error::LoadTLSCertificateError)?;
23 let ca = Certificate::from_pem(pem);
24 let tls = ClientTlsConfig::new().ca_certificate(ca);
25
26 Ok(Self(tls))
27 }
28}