@@ -171,10 +171,10 @@ pub struct Config {
171
171
pub ( crate ) dbname : Option < String > ,
172
172
pub ( crate ) options : Option < String > ,
173
173
pub ( crate ) application_name : Option < String > ,
174
- pub ( crate ) ssl_cert : Option < PathBuf > ,
175
- pub ( crate ) ssl_key : Option < PathBuf > ,
174
+ pub ( crate ) ssl_cert : Option < Vec < u8 > > ,
175
+ pub ( crate ) ssl_key : Option < Vec < u8 > > ,
176
176
pub ( crate ) ssl_mode : SslMode ,
177
- pub ( crate ) ssl_root_cert : Option < PathBuf > ,
177
+ pub ( crate ) ssl_root_cert : Option < Vec < u8 > > ,
178
178
pub ( crate ) host : Vec < Host > ,
179
179
pub ( crate ) port : Vec < u16 > ,
180
180
pub ( crate ) connect_timeout : Option < Duration > ,
@@ -282,30 +282,30 @@ impl Config {
282
282
self . application_name . as_deref ( )
283
283
}
284
284
285
- /// Sets the location of the client SSL certificate file .
285
+ /// Sets the client SSL certificate in PEM format .
286
286
///
287
287
/// Defaults to `None`.
288
- pub fn ssl_cert ( & mut self , ssl_cert : & str ) -> & mut Config {
289
- self . ssl_cert = Some ( PathBuf :: from ( ssl_cert) ) ;
288
+ pub fn ssl_cert ( & mut self , ssl_cert : & [ u8 ] ) -> & mut Config {
289
+ self . ssl_cert = Some ( ssl_cert. into ( ) ) ;
290
290
self
291
291
}
292
292
293
- /// Gets the location of the client SSL certificate file .
294
- pub fn get_ssl_cert ( & self ) -> Option < PathBuf > {
295
- self . ssl_cert . clone ( )
293
+ /// Gets the location of the client SSL certificate in PEM format .
294
+ pub fn get_ssl_cert ( & self ) -> Option < & [ u8 ] > {
295
+ self . ssl_cert . as_deref ( )
296
296
}
297
297
298
- /// Sets the location of the secret key file used for the client certificate .
298
+ /// Sets the client SSL key in PEM format .
299
299
///
300
300
/// Defaults to `None`.
301
- pub fn ssl_key ( & mut self , ssl_key : & str ) -> & mut Config {
302
- self . ssl_key = Some ( PathBuf :: from ( ssl_key) ) ;
301
+ pub fn ssl_key ( & mut self , ssl_key : & [ u8 ] ) -> & mut Config {
302
+ self . ssl_key = Some ( ssl_key. into ( ) ) ;
303
303
self
304
304
}
305
305
306
- /// Gets the location of the secret key file used for the client certificate .
307
- pub fn get_ssl_key ( & self ) -> Option < PathBuf > {
308
- self . ssl_key . clone ( )
306
+ /// Gets the client SSL key in PEM format .
307
+ pub fn get_ssl_key ( & self ) -> Option < & [ u8 ] > {
308
+ self . ssl_key . as_deref ( )
309
309
}
310
310
311
311
/// Sets the SSL configuration.
@@ -321,17 +321,17 @@ impl Config {
321
321
self . ssl_mode
322
322
}
323
323
324
- /// Sets the location of SSL certificate authority (CA) certificate.
324
+ /// Sets the SSL certificate authority (CA) certificate in PEM format .
325
325
///
326
326
/// Defaults to `None`.
327
- pub fn ssl_root_cert ( & mut self , ssl_root_cert : & str ) -> & mut Config {
328
- self . ssl_root_cert = Some ( PathBuf :: from ( ssl_root_cert) ) ;
327
+ pub fn ssl_root_cert ( & mut self , ssl_root_cert : & [ u8 ] ) -> & mut Config {
328
+ self . ssl_root_cert = Some ( ssl_root_cert. into ( ) ) ;
329
329
self
330
330
}
331
331
332
- /// Gets the location of SSL certificate authority (CA) certificate.
333
- pub fn get_ssl_root_cert ( & self ) -> Option < PathBuf > {
334
- self . ssl_root_cert . clone ( )
332
+ /// Gets the SSL certificate authority (CA) certificate in PEM format .
333
+ pub fn get_ssl_root_cert ( & self ) -> Option < & [ u8 ] > {
334
+ self . ssl_root_cert . as_deref ( )
335
335
}
336
336
337
337
/// Adds a host to the configuration.
@@ -482,18 +482,22 @@ impl Config {
482
482
"application_name" => {
483
483
self . application_name ( value) ;
484
484
}
485
- "sslcert" => {
486
- if std:: fs:: metadata ( & value) . is_err ( ) {
485
+ "sslcert" => match std:: fs:: read ( & value) {
486
+ Ok ( contents) => {
487
+ self . ssl_cert ( & contents) ;
488
+ }
489
+ Err ( _) => {
487
490
return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslcert" ) ) ) ) ;
488
491
}
489
- self . ssl_cert ( value) ;
490
- }
491
- "sslkey" => {
492
- if std:: fs:: metadata ( & value) . is_err ( ) {
492
+ } ,
493
+ "sslkey" => match std:: fs:: read ( & value) {
494
+ Ok ( contents) => {
495
+ self . ssl_key ( & contents) ;
496
+ }
497
+ Err ( _) => {
493
498
return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslkey" ) ) ) ) ;
494
499
}
495
- self . ssl_key ( value) ;
496
- }
500
+ } ,
497
501
"sslmode" => {
498
502
let mode = match value {
499
503
"disable" => SslMode :: Disable ,
@@ -505,12 +509,14 @@ impl Config {
505
509
} ;
506
510
self . ssl_mode ( mode) ;
507
511
}
508
- "sslrootcert" => {
509
- if std:: fs:: metadata ( & value) . is_err ( ) {
512
+ "sslrootcert" => match std:: fs:: read ( & value) {
513
+ Ok ( contents) => {
514
+ self . ssl_root_cert ( & contents) ;
515
+ }
516
+ Err ( _) => {
510
517
return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslrootcert" ) ) ) ) ;
511
518
}
512
- self . ssl_root_cert ( value) ;
513
- }
519
+ } ,
514
520
"host" => {
515
521
for host in value. split ( ',' ) {
516
522
self . host ( host) ;
0 commit comments