@@ -14,7 +14,7 @@ pub mod rustls_tls {
14
14
pub enum Error {
15
15
/// Identity PEM is invalid
16
16
#[ error( "identity PEM is invalid: {0}" ) ]
17
- InvalidIdentityPem ( #[ source] std :: io :: Error ) ,
17
+ InvalidIdentityPem ( #[ source] rustls :: pki_types :: pem :: Error ) ,
18
18
19
19
/// Identity PEM is missing a private key: the key must be PKCS8 or RSA/PKCS1
20
20
#[ error( "identity PEM is missing a private key: the key must be PKCS8 or RSA/PKCS1" ) ]
@@ -96,22 +96,19 @@ pub mod rustls_tls {
96
96
}
97
97
98
98
fn client_auth ( data : & [ u8 ] ) -> Result < ( Vec < CertificateDer < ' static > > , PrivateKeyDer < ' static > ) , Error > {
99
- use rustls_pemfile :: Item ;
99
+ use rustls :: pki_types :: pem :: { self , PemObject , SectionKind } ;
100
100
101
101
let mut cert_chain = Vec :: new ( ) ;
102
102
let mut pkcs8_key = None ;
103
103
let mut pkcs1_key = None ;
104
104
let mut sec1_key = None ;
105
105
let mut reader = std:: io:: Cursor :: new ( data) ;
106
- for item in rustls_pemfile:: read_all ( & mut reader)
107
- . collect :: < Result < Vec < _ > , _ > > ( )
108
- . map_err ( Error :: InvalidIdentityPem ) ?
109
- {
110
- match item {
111
- Item :: X509Certificate ( cert) => cert_chain. push ( cert) ,
112
- Item :: Pkcs8Key ( key) => pkcs8_key = Some ( PrivateKeyDer :: Pkcs8 ( key) ) ,
113
- Item :: Pkcs1Key ( key) => pkcs1_key = Some ( PrivateKeyDer :: from ( key) ) ,
114
- Item :: Sec1Key ( key) => sec1_key = Some ( PrivateKeyDer :: from ( key) ) ,
106
+ while let Some ( ( kind, der) ) = pem:: from_buf ( & mut reader) . map_err ( Error :: InvalidIdentityPem ) ? {
107
+ match kind {
108
+ SectionKind :: Certificate => cert_chain. push ( der. into ( ) ) ,
109
+ SectionKind :: PrivateKey => pkcs8_key = PrivateKeyDer :: from_pem ( kind, der) ,
110
+ SectionKind :: RsaPrivateKey => pkcs1_key = PrivateKeyDer :: from_pem ( kind, der) ,
111
+ SectionKind :: EcPrivateKey => sec1_key = PrivateKeyDer :: from_pem ( kind, der) ,
115
112
_ => return Err ( Error :: UnknownPrivateKeyFormat ) ,
116
113
}
117
114
}
0 commit comments