mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
tokio-xmpp: Remove an unwrap() in DNS name parsing
This commit is contained in:
parent
4a8bda1287
commit
edba9c9f5d
2 changed files with 15 additions and 1 deletions
|
@ -7,6 +7,8 @@ use std::fmt;
|
|||
use std::io::Error as IoError;
|
||||
use std::str::Utf8Error;
|
||||
#[cfg(feature = "tls-rust")]
|
||||
use tokio_rustls::rustls::client::InvalidDnsNameError;
|
||||
#[cfg(feature = "tls-rust")]
|
||||
use tokio_rustls::rustls::Error as TlsError;
|
||||
use trust_dns_proto::error::ProtoError;
|
||||
use trust_dns_resolver::error::ResolveError;
|
||||
|
@ -32,6 +34,9 @@ pub enum Error {
|
|||
Auth(AuthError),
|
||||
/// TLS error
|
||||
Tls(TlsError),
|
||||
#[cfg(feature = "tls-rust")]
|
||||
/// DNS name parsing error
|
||||
DnsNameError(InvalidDnsNameError),
|
||||
/// Connection closed
|
||||
Disconnected,
|
||||
/// Shoud never happen
|
||||
|
@ -48,6 +53,8 @@ impl fmt::Display for Error {
|
|||
Error::Protocol(e) => write!(fmt, "protocol error: {}", e),
|
||||
Error::Auth(e) => write!(fmt, "authentication error: {}", e),
|
||||
Error::Tls(e) => write!(fmt, "TLS error: {}", e),
|
||||
#[cfg(feature = "tls-rust")]
|
||||
Error::DnsNameError(e) => write!(fmt, "DNS name error: {}", e),
|
||||
Error::Disconnected => write!(fmt, "disconnected"),
|
||||
Error::InvalidState => write!(fmt, "invalid state"),
|
||||
}
|
||||
|
@ -90,6 +97,13 @@ impl From<TlsError> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls-rust")]
|
||||
impl From<InvalidDnsNameError> for Error {
|
||||
fn from(e: InvalidDnsNameError) -> Self {
|
||||
Error::DnsNameError(e)
|
||||
}
|
||||
}
|
||||
|
||||
/// Causes for stream parsing errors
|
||||
#[derive(Debug)]
|
||||
pub enum ParserError {
|
||||
|
|
|
@ -42,7 +42,7 @@ async fn get_tls_stream<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
xmpp_stream: XMPPStream<S>,
|
||||
) -> Result<TlsStream<S>, Error> {
|
||||
let domain = &xmpp_stream.jid.clone().domain();
|
||||
let domain = ServerName::try_from(domain.as_str()).unwrap();
|
||||
let domain = ServerName::try_from(domain.as_str())?;
|
||||
let stream = xmpp_stream.into_inner();
|
||||
let mut root_store = RootCertStore::empty();
|
||||
root_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
|
||||
|
|
Loading…
Reference in a new issue