File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed
trigger/src/runtime_config Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,13 @@ pub fn load_key(path: impl AsRef<Path>) -> io::Result<rustls_pki_types::PrivateK
56
56
} ,
57
57
) ?) )
58
58
. map_err ( |_| io:: Error :: new ( io:: ErrorKind :: InvalidInput , "invalid private key" ) )
59
- . map ( |keys| keys. unwrap ( ) )
59
+ . transpose ( )
60
+ . ok_or_else ( || {
61
+ io:: Error :: new (
62
+ io:: ErrorKind :: InvalidInput ,
63
+ "private key file contains no private keys" ,
64
+ )
65
+ } ) ?
60
66
}
61
67
62
68
#[ cfg( test) ]
Original file line number Diff line number Diff line change 1
1
use anyhow:: Context ;
2
2
use rustls_pemfile:: private_key;
3
3
use std:: io;
4
- use std:: io:: Cursor ;
5
4
use std:: {
6
5
fs,
7
6
path:: { Path , PathBuf } ,
@@ -21,13 +20,16 @@ pub struct ClientTlsOpts {
21
20
// load_certs parse and return the certs from the provided file
22
21
pub fn load_certs (
23
22
path : impl AsRef < Path > ,
24
- ) -> anyhow:: Result < Vec < rustls_pki_types:: CertificateDer < ' static > > > {
25
- let contents = fs:: read_to_string ( path) . expect ( "Should have been able to read the file" ) ;
26
- let mut custom_root_ca_cursor = Cursor :: new ( contents) ;
27
-
28
- Ok ( rustls_pemfile:: certs ( & mut custom_root_ca_cursor)
29
- . map ( |certs| certs. unwrap ( ) )
30
- . collect ( ) )
23
+ ) -> io:: Result < Vec < rustls_pki_types:: CertificateDer < ' static > > > {
24
+ rustls_pemfile:: certs ( & mut io:: BufReader :: new ( fs:: File :: open ( path) . map_err (
25
+ |err| {
26
+ io:: Error :: new (
27
+ io:: ErrorKind :: InvalidInput ,
28
+ format ! ( "failed to read cert file {:?}" , err) ,
29
+ )
30
+ } ,
31
+ ) ?) )
32
+ . collect :: < io:: Result < Vec < rustls_pki_types:: CertificateDer < ' static > > > > ( )
31
33
}
32
34
33
35
// load_keys parse and return the first private key from the provided file
@@ -38,5 +40,11 @@ pub fn load_key(
38
40
fs:: File :: open ( path) . context ( "loading private key" ) ?,
39
41
) )
40
42
. map_err ( |_| anyhow:: anyhow!( "invalid input" ) )
41
- . map ( |keys| keys. unwrap ( ) )
43
+ . transpose ( )
44
+ . ok_or_else ( || {
45
+ io:: Error :: new (
46
+ io:: ErrorKind :: InvalidInput ,
47
+ "private key file contains no private keys" ,
48
+ )
49
+ } ) ?
42
50
}
You can’t perform that action at this time.
0 commit comments