@@ -51,6 +51,7 @@ use rustls::{
51
51
server:: ParsedCertificate , DigitallySignedStruct , Error as TLSError , RootCertStore ,
52
52
SignatureScheme ,
53
53
} ;
54
+ use rustls_pki_types:: pem:: PemObject ;
54
55
#[ cfg( feature = "__rustls" ) ]
55
56
use rustls_pki_types:: { ServerName , UnixTime } ;
56
57
use std:: {
@@ -228,7 +229,7 @@ impl Certificate {
228
229
}
229
230
230
231
fn read_pem_certs ( reader : & mut impl BufRead ) -> crate :: Result < Vec < Vec < u8 > > > {
231
- rustls_pemfile :: certs ( reader)
232
+ rustls_pki_types :: CertificateDer :: pem_reader_iter ( reader)
232
233
. map ( |result| match result {
233
234
Ok ( cert) => Ok ( cert. as_ref ( ) . to_vec ( ) ) ,
234
235
Err ( _) => Err ( crate :: error:: builder ( "invalid certificate encoding" ) ) ,
@@ -339,30 +340,31 @@ impl Identity {
339
340
/// This requires the `rustls-tls(-...)` Cargo feature enabled.
340
341
#[ cfg( feature = "__rustls" ) ]
341
342
pub fn from_pem ( buf : & [ u8 ] ) -> crate :: Result < Identity > {
342
- use rustls_pemfile :: Item ;
343
+ use rustls_pki_types :: { pem :: SectionKind , PrivateKeyDer } ;
343
344
use std:: io:: Cursor ;
344
345
345
346
let ( key, certs) = {
346
347
let mut pem = Cursor :: new ( buf) ;
347
348
let mut sk = Vec :: < rustls_pki_types:: PrivateKeyDer > :: new ( ) ;
348
349
let mut certs = Vec :: < rustls_pki_types:: CertificateDer > :: new ( ) ;
349
350
350
- for result in rustls_pemfile:: read_all ( & mut pem) {
351
- match result {
352
- Ok ( Item :: X509Certificate ( cert) ) => certs. push ( cert) ,
353
- Ok ( Item :: Pkcs1Key ( key) ) => sk. push ( key. into ( ) ) ,
354
- Ok ( Item :: Pkcs8Key ( key) ) => sk. push ( key. into ( ) ) ,
355
- Ok ( Item :: Sec1Key ( key) ) => sk. push ( key. into ( ) ) ,
356
- Ok ( _) => {
351
+ while let Some ( ( kind, data) ) =
352
+ rustls_pki_types:: pem:: from_buf ( & mut pem) . map_err ( |_| {
353
+ crate :: error:: builder ( TLSError :: General ( String :: from (
354
+ "Invalid identity PEM file" ,
355
+ ) ) )
356
+ } ) ?
357
+ {
358
+ match kind {
359
+ SectionKind :: Certificate => certs. push ( data. into ( ) ) ,
360
+ SectionKind :: PrivateKey => sk. push ( PrivateKeyDer :: Pkcs8 ( data. into ( ) ) ) ,
361
+ SectionKind :: RsaPrivateKey => sk. push ( PrivateKeyDer :: Pkcs1 ( data. into ( ) ) ) ,
362
+ SectionKind :: EcPrivateKey => sk. push ( PrivateKeyDer :: Sec1 ( data. into ( ) ) ) ,
363
+ _ => {
357
364
return Err ( crate :: error:: builder ( TLSError :: General ( String :: from (
358
365
"No valid certificate was found" ,
359
366
) ) ) )
360
367
}
361
- Err ( _) => {
362
- return Err ( crate :: error:: builder ( TLSError :: General ( String :: from (
363
- "Invalid identity PEM file" ,
364
- ) ) ) )
365
- }
366
368
}
367
369
}
368
370
@@ -469,9 +471,7 @@ impl CertificateRevocationList {
469
471
/// This requires the `rustls-tls(-...)` Cargo feature enabled.
470
472
#[ cfg( feature = "__rustls" ) ]
471
473
pub fn from_pem_bundle ( pem_bundle : & [ u8 ] ) -> crate :: Result < Vec < CertificateRevocationList > > {
472
- let mut reader = BufReader :: new ( pem_bundle) ;
473
-
474
- rustls_pemfile:: crls ( & mut reader)
474
+ rustls_pki_types:: CertificateRevocationListDer :: pem_slice_iter ( pem_bundle)
475
475
. map ( |result| match result {
476
476
Ok ( crl) => Ok ( CertificateRevocationList { inner : crl } ) ,
477
477
Err ( _) => Err ( crate :: error:: builder ( "invalid crl encoding" ) ) ,
0 commit comments