mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
tokio-xmpp: Error out when both tls-native and tls-rust features are enabled
If the user enables the tls-rust feature and forgets to disable default-features (which includes tls-native), tell them and bail out. The code was made to work anyway when both are enabled, and here it defaults to tls-native. It does seem better to have one explicitely choose one though hence the compile_error! message. Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
fc16b7919b
commit
a16f670ee6
5 changed files with 12 additions and 9 deletions
|
@ -7,7 +7,7 @@ use tokio::net::TcpStream;
|
|||
use tokio::task::JoinHandle;
|
||||
#[cfg(feature = "tls-native")]
|
||||
use tokio_native_tls::TlsStream;
|
||||
#[cfg(feature = "tls-rust")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
use tokio_rustls::client::TlsStream;
|
||||
use xmpp_parsers::{ns, Element, Jid};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::task::{Context, Poll};
|
|||
use tokio::net::TcpStream;
|
||||
#[cfg(feature = "tls-native")]
|
||||
use tokio_native_tls::TlsStream;
|
||||
#[cfg(feature = "tls-rust")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
use tokio_rustls::client::TlsStream;
|
||||
use tokio_stream::StreamExt;
|
||||
use xmpp_parsers::{ns, Element, Jid};
|
||||
|
|
|
@ -6,9 +6,9 @@ use std::error::Error as StdError;
|
|||
use std::fmt;
|
||||
use std::io::Error as IoError;
|
||||
use std::str::Utf8Error;
|
||||
#[cfg(feature = "tls-rust")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
use tokio_rustls::rustls::client::InvalidDnsNameError;
|
||||
#[cfg(feature = "tls-rust")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
use tokio_rustls::rustls::Error as TlsError;
|
||||
use trust_dns_proto::error::ProtoError;
|
||||
use trust_dns_resolver::error::ResolveError;
|
||||
|
@ -34,7 +34,7 @@ pub enum Error {
|
|||
Auth(AuthError),
|
||||
/// TLS error
|
||||
Tls(TlsError),
|
||||
#[cfg(feature = "tls-rust")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
/// DNS name parsing error
|
||||
DnsNameError(InvalidDnsNameError),
|
||||
/// Connection closed
|
||||
|
@ -57,7 +57,7 @@ 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")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
Error::DnsNameError(e) => write!(fmt, "DNS name error: {}", e),
|
||||
Error::Disconnected => write!(fmt, "disconnected"),
|
||||
Error::InvalidState => write!(fmt, "invalid state"),
|
||||
|
@ -117,7 +117,7 @@ impl From<Utf8Error> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls-rust")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
impl From<InvalidDnsNameError> for Error {
|
||||
fn from(e: InvalidDnsNameError) -> Self {
|
||||
Error::DnsNameError(e)
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#![deny(unsafe_code, missing_docs, bare_trait_objects)]
|
||||
|
||||
#[cfg(all(feature = "tls-native", feature = "tls-rust"))]
|
||||
compile_error!("Both tls-native and tls-rust features can't be enabled at the same time.");
|
||||
|
||||
mod starttls;
|
||||
mod stream_start;
|
||||
mod xmpp_codec;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use futures::{sink::SinkExt, stream::StreamExt};
|
||||
|
||||
#[cfg(feature = "tls-rust")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
use {
|
||||
std::convert::TryFrom,
|
||||
std::sync::Arc,
|
||||
|
@ -37,7 +37,7 @@ async fn get_tls_stream<S: AsyncRead + AsyncWrite + Unpin>(
|
|||
Ok(tls_stream)
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls-rust")]
|
||||
#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
|
||||
async fn get_tls_stream<S: AsyncRead + AsyncWrite + Unpin>(
|
||||
xmpp_stream: XMPPStream<S>,
|
||||
) -> Result<TlsStream<S>, Error> {
|
||||
|
|
Loading…
Reference in a new issue