Skip to content

Commit 2c7637c

Browse files
committed
Clean up imports, import ServerName directly
1 parent 6f7373d commit 2c7637c

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

examples/client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::PathBuf;
66
use std::sync::Arc;
77

88
use argh::FromArgs;
9+
use pki_types::ServerName;
910
use tokio::io::{copy, split, stdin as tokio_stdin, stdout as tokio_stdout, AsyncWriteExt};
1011
use tokio::net::TcpStream;
1112
use tokio_rustls::{rustls, TlsConnector};
@@ -60,7 +61,7 @@ async fn main() -> io::Result<()> {
6061

6162
let (mut stdin, mut stdout) = (tokio_stdin(), tokio_stdout());
6263

63-
let domain = pki_types::ServerName::try_from(domain.as_str())
64+
let domain = ServerName::try_from(domain.as_str())
6465
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid dnsname"))?
6566
.to_owned();
6667

src/common/test_stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::task::{Context, Poll};
55

66
use futures_util::future::poll_fn;
77
use futures_util::task::noop_waker_ref;
8+
use pki_types::ServerName;
89
use rustls::{ClientConnection, Connection, ServerConnection};
910
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf};
1011

@@ -294,7 +295,7 @@ fn make_pair() -> (ServerConnection, ClientConnection) {
294295
let (sconfig, cconfig) = utils::make_configs();
295296
let server = ServerConnection::new(Arc::new(sconfig)).unwrap();
296297

297-
let domain = pki_types::ServerName::try_from("foobar.com").unwrap();
298+
let domain = ServerName::try_from("foobar.com").unwrap();
298299
let client = ClientConnection::new(Arc::new(cconfig), domain).unwrap();
299300

300301
(server, client)

src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ use std::sync::Arc;
4747
use std::task::{Context, Poll};
4848

4949
pub use rustls;
50+
51+
use pki_types::ServerName;
5052
use rustls::server::AcceptedAlert;
5153
use rustls::{ClientConfig, ClientConnection, CommonState, ServerConfig, ServerConnection};
5254
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
@@ -107,19 +109,14 @@ impl TlsConnector {
107109
}
108110

109111
#[inline]
110-
pub fn connect<IO>(&self, domain: pki_types::ServerName<'static>, stream: IO) -> Connect<IO>
112+
pub fn connect<IO>(&self, domain: ServerName<'static>, stream: IO) -> Connect<IO>
111113
where
112114
IO: AsyncRead + AsyncWrite + Unpin,
113115
{
114116
self.connect_with(domain, stream, |_| ())
115117
}
116118

117-
pub fn connect_with<IO, F>(
118-
&self,
119-
domain: pki_types::ServerName<'static>,
120-
stream: IO,
121-
f: F,
122-
) -> Connect<IO>
119+
pub fn connect_with<IO, F>(&self, domain: ServerName<'static>, stream: IO, f: F) -> Connect<IO>
123120
where
124121
IO: AsyncRead + AsyncWrite + Unpin,
125122
F: FnOnce(&mut ClientConnection),

tests/badssl.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ use std::io;
22
use std::net::ToSocketAddrs;
33
use std::sync::Arc;
44

5+
use pki_types::ServerName;
6+
use rustls::ClientConfig;
57
use tokio::io::{AsyncReadExt, AsyncWriteExt};
68
use tokio::net::TcpStream;
7-
use tokio_rustls::{
8-
client::TlsStream,
9-
rustls::{self, ClientConfig},
10-
TlsConnector,
11-
};
9+
use tokio_rustls::client::TlsStream;
10+
use tokio_rustls::TlsConnector;
1211

1312
async fn get(
1413
config: Arc<ClientConfig>,
@@ -20,7 +19,7 @@ async fn get(
2019
let input = format!("GET / HTTP/1.0\r\nHost: {}\r\n\r\n", domain);
2120

2221
let addr = (domain, port).to_socket_addrs()?.next().unwrap();
23-
let domain = pki_types::ServerName::try_from(domain).unwrap().to_owned();
22+
let domain = ServerName::try_from(domain).unwrap().to_owned();
2423
let mut buf = Vec::new();
2524

2625
let stream = TcpStream::connect(&addr).await?;

tests/early-data.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ use std::task::{Context, Poll};
88
use std::thread;
99

1010
use futures_util::{future::Future, ready};
11+
use pki_types::ServerName;
1112
use rustls::{self, ClientConfig, ServerConnection, Stream};
1213
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWriteExt, ReadBuf};
1314
use tokio::net::TcpStream;
14-
use tokio_rustls::{client::TlsStream, TlsConnector};
15+
use tokio_rustls::client::TlsStream;
16+
use tokio_rustls::TlsConnector;
1517

1618
struct Read1<T>(T);
1719

@@ -41,7 +43,7 @@ async fn send(
4143
) -> io::Result<(TlsStream<TcpStream>, Vec<u8>)> {
4244
let connector = TlsConnector::from(config).early_data(true);
4345
let stream = TcpStream::connect(&addr).await?;
44-
let domain = pki_types::ServerName::try_from("foobar.com").unwrap();
46+
let domain = ServerName::try_from("foobar.com").unwrap();
4547

4648
let mut stream = connector.connect(domain, stream).await?;
4749
utils::write(&mut stream, data, vectored).await?;

tests/test.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{io, thread};
77

88
use futures_util::future::TryFutureExt;
99
use lazy_static::lazy_static;
10+
use pki_types::ServerName;
1011
use rustls::ClientConfig;
1112
use tokio::io::{copy, split, AsyncReadExt, AsyncWriteExt};
1213
use tokio::net::{TcpListener, TcpStream};
@@ -64,7 +65,7 @@ lazy_static! {
6465
async fn start_client(addr: SocketAddr, domain: &str, config: Arc<ClientConfig>) -> io::Result<()> {
6566
const FILE: &[u8] = include_bytes!("../README.md");
6667

67-
let domain = pki_types::ServerName::try_from(domain).unwrap().to_owned();
68+
let domain = ServerName::try_from(domain).unwrap().to_owned();
6869
let config = TlsConnector::from(config);
6970
let mut buf = vec![0; FILE.len()];
7071

@@ -112,9 +113,7 @@ async fn test_lazy_config_acceptor() -> io::Result<()> {
112113
let (sconfig, cconfig) = utils::make_configs();
113114

114115
let (cstream, sstream) = tokio::io::duplex(1200);
115-
let domain = pki_types::ServerName::try_from("foobar.com")
116-
.unwrap()
117-
.to_owned();
116+
let domain = ServerName::try_from("foobar.com").unwrap().to_owned();
118117
tokio::spawn(async move {
119118
let connector = crate::TlsConnector::from(Arc::new(cconfig));
120119
let mut client = connector.connect(domain, cstream).await.unwrap();

0 commit comments

Comments
 (0)