Skip to content

Commit 9cb7dc6

Browse files
committed
RUST-791 use PathBuf instead of String for paths (C-CUSTOM-TYPE)
1 parent ec07245 commit 9cb7dc6

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

src/client/options/mod.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::{
1010
fs::File,
1111
hash::{Hash, Hasher},
1212
io::{BufReader, Seek, SeekFrom},
13+
path::PathBuf,
1314
str::FromStr,
1415
sync::Arc,
1516
time::Duration,
@@ -564,13 +565,13 @@ pub struct TlsOptions {
564565
/// The path to the CA file that the [`Client`](../struct.Client.html) should use for TLS. If
565566
/// none is specified, then the driver will use the Mozilla root certificates from the
566567
/// `webpki-roots` crate.
567-
pub ca_file_path: Option<String>,
568+
pub ca_file_path: Option<PathBuf>,
568569

569570
/// The path to the certificate file that the [`Client`](../struct.Client.html) should present
570571
/// to the server to verify its identify. If none is specified, then the
571572
/// [`Client`](../struct.Client.html) will not attempt to verify its identity to the
572573
/// server.
573-
pub cert_key_file_path: Option<String>,
574+
pub cert_key_file_path: Option<PathBuf>,
574575
}
575576

576577
struct NoCertVerifier {}
@@ -603,7 +604,10 @@ impl TlsOptions {
603604
store
604605
.add_pem_file(&mut BufReader::new(File::open(&path)?))
605606
.map_err(|_| ErrorKind::InvalidTlsConfig {
606-
message: format!("Unable to parse PEM-encoded root certificate from {}", path),
607+
message: format!(
608+
"Unable to parse PEM-encoded root certificate from {}",
609+
path.display()
610+
),
607611
})?;
608612
} else {
609613
store.add_server_trust_anchors(&TLS_SERVER_ROOTS);
@@ -619,7 +623,7 @@ impl TlsOptions {
619623
return Err(ErrorKind::InvalidTlsConfig {
620624
message: format!(
621625
"Unable to parse PEM-encoded client certificate from {}",
622-
path
626+
path.display()
623627
),
624628
}
625629
.into())
@@ -631,7 +635,10 @@ impl TlsOptions {
631635
Ok(key) => key,
632636
Err(()) => {
633637
return Err(ErrorKind::InvalidTlsConfig {
634-
message: format!("Unable to parse PEM-encoded RSA key from {}", path),
638+
message: format!(
639+
"Unable to parse PEM-encoded RSA key from {}",
640+
path.display()
641+
),
635642
}
636643
.into())
637644
}
@@ -1623,13 +1630,11 @@ impl ClientOptionsParser {
16231630
.into());
16241631
}
16251632
Some(Tls::Enabled(ref mut options)) => {
1626-
options.ca_file_path = Some(value.to_string());
1633+
options.ca_file_path = Some(value.into());
16271634
}
16281635
None => {
16291636
self.tls = Some(Tls::Enabled(
1630-
TlsOptions::builder()
1631-
.ca_file_path(value.to_string())
1632-
.build(),
1637+
TlsOptions::builder().ca_file_path(value.into()).build(),
16331638
))
16341639
}
16351640
},
@@ -1641,12 +1646,12 @@ impl ClientOptionsParser {
16411646
.into());
16421647
}
16431648
Some(Tls::Enabled(ref mut options)) => {
1644-
options.cert_key_file_path = Some(value.to_string());
1649+
options.cert_key_file_path = Some(value.into());
16451650
}
16461651
None => {
16471652
self.tls = Some(Tls::Enabled(
16481653
TlsOptions::builder()
1649-
.cert_key_file_path(value.to_string())
1654+
.cert_key_file_path(value.into())
16501655
.build(),
16511656
))
16521657
}

src/client/options/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ fn document_from_client_options(mut options: ClientOptions) -> Document {
153153

154154
if let Some(s) = ca_file_path {
155155
doc.insert("tls", true);
156-
doc.insert("tlscafile", s);
156+
doc.insert("tlscafile", s.to_str().unwrap());
157157
}
158158

159159
if let Some(s) = cert_key_file_path {
160-
doc.insert("tlscertificatekeyfile", s);
160+
doc.insert("tlscertificatekeyfile", s.to_str().unwrap());
161161
}
162162

163163
if let Some(b) = allow_invalid_certificates {

src/cmap/test/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,26 @@ impl Matchable for TlsOptions {
323323
fn content_matches(&self, expected: &TlsOptions) -> bool {
324324
self.allow_invalid_certificates
325325
.matches(&expected.allow_invalid_certificates)
326-
&& self.ca_file_path.matches(&expected.ca_file_path)
326+
&& self
327+
.ca_file_path
328+
.as_ref()
329+
.map(|pb| pb.display().to_string())
330+
.matches(
331+
&expected
332+
.ca_file_path
333+
.as_ref()
334+
.map(|pb| pb.display().to_string()),
335+
)
327336
&& self
328337
.cert_key_file_path
329-
.matches(&expected.cert_key_file_path)
338+
.as_ref()
339+
.map(|pb| pb.display().to_string())
340+
.matches(
341+
&expected
342+
.cert_key_file_path
343+
.as_ref()
344+
.map(|pb| pb.display().to_string()),
345+
)
330346
}
331347
}
332348

src/test/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ async fn auth_test_uri(
360360
uri.push_str("&tlsCAFile=");
361361
uri.push_str(
362362
&percent_encoding::utf8_percent_encode(
363-
ca_file_path,
363+
ca_file_path.to_str().unwrap(),
364364
percent_encoding::NON_ALPHANUMERIC,
365365
)
366366
.to_string(),
@@ -371,7 +371,7 @@ async fn auth_test_uri(
371371
uri.push_str("&tlsCertificateKeyFile=");
372372
uri.push_str(
373373
&percent_encoding::utf8_percent_encode(
374-
cert_key_file_path,
374+
cert_key_file_path.to_str().unwrap(),
375375
percent_encoding::NON_ALPHANUMERIC,
376376
)
377377
.to_string(),

0 commit comments

Comments
 (0)