Compare commits

...

5 Commits

Author SHA1 Message Date
Jacob Rothstein 635ecf075d
Merge pull request #13 from joshtriplett/async-rustls
Switch to async-rustls
2021-03-19 17:44:22 -07:00
Josh Triplett 2990e7d4a0 Switch to async-rustls
tide-rustls is rustls-specific, and using async-rustls will allow users
of tide-rustls to depend on that.
2021-03-19 17:04:39 -07:00
Jacob Rothstein 895760f75e
Merge pull request #12 from joshtriplett/simplification
Drop unused return values of TlsListener::configure and TlsListener::connect
2021-03-19 16:39:58 -07:00
Josh Triplett 0306e915b0 Simplify TlsListener::configure
Now that we no longer need to return the TlsAcceptor, integrate the
error handling into the preceeding match.
2021-03-19 16:32:50 -07:00
Josh Triplett e8ea6d0e0b Drop unused return values of TlsListener::configure and TlsListener::connect
These methods return the TlsAcceptor and TcpListener, respectively,
but the only caller ignores those return values.
2021-03-19 13:09:02 -07:00
5 changed files with 19 additions and 24 deletions

View File

@ -1,9 +1,9 @@
[package]
name = "tide-rustls"
version = "0.2.0"
version = "0.3.0"
authors = ["Jacob Rothstein <hi@jbr.me>"]
edition = "2018"
description = "tide tls listener based on async-tls and rustls"
description = "tide tls listener based on async-rustls and rustls"
readme = "README.md"
repository = "https://github.com/jbr/tide-rustls"
documentation = "https://docs.rs/tide-rustls"
@ -14,7 +14,7 @@ categories = ["web-programming::http-server", "web-programming"]
[dependencies]
async-std = "1.7.0"
tide = { version = "0.16.0", default-features = false }
async-tls = "0.11.0"
async-rustls = "0.2.0"
rustls = "0.19.0"
async-h1 = "2.2.0"
async-dup = "1.2.2"

View File

@ -41,5 +41,5 @@ pub(crate) use tls_stream_wrapper::TlsStreamWrapper;
pub use tls_listener::TlsListener;
pub use tls_listener_builder::TlsListenerBuilder;
pub use async_tls;
pub use async_rustls;
pub use rustls;

View File

@ -8,7 +8,7 @@ use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::*;
use async_std::{io, task};
use async_tls::TlsAcceptor;
use async_rustls::TlsAcceptor;
use rustls::internal::pemfile::{certs, pkcs8_private_keys, rsa_private_keys};
use rustls::{Certificate, NoClientAuth, PrivateKey, ServerConfig};
@ -69,7 +69,7 @@ impl<State> TlsListener<State> {
TlsListenerBuilder::new()
}
async fn configure(&mut self) -> io::Result<TlsAcceptor> {
async fn configure(&mut self) -> io::Result<()> {
self.config = match std::mem::take(&mut self.config) {
TlsListenerConfig::Paths { cert, key } => {
let certs = load_certs(&cert)?;
@ -86,17 +86,17 @@ impl<State> TlsListener<State> {
TlsListenerConfig::Acceptor(TlsAcceptor::from(Arc::new(config)))
}
other => other,
other @ TlsListenerConfig::Acceptor(_) => other,
TlsListenerConfig::Unconfigured => {
return Err(io::Error::new(
io::ErrorKind::Other,
"could not configure tlslistener",
));
}
};
if let TlsListenerConfig::Acceptor(ref a) = self.config {
Ok(a.clone())
} else {
Err(io::Error::new(
io::ErrorKind::Other,
"could not configure tlslistener",
))
}
Ok(())
}
fn acceptor(&self) -> Option<&TlsAcceptor> {
@ -113,17 +113,12 @@ impl<State> TlsListener<State> {
}
}
async fn connect(&mut self) -> io::Result<&TcpListener> {
async fn connect(&mut self) -> io::Result<()> {
if let TcpConnection::Addrs(addrs) = &self.connection {
let tcp = TcpListener::bind(&addrs[..]).await?;
self.connection = TcpConnection::Connected(tcp);
}
if let TcpConnection::Connected(tcp) = &self.connection {
Ok(tcp)
} else {
unreachable!()
}
Ok(())
}
}

View File

@ -1,6 +1,6 @@
use std::fmt::{self, Debug, Formatter};
use async_tls::TlsAcceptor;
use async_rustls::TlsAcceptor;
use rustls::ServerConfig;
use std::path::PathBuf;

View File

@ -1,7 +1,7 @@
use async_dup::{Arc, Mutex};
use async_rustls::server::TlsStream;
use async_std::io::{Read, Result, Write};
use async_std::net::TcpStream;
use async_tls::server::TlsStream;
use std::pin::Pin;
use std::task::{Context, Poll};