use std::path::PathBuf;
use dusa_collection_utils::core::errors::{ErrorArrayItem, Errors};
pub struct MtlsMaterial {
pub cert_pem: Vec<u8>,
pub key_pem: Vec<u8>,
pub ca_pem: Vec<u8>,
}
pub struct MtlsConfig {
pub cert_path: PathBuf,
pub key_path: PathBuf,
pub ca_cert_path: PathBuf,
}
pub fn load_mtls_material(cfg: &MtlsConfig) -> Result<MtlsMaterial, ErrorArrayItem> {
let cert_pem = std::fs::read(&cfg.cert_path)
.map_err(|e| ErrorArrayItem::new(
Errors::GeneralError,
format!("failed to read cert at {:?}: {}", cfg.cert_path, e)
))?;
let key_pem = std::fs::read(&cfg.key_path)
.map_err(|e| ErrorArrayItem::new(
Errors::GeneralError,
format!("failed to read key at {:?}: {}", cfg.key_path, e)
))?;
let ca_pem = std::fs::read(&cfg.ca_cert_path)
.map_err(|e| ErrorArrayItem::new(
Errors::GeneralError,
format!("failed to read CA cert at {:?}: {}", cfg.ca_cert_path, e)
))?;
Ok(MtlsMaterial { cert_pem, key_pem, ca_pem })
}