@@ -14,7 +14,7 @@ pub mod rustls_tls {
1414 pub enum Error {
1515 /// Identity PEM is invalid
1616 #[ error( "identity PEM is invalid: {0}" ) ]
17- InvalidIdentityPem ( #[ source] std :: io :: Error ) ,
17+ InvalidIdentityPem ( #[ source] rustls :: pki_types :: pem :: Error ) ,
1818
1919 /// Identity PEM is missing a private key: the key must be PKCS8 or RSA/PKCS1
2020 #[ error( "identity PEM is missing a private key: the key must be PKCS8 or RSA/PKCS1" ) ]
@@ -96,22 +96,19 @@ pub mod rustls_tls {
9696 }
9797
9898 fn client_auth ( data : & [ u8 ] ) -> Result < ( Vec < CertificateDer < ' static > > , PrivateKeyDer < ' static > ) , Error > {
99- use rustls_pemfile :: Item ;
99+ use rustls :: pki_types :: pem :: { self , SectionKind } ;
100100
101101 let mut cert_chain = Vec :: new ( ) ;
102102 let mut pkcs8_key = None ;
103103 let mut pkcs1_key = None ;
104104 let mut sec1_key = None ;
105105 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 = Some ( PrivateKeyDer :: Pkcs8 ( der. into ( ) ) ) ,
110+ SectionKind :: RsaPrivateKey => pkcs1_key = Some ( PrivateKeyDer :: Pkcs1 ( der. into ( ) ) ) ,
111+ SectionKind :: EcPrivateKey => sec1_key = Some ( PrivateKeyDer :: Sec1 ( der. into ( ) ) ) ,
115112 _ => return Err ( Error :: UnknownPrivateKeyFormat ) ,
116113 }
117114 }
0 commit comments