@@ -223,10 +223,10 @@ pub struct Config {
223
223
pub ( crate ) dbname : Option < String > ,
224
224
pub ( crate ) options : Option < String > ,
225
225
pub ( crate ) application_name : Option < String > ,
226
- pub ( crate ) ssl_cert : Option < PathBuf > ,
227
- pub ( crate ) ssl_key : Option < PathBuf > ,
226
+ pub ( crate ) ssl_cert : Option < Vec < u8 > > ,
227
+ pub ( crate ) ssl_key : Option < Vec < u8 > > ,
228
228
pub ( crate ) ssl_mode : SslMode ,
229
- pub ( crate ) ssl_root_cert : Option < PathBuf > ,
229
+ pub ( crate ) ssl_root_cert : Option < Vec < u8 > > ,
230
230
pub ( crate ) host : Vec < Host > ,
231
231
pub ( crate ) hostaddr : Vec < IpAddr > ,
232
232
pub ( crate ) port : Vec < u16 > ,
@@ -346,30 +346,30 @@ impl Config {
346
346
self . application_name . as_deref ( )
347
347
}
348
348
349
- /// Sets the location of the client SSL certificate file .
349
+ /// Sets the client SSL certificate in PEM format .
350
350
///
351
351
/// Defaults to `None`.
352
- pub fn ssl_cert ( & mut self , ssl_cert : & str ) -> & mut Config {
353
- self . ssl_cert = Some ( PathBuf :: from ( ssl_cert) ) ;
352
+ pub fn ssl_cert ( & mut self , ssl_cert : & [ u8 ] ) -> & mut Config {
353
+ self . ssl_cert = Some ( ssl_cert. into ( ) ) ;
354
354
self
355
355
}
356
356
357
- /// Gets the location of the client SSL certificate file .
358
- pub fn get_ssl_cert ( & self ) -> Option < PathBuf > {
359
- self . ssl_cert . clone ( )
357
+ /// Gets the location of the client SSL certificate in PEM format .
358
+ pub fn get_ssl_cert ( & self ) -> Option < & [ u8 ] > {
359
+ self . ssl_cert . as_deref ( )
360
360
}
361
361
362
- /// Sets the location of the secret key file used for the client certificate .
362
+ /// Sets the client SSL key in PEM format .
363
363
///
364
364
/// Defaults to `None`.
365
- pub fn ssl_key ( & mut self , ssl_key : & str ) -> & mut Config {
366
- self . ssl_key = Some ( PathBuf :: from ( ssl_key) ) ;
365
+ pub fn ssl_key ( & mut self , ssl_key : & [ u8 ] ) -> & mut Config {
366
+ self . ssl_key = Some ( ssl_key. into ( ) ) ;
367
367
self
368
368
}
369
369
370
- /// Gets the location of the secret key file used for the client certificate .
371
- pub fn get_ssl_key ( & self ) -> Option < PathBuf > {
372
- self . ssl_key . clone ( )
370
+ /// Gets the client SSL key in PEM format .
371
+ pub fn get_ssl_key ( & self ) -> Option < & [ u8 ] > {
372
+ self . ssl_key . as_deref ( )
373
373
}
374
374
375
375
/// Sets the SSL configuration.
@@ -385,17 +385,17 @@ impl Config {
385
385
self . ssl_mode
386
386
}
387
387
388
- /// Sets the location of SSL certificate authority (CA) certificate.
388
+ /// Sets the SSL certificate authority (CA) certificate in PEM format .
389
389
///
390
390
/// Defaults to `None`.
391
- pub fn ssl_root_cert ( & mut self , ssl_root_cert : & str ) -> & mut Config {
392
- self . ssl_root_cert = Some ( PathBuf :: from ( ssl_root_cert) ) ;
391
+ pub fn ssl_root_cert ( & mut self , ssl_root_cert : & [ u8 ] ) -> & mut Config {
392
+ self . ssl_root_cert = Some ( ssl_root_cert. into ( ) ) ;
393
393
self
394
394
}
395
395
396
- /// Gets the location of SSL certificate authority (CA) certificate.
397
- pub fn get_ssl_root_cert ( & self ) -> Option < PathBuf > {
398
- self . ssl_root_cert . clone ( )
396
+ /// Gets the SSL certificate authority (CA) certificate in PEM format .
397
+ pub fn get_ssl_root_cert ( & self ) -> Option < & [ u8 ] > {
398
+ self . ssl_root_cert . as_deref ( )
399
399
}
400
400
401
401
/// Adds a host to the configuration.
@@ -630,18 +630,22 @@ impl Config {
630
630
"application_name" => {
631
631
self . application_name ( value) ;
632
632
}
633
- "sslcert" => {
634
- if std:: fs:: metadata ( value) . is_err ( ) {
633
+ "sslcert" => match std:: fs:: read ( value) {
634
+ Ok ( contents) => {
635
+ self . ssl_cert ( & contents) ;
636
+ }
637
+ Err ( _) => {
635
638
return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslcert" ) ) ) ) ;
636
639
}
637
- self . ssl_cert ( value) ;
638
- }
639
- "sslkey" => {
640
- if std:: fs:: metadata ( value) . is_err ( ) {
640
+ } ,
641
+ "sslkey" => match std:: fs:: read ( value) {
642
+ Ok ( contents) => {
643
+ self . ssl_key ( & contents) ;
644
+ }
645
+ Err ( _) => {
641
646
return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslkey" ) ) ) ) ;
642
647
}
643
- self . ssl_key ( value) ;
644
- }
648
+ } ,
645
649
"sslmode" => {
646
650
let mode = match value {
647
651
"disable" => SslMode :: Disable ,
@@ -653,12 +657,14 @@ impl Config {
653
657
} ;
654
658
self . ssl_mode ( mode) ;
655
659
}
656
- "sslrootcert" => {
657
- if std:: fs:: metadata ( value) . is_err ( ) {
660
+ "sslrootcert" => match std:: fs:: read ( value) {
661
+ Ok ( contents) => {
662
+ self . ssl_root_cert ( & contents) ;
663
+ }
664
+ Err ( _) => {
658
665
return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslrootcert" ) ) ) ) ;
659
666
}
660
- self . ssl_root_cert ( value) ;
661
- }
667
+ } ,
662
668
"host" => {
663
669
for host in value. split ( ',' ) {
664
670
self . host ( host) ;
0 commit comments