diff --git a/tokio-xmpp/src/connect/starttls.rs b/tokio-xmpp/src/connect/starttls.rs
index aa6772d6..9d30fad4 100644
--- a/tokio-xmpp/src/connect/starttls.rs
+++ b/tokio-xmpp/src/connect/starttls.rs
@@ -2,14 +2,10 @@
use alloc::borrow::Cow;
use std::io;
-use std::os::fd::AsRawFd;
use futures::{sink::SinkExt, stream::StreamExt};
use sasl::common::ChannelBinding;
-use tokio::{
- io::{AsyncRead, AsyncWrite, BufStream},
- net::TcpStream,
-};
+use tokio::{io::BufStream, net::TcpStream};
use xmpp_parsers::{
jid::Jid,
starttls::{self, Request},
@@ -17,7 +13,7 @@ use xmpp_parsers::{
use crate::{
connect::{
- tls_common::{establish_tls_connection, TlsConnectorError, TlsStream},
+ tls_common::{establish_tls_connection, TlsAsyncStream, TlsConnectorError, TlsStream},
DnsConfig, ServerConnector,
},
error::{Error, ProtocolError},
@@ -94,7 +90,7 @@ impl ServerConnector for StartTlsServerConnector {
/// Performs `` on an XmppStream and returns a binary
/// TlsStream.
-pub async fn starttls(
+pub async fn starttls(
mut stream: XmppStream>,
domain: &str,
) -> Result<(TlsStream, ChannelBinding), Error> {
diff --git a/tokio-xmpp/src/connect/tls_common.rs b/tokio-xmpp/src/connect/tls_common.rs
index e5dead16..bcf4dd66 100644
--- a/tokio-xmpp/src/connect/tls_common.rs
+++ b/tokio-xmpp/src/connect/tls_common.rs
@@ -7,10 +7,23 @@
//! Common TLS functionality shared between direct_tls and starttls modules
use core::{error::Error as StdError, fmt};
-#[cfg(all(feature = "rustls-any-backend", not(feature = "native-tls")))]
+#[cfg(feature = "ktls")]
use std::os::fd::AsRawFd;
use tokio::io::{AsyncRead, AsyncWrite};
+/// Trait alias for async streams that can be used with TLS.
+// When the `ktls` feature is enabled, this additionally requires `AsRawFd`.
+#[cfg(feature = "ktls")]
+pub trait TlsAsyncStream: AsyncRead + AsyncWrite + Unpin + AsRawFd {}
+#[cfg(feature = "ktls")]
+impl TlsAsyncStream for T {}
+
+/// Trait alias for async streams that can be used with TLS.
+#[cfg(not(feature = "ktls"))]
+pub trait TlsAsyncStream: AsyncRead + AsyncWrite + Unpin {}
+#[cfg(not(feature = "ktls"))]
+impl TlsAsyncStream for T {}
+
#[cfg(feature = "native-tls")]
use native_tls::Error as TlsError;
#[cfg(feature = "rustls-any-backend")]
@@ -92,13 +105,10 @@ impl From for TlsConnectorError {
/// Establish TLS connection using native-tls
#[cfg(feature = "native-tls")]
-pub async fn establish_tls_connection(
+pub async fn establish_tls_connection(
stream: S,
domain: &str,
-) -> Result<(TlsStream, ChannelBinding), Error>
-where
- S: AsyncRead + AsyncWrite + Unpin,
-{
+) -> Result<(TlsStream, ChannelBinding), Error> {
let domain = domain.to_owned();
let tls_stream = TlsConnector::from(NativeTlsConnector::builder().build().unwrap())
.connect(&domain, stream)
@@ -112,13 +122,10 @@ where
/// Establish TLS connection using rustls
#[cfg(all(feature = "rustls-any-backend", not(feature = "native-tls")))]
-pub async fn establish_tls_connection(
+pub async fn establish_tls_connection(
stream: S,
domain: &str,
-) -> Result<(TlsStream, ChannelBinding), Error>
-where
- S: AsyncRead + AsyncWrite + Unpin + AsRawFd,
-{
+) -> Result<(TlsStream, ChannelBinding), Error> {
let domain =
ServerName::try_from(domain.to_owned()).map_err(TlsConnectorError::DnsNameError)?;
let mut root_store = RootCertStore::empty();