Skip to content

Commit

Permalink
Return error for InvalidDnsNameError, don't panic (#436)
Browse files Browse the repository at this point in the history
Can't provide src for the error as rustls 0.20 didn't implement stdlib Error for it; it's on main and targeted for 0.20.1.
  • Loading branch information
AlyoshaVasilieva committed Nov 13, 2021
1 parent dbc52eb commit 31dd673
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,10 @@ pub(crate) fn connect_https(unit: &Unit, hostname: &str) -> Result<Stream, Error
let mut sock = connect_host(unit, hostname, port)?;
let mut sess = rustls::ClientConnection::new(
tls_conf,
rustls::ServerName::try_from(hostname).expect("invalid DNS name"),
rustls::ServerName::try_from(hostname).map_err(|_e| ErrorKind::Dns.new())?,
)
.map_err(|e| ErrorKind::Io.new().src(e))?;
// TODO rustls 0.20.1: Add src to ServerName error (0.20 didn't implement StdError trait for it)

sess.complete_io(&mut sock)
.map_err(|err| ErrorKind::ConnectionFailed.new().src(err))?;
Expand Down

0 comments on commit 31dd673

Please sign in to comment.