11use std:: { fmt, io:: Cursor } ;
22
3- use tokio_rustls:: rustls:: {
4- pki_types:: { CertificateDer , PrivateKeyDer } ,
5- RootCertStore ,
6- } ;
3+ use tokio_rustls:: rustls:: pki_types:: { CertificateDer , PrivateKeyDer } ;
74
8- use crate :: transport:: Identity ;
5+ use crate :: transport:: { Certificate , Identity } ;
96
107/// h2 alpn in plain format for rustls.
118pub ( crate ) const ALPN_H2 : & [ u8 ] = b"h2" ;
@@ -34,6 +31,14 @@ impl fmt::Display for TlsError {
3431
3532impl std:: error:: Error for TlsError { }
3633
34+ impl Certificate {
35+ pub ( crate ) fn parse ( & self ) -> Result < Vec < CertificateDer < ' static > > , TlsError > {
36+ rustls_pemfile:: certs ( & mut Cursor :: new ( & self . pem ) )
37+ . collect :: < Result < Vec < _ > , _ > > ( )
38+ . map_err ( |_| TlsError :: CertificateParseError )
39+ }
40+ }
41+
3742pub ( crate ) fn load_identity (
3843 identity : Identity ,
3944) -> Result < ( Vec < CertificateDer < ' static > > , PrivateKeyDer < ' static > ) , TlsError > {
@@ -47,16 +52,3 @@ pub(crate) fn load_identity(
4752
4853 Ok ( ( cert, key) )
4954}
50-
51- pub ( crate ) fn add_certs_from_pem (
52- mut certs : & mut dyn std:: io:: BufRead ,
53- roots : & mut RootCertStore ,
54- ) -> Result < ( ) , crate :: Error > {
55- for cert in rustls_pemfile:: certs ( & mut certs) . collect :: < Result < Vec < _ > , _ > > ( ) ? {
56- roots
57- . add ( cert)
58- . map_err ( |_| TlsError :: CertificateParseError ) ?;
59- }
60-
61- Ok ( ( ) )
62- }
0 commit comments