Commit 2bbd01b0 authored by Ian Jackson's avatar Ian Jackson
Browse files

tor-rtcompat: Provide TLS wrapping for all streams

Now all of the runtime types we provide all
  impl<S> TlsProvider<S> where S: ...
rather than merely TlsProvider<Self::TcpStream>.

And we document and intent to perhaps require this in the future.
parent e62afdf7
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ use std::io::Result as IoResult;
use crate::impls::native_tls::NativeTlsProvider;
#[cfg(feature = "rustls")]
use crate::impls::rustls::RustlsProvider;
use async_std_crate::net::TcpStream;

use async_executors::AsyncStd;

@@ -36,7 +35,7 @@ pub struct AsyncStdNativeTlsRuntime {

/// Implementation type for AsyncStdRuntime.
#[cfg(all(feature = "native-tls"))]
type NativeTlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, NativeTlsProvider<TcpStream>>;
type NativeTlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, NativeTlsProvider>;

#[cfg(all(feature = "native-tls"))]
crate::opaque::implement_opaque_runtime! {
@@ -53,7 +52,7 @@ pub struct AsyncStdRustlsRuntime {

/// Implementation type for AsyncStdRustlsRuntime.
#[cfg(feature = "rustls")]
type RustlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, RustlsProvider<TcpStream>>;
type RustlsInner = CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, RustlsProvider>;

#[cfg(feature = "rustls")]
crate::opaque::implement_opaque_runtime! {
+2 −3
Original line number Diff line number Diff line
@@ -118,11 +118,10 @@ where
    }
}

impl<SpawnR, SleepR, TcpR, TlsR> TlsProvider<TcpR::TcpStream>
    for CompoundRuntime<SpawnR, SleepR, TcpR, TlsR>
impl<SpawnR, SleepR, TcpR, TlsR, S> TlsProvider<S> for CompoundRuntime<SpawnR, SleepR, TcpR, TlsR>
where
    TcpR: TcpProvider,
    TlsR: TlsProvider<TcpR::TcpStream>,
    TlsR: TlsProvider<S>,
{
    type Connector = TlsR::Connector;
    type TlsStream = TlsR::TlsStream;
+5 −10
Original line number Diff line number Diff line
@@ -14,10 +14,7 @@ use std::{
///
/// It supports wrapping any reasonable stream type that implements `AsyncRead` + `AsyncWrite`.
#[non_exhaustive]
pub struct NativeTlsProvider<S> {
    /// Phantom data to ensure proper variance.
    _phantom: std::marker::PhantomData<fn(S) -> S>,
}
pub struct NativeTlsProvider {}

impl<S> CertifiedConn for async_native_tls::TlsStream<S>
where
@@ -63,7 +60,7 @@ where
    }
}

impl<S> TlsProvider<S> for NativeTlsProvider<S>
impl<S> TlsProvider<S> for NativeTlsProvider
where
    S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
@@ -90,16 +87,14 @@ where
    }
}

impl<S> NativeTlsProvider<S> {
impl NativeTlsProvider {
    /// Construct a new [`NativeTlsProvider`.]
    pub(crate) fn new() -> Self {
        NativeTlsProvider {
            _phantom: std::marker::PhantomData,
        }
        NativeTlsProvider {}
    }
}

impl<S> Default for NativeTlsProvider<S> {
impl Default for NativeTlsProvider {
    fn default() -> Self {
        Self::new()
    }
+4 −7
Original line number Diff line number Diff line
@@ -16,11 +16,9 @@ use std::{
///
/// It supports wrapping any reasonable stream type that implements `AsyncRead` + `AsyncWrite`.
#[non_exhaustive]
pub struct RustlsProvider<S> {
pub struct RustlsProvider {
    /// Inner `ClientConfig` logic used to create connectors.
    config: Arc<async_rustls::rustls::ClientConfig>,
    /// Phantom data to ensure proper variance.
    _phantom: std::marker::PhantomData<fn(S) -> S>,
}

impl<S> CertifiedConn for async_rustls::client::TlsStream<S> {
@@ -53,7 +51,7 @@ where
    }
}

impl<S> TlsProvider<S> for RustlsProvider<S>
impl<S> TlsProvider<S> for RustlsProvider
where
    S: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
@@ -70,7 +68,7 @@ where
    }
}

impl<S> RustlsProvider<S> {
impl RustlsProvider {
    /// Construct a new [`RustlsProvider`.]
    pub(crate) fn new() -> Self {
        let mut config = async_rustls::rustls::ClientConfig::new();
@@ -89,12 +87,11 @@ impl<S> RustlsProvider<S> {

        RustlsProvider {
            config: Arc::new(config),
            _phantom: std::marker::PhantomData,
        }
    }
}

impl<S> Default for RustlsProvider<S> {
impl Default for RustlsProvider {
    fn default() -> Self {
        Self::new()
    }
+5 −3
Original line number Diff line number Diff line
@@ -46,9 +46,11 @@ macro_rules! implement_opaque_runtime {
        }
    }

    impl $crate::traits::TlsProvider<<$t as $crate::traits::TcpProvider>::TcpStream> for $t {
        type Connector = <$mty as $crate::traits::TlsProvider<<$t as $crate::traits::TcpProvider>::TcpStream>>::Connector;
        type TlsStream = <$mty as $crate::traits::TlsProvider<<$t as $crate::traits::TcpProvider>::TcpStream>>::TlsStream;
    impl<S> $crate::traits::TlsProvider<S> for $t
    where S: futures::AsyncRead + futures::AsyncWrite + Unpin + Send + 'static,
    {
        type Connector = <$mty as $crate::traits::TlsProvider<S>>::Connector;
        type TlsStream = <$mty as $crate::traits::TlsProvider<S>>::TlsStream;
        #[inline]
        fn tls_connector(&self) -> Self::Connector {
            self.$member.tls_connector()
Loading