@@ -3,8 +3,6 @@ use crate::transport::{
33 server:: { Connected , TlsStream } ,
44 Certificate , Identity ,
55} ;
6- #[ cfg( feature = "tls-roots" ) ]
7- use rustls_native_certs;
86use std:: { fmt, sync:: Arc } ;
97use tokio:: io:: { AsyncRead , AsyncWrite } ;
108use tokio_rustls:: {
@@ -38,30 +36,19 @@ impl TlsConnector {
3836 let mut roots = RootCertStore :: empty ( ) ;
3937
4038 #[ cfg( feature = "tls-roots" ) ]
41- {
42- match rustls_native_certs:: load_native_certs ( ) {
43- Ok ( certs) => roots. add_parsable_certificates (
44- & certs. into_iter ( ) . map ( |cert| cert. 0 ) . collect :: < Vec < _ > > ( ) ,
45- ) ,
46- Err ( error) => return Err ( error. into ( ) ) ,
47- } ;
48- }
39+ roots. add_parsable_certificates ( & rustls_native_certs:: load_native_certs ( ) ?) ;
4940
5041 #[ cfg( feature = "tls-webpki-roots" ) ]
51- {
52- use tokio_rustls:: rustls:: OwnedTrustAnchor ;
53-
54- roots. add_trust_anchors ( webpki_roots:: TLS_SERVER_ROOTS . iter ( ) . map ( |ta| {
55- OwnedTrustAnchor :: from_subject_spki_name_constraints (
56- ta. subject ,
57- ta. spki ,
58- ta. name_constraints ,
59- )
60- } ) ) ;
61- }
42+ roots. add_trust_anchors ( webpki_roots:: TLS_SERVER_ROOTS . iter ( ) . map ( |ta| {
43+ tokio_rustls:: rustls:: OwnedTrustAnchor :: from_subject_spki_name_constraints (
44+ ta. subject ,
45+ ta. spki ,
46+ ta. name_constraints ,
47+ )
48+ } ) ) ;
6249
6350 if let Some ( cert) = ca_cert {
64- rustls_keys:: add_certs_from_pem ( std:: io:: Cursor :: new ( & cert. pem [ .. ] ) , & mut roots) ?;
51+ rustls_keys:: add_certs_from_pem ( std:: io:: Cursor :: new ( cert. as_ref ( ) ) , & mut roots) ?;
6552 }
6653
6754 let builder = builder. with_root_certificates ( roots) ;
@@ -127,15 +114,15 @@ impl TlsAcceptor {
127114 ( Some ( cert) , true ) => {
128115 use tokio_rustls:: rustls:: server:: AllowAnyAnonymousOrAuthenticatedClient ;
129116 let mut roots = RootCertStore :: empty ( ) ;
130- rustls_keys:: add_certs_from_pem ( std:: io:: Cursor :: new ( & cert. pem [ .. ] ) , & mut roots) ?;
117+ rustls_keys:: add_certs_from_pem ( std:: io:: Cursor :: new ( cert. as_ref ( ) ) , & mut roots) ?;
131118 builder. with_client_cert_verifier (
132119 AllowAnyAnonymousOrAuthenticatedClient :: new ( roots) . boxed ( ) ,
133120 )
134121 }
135122 ( Some ( cert) , false ) => {
136123 use tokio_rustls:: rustls:: server:: AllowAnyAuthenticatedClient ;
137124 let mut roots = RootCertStore :: empty ( ) ;
138- rustls_keys:: add_certs_from_pem ( std:: io:: Cursor :: new ( & cert. pem [ .. ] ) , & mut roots) ?;
125+ rustls_keys:: add_certs_from_pem ( std:: io:: Cursor :: new ( cert. as_ref ( ) ) , & mut roots) ?;
139126 builder. with_client_cert_verifier ( AllowAnyAuthenticatedClient :: new ( roots) . boxed ( ) )
140127 }
141128 } ;
@@ -207,15 +194,15 @@ mod rustls_keys {
207194 identity : Identity ,
208195 ) -> Result < ( Vec < Certificate > , PrivateKey ) , crate :: Error > {
209196 let cert = {
210- let mut cert = std:: io:: Cursor :: new ( & identity. cert . pem [ .. ] ) ;
197+ let mut cert = std:: io:: Cursor :: new ( identity. cert . as_ref ( ) ) ;
211198 match rustls_pemfile:: certs ( & mut cert) {
212199 Ok ( certs) => certs. into_iter ( ) . map ( Certificate ) . collect ( ) ,
213200 Err ( _) => return Err ( Box :: new ( TlsError :: CertificateParseError ) ) ,
214201 }
215202 } ;
216203
217204 let key = {
218- let key = std:: io:: Cursor :: new ( & identity. key [ .. ] ) ;
205+ let key = std:: io:: Cursor :: new ( identity. key . as_ref ( ) ) ;
219206 match load_rustls_private_key ( key) {
220207 Ok ( key) => key,
221208 Err ( e) => {
0 commit comments