tokio-xmpp: gate AsRawFd behind ktls feature

`AsRawFd` was breaking compilation on Windows.

skip-changelog: ktls support hasn't been released yet

Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
Alexander Brook Perry 2025-12-05 15:03:11 +00:00 committed by Link Mauve
commit b046d36424
2 changed files with 21 additions and 18 deletions

View file

@ -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 `<starttls/>` on an XmppStream and returns a binary
/// TlsStream.
pub async fn starttls<S: AsyncRead + AsyncWrite + Unpin + AsRawFd>(
pub async fn starttls<S: TlsAsyncStream>(
mut stream: XmppStream<BufStream<S>>,
domain: &str,
) -> Result<(TlsStream<S>, ChannelBinding), Error> {

View file

@ -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<T: AsyncRead + AsyncWrite + Unpin + AsRawFd> 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<T: AsyncRead + AsyncWrite + Unpin> TlsAsyncStream for T {}
#[cfg(feature = "native-tls")]
use native_tls::Error as TlsError;
#[cfg(feature = "rustls-any-backend")]
@ -92,13 +105,10 @@ impl From<InvalidDnsNameError> for TlsConnectorError {
/// Establish TLS connection using native-tls
#[cfg(feature = "native-tls")]
pub async fn establish_tls_connection<S>(
pub async fn establish_tls_connection<S: TlsAsyncStream>(
stream: S,
domain: &str,
) -> Result<(TlsStream<S>, ChannelBinding), Error>
where
S: AsyncRead + AsyncWrite + Unpin,
{
) -> Result<(TlsStream<S>, 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<S>(
pub async fn establish_tls_connection<S: TlsAsyncStream>(
stream: S,
domain: &str,
) -> Result<(TlsStream<S>, ChannelBinding), Error>
where
S: AsyncRead + AsyncWrite + Unpin + AsRawFd,
{
) -> Result<(TlsStream<S>, ChannelBinding), Error> {
let domain =
ServerName::try_from(domain.to_owned()).map_err(TlsConnectorError::DnsNameError)?;
let mut root_store = RootCertStore::empty();