1
//! Stub types to provide in place of an unimplemented TLS server-side implementation.
2

            
3
use std::{borrow::Cow, io::Result as IoResult, pin::Pin, task::Context};
4

            
5
use async_trait::async_trait;
6
use futures::{AsyncRead, AsyncWrite};
7

            
8
use crate::{CertifiedConn, StreamOps, tls::TlsConnector};
9

            
10
/// A [`TlsConnector`] or stream that can never be constructed or returned.
11
#[derive(Clone, Debug)]
12
pub struct UnimplementedTls(void::Void);
13

            
14
#[async_trait]
15
impl<S: Send + 'static> TlsConnector<S> for UnimplementedTls {
16
    type Conn = UnimplementedTls;
17

            
18
    async fn negotiate_unvalidated(&self, _stream: S, _sni_hostname: &str) -> IoResult<Self::Conn> {
19
        void::unreachable(self.0)
20
    }
21
}
22

            
23
impl CertifiedConn for UnimplementedTls {
24
    fn export_keying_material(
25
        &self,
26
        _len: usize,
27
        _label: &[u8],
28
        _context: Option<&[u8]>,
29
    ) -> IoResult<Vec<u8>> {
30
        void::unreachable(self.0)
31
    }
32

            
33
    fn peer_certificate(&self) -> IoResult<Option<Cow<'_, [u8]>>> {
34
        void::unreachable(self.0)
35
    }
36

            
37
    fn own_certificate(&self) -> IoResult<Option<Cow<'_, [u8]>>> {
38
        void::unreachable(self.0)
39
    }
40
}
41

            
42
impl AsyncRead for UnimplementedTls {
43
    fn poll_read(
44
        self: Pin<&mut Self>,
45
        _cx: &mut Context<'_>,
46
        _buf: &mut [u8],
47
    ) -> std::task::Poll<IoResult<usize>> {
48
        void::unreachable(self.0)
49
    }
50
}
51
impl AsyncWrite for UnimplementedTls {
52
    fn poll_write(
53
        self: Pin<&mut Self>,
54
        _cx: &mut Context<'_>,
55
        _buf: &[u8],
56
    ) -> std::task::Poll<IoResult<usize>> {
57
        void::unreachable(self.0)
58
    }
59

            
60
    fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> std::task::Poll<IoResult<()>> {
61
        void::unreachable(self.0)
62
    }
63

            
64
    fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> std::task::Poll<IoResult<()>> {
65
        void::unreachable(self.0)
66
    }
67
}
68
impl StreamOps for UnimplementedTls {
69
    fn set_tcp_notsent_lowat(&self, _notsent_lowat: u32) -> IoResult<()> {
70
        void::unreachable(self.0)
71
    }
72

            
73
    fn new_handle(&self) -> Box<dyn StreamOps + Send + Unpin> {
74
        void::unreachable(self.0)
75
    }
76
}