diff --git a/rpxy-bin/src/cert_file_reader.rs b/rpxy-bin/src/cert_file_reader.rs index 0a6a14f..ee9a591 100644 --- a/rpxy-bin/src/cert_file_reader.rs +++ b/rpxy-bin/src/cert_file_reader.rs @@ -8,7 +8,7 @@ use rpxy_lib::{ use std::{ fs::File, io::{self, BufReader, Cursor, Read}, - path::PathBuf, + path::{Path, PathBuf}, }; #[derive(Builder, Debug, Clone)] @@ -28,16 +28,16 @@ pub struct CryptoFileSource { } impl CryptoFileSourceBuilder { - pub fn tls_cert_path(&mut self, v: &str) -> &mut Self { - self.tls_cert_path = Some(PathBuf::from(v)); + pub fn tls_cert_path>(&mut self, v: T) -> &mut Self { + self.tls_cert_path = Some(v.as_ref().to_path_buf()); self } - pub fn tls_cert_key_path(&mut self, v: &str) -> &mut Self { - self.tls_cert_key_path = Some(PathBuf::from(v)); + pub fn tls_cert_key_path>(&mut self, v: T) -> &mut Self { + self.tls_cert_key_path = Some(v.as_ref().to_path_buf()); self } - pub fn client_ca_cert_path(&mut self, v: &Option) -> &mut Self { - self.client_ca_cert_path = Some(v.to_owned().as_ref().map(PathBuf::from)); + pub fn client_ca_cert_path>(&mut self, v: Option) -> &mut Self { + self.client_ca_cert_path = Some(v.map(|p| p.as_ref().to_path_buf())); self } } @@ -167,11 +167,11 @@ mod tests { async fn read_server_crt_key_files_with_client_ca_crt() { let tls_cert_path = "../example-certs/server.crt"; let tls_cert_key_path = "../example-certs/server.key"; - let client_ca_cert_path = Some("../example-certs/client.ca.crt".to_string()); + let client_ca_cert_path = Some("../example-certs/client.ca.crt"); let crypto_file_source = CryptoFileSourceBuilder::default() .tls_cert_key_path(tls_cert_key_path) .tls_cert_path(tls_cert_path) - .client_ca_cert_path(&client_ca_cert_path) + .client_ca_cert_path(client_ca_cert_path) .build(); assert!(crypto_file_source.is_ok()); diff --git a/rpxy-bin/src/config/toml.rs b/rpxy-bin/src/config/toml.rs index e678012..57e12e0 100644 --- a/rpxy-bin/src/config/toml.rs +++ b/rpxy-bin/src/config/toml.rs @@ -217,7 +217,7 @@ impl Application { let inner = CryptoFileSourceBuilder::default() .tls_cert_path(tls.tls_cert_path.as_ref().unwrap()) .tls_cert_key_path(tls.tls_cert_key_path.as_ref().unwrap()) - .client_ca_cert_path(&tls.client_ca_cert_path) + .client_ca_cert_path(tls.client_ca_cert_path.as_deref()) .build()?; let https_redirection = if tls.https_redirection.is_none() {