@@ -14,7 +14,7 @@ use tokio::io::{
1414use tokio:: net:: { TcpStream , ToSocketAddrs } ;
1515
1616#[ cfg( feature = "secure" ) ]
17- use tokio_rustls:: { rustls:: ClientConfig , webpki :: DNSName , TlsConnector } ;
17+ use tokio_rustls:: { rustls:: ClientConfig , rustls :: ServerName , TlsConnector } ;
1818
1919use crate :: data_stream:: DataStream ;
2020use crate :: status;
@@ -36,7 +36,7 @@ lazy_static::lazy_static! {
3636pub struct FtpStream {
3737 reader : BufReader < DataStream > ,
3838 #[ cfg( feature = "secure" ) ]
39- ssl_cfg : Option < ( ClientConfig , DNSName ) > ,
39+ ssl_cfg : Option < ( ClientConfig , ServerName ) > ,
4040 welcome_msg : Option < String > ,
4141}
4242
@@ -69,30 +69,29 @@ impl FtpStream {
6969 /// ## Example
7070 ///
7171 /// ```rust,no_run
72+ /// use std::convert::TryFrom;
7273 /// use std::path::Path;
7374 /// use async_ftp::FtpStream;
74- /// use tokio_rustls::rustls::{ClientConfig, RootCertStore};
75- /// use tokio_rustls::webpki::{DNSName, DNSNameRef};
75+ /// use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
7676 ///
7777 /// let mut root_store = RootCertStore::empty();
7878 /// // root_store.add_pem_file(...);
79- /// let mut conf = ClientConfig::new();
80- /// conf.root_store = root_store;
81- /// let domain = DNSNameRef::try_from_ascii_str("www.cert-domain.com").unwrap().into();
79+ /// let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
80+ /// let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");
8281 /// async {
8382 /// let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
8483 /// let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
8584 /// };
8685 /// ```
8786 #[ cfg( feature = "secure" ) ]
88- pub async fn into_secure ( mut self , config : ClientConfig , domain : DNSName ) -> Result < FtpStream > {
87+ pub async fn into_secure ( mut self , config : ClientConfig , domain : ServerName ) -> Result < FtpStream > {
8988 // Ask the server to start securing data.
9089 self . write_str ( "AUTH TLS\r \n " ) . await ?;
9190 self . read_response ( status:: AUTH_OK ) . await ?;
9291
9392 let connector: TlsConnector = std:: sync:: Arc :: new ( config. clone ( ) ) . into ( ) ;
9493 let stream = connector
95- . connect ( domain. as_ref ( ) , self . reader . into_inner ( ) . into_tcp_stream ( ) )
94+ . connect ( domain. clone ( ) , self . reader . into_inner ( ) . into_tcp_stream ( ) )
9695 . await
9796 . map_err ( |e| FtpError :: SecureError ( format ! ( "{}" , e) ) ) ?;
9897
@@ -116,16 +115,15 @@ impl FtpStream {
116115 /// ## Example
117116 ///
118117 /// ```rust,no_run
118+ /// use std::convert::TryFrom;
119119 /// use std::path::Path;
120120 /// use async_ftp::FtpStream;
121- /// use tokio_rustls::rustls::{ClientConfig, RootCertStore};
122- /// use tokio_rustls::webpki::{DNSName, DNSNameRef};
121+ /// use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
123122 ///
124123 /// let mut root_store = RootCertStore::empty();
125124 /// // root_store.add_pem_file(...);
126- /// let mut conf = ClientConfig::new();
127- /// conf.root_store = root_store;
128- /// let domain = DNSNameRef::try_from_ascii_str("www.cert-domain.com").unwrap().into();
125+ /// let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
126+ /// let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");
129127 /// async {
130128 /// let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await.unwrap();
131129 /// let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
@@ -162,7 +160,7 @@ impl FtpStream {
162160 Some ( ( config, domain) ) => {
163161 let connector: TlsConnector = std:: sync:: Arc :: new ( config. clone ( ) ) . into ( ) ;
164162 return connector
165- . connect ( domain. as_ref ( ) , stream)
163+ . connect ( domain. to_owned ( ) , stream)
166164 . await
167165 . map ( |stream| DataStream :: Ssl ( stream) )
168166 . map_err ( |e| FtpError :: SecureError ( format ! ( "{}" , e) ) ) ;
0 commit comments