1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::AsyncSocket;
use crate::ImplInfo;

/// Trait implemented by all `TlsStream` objects.
///
/// Provide access to some TLS stream properties (only ALPN at the moment.)
pub trait TlsStreamDyn: AsyncSocket {
    /// Get negotiated ALPN protocol negotiated.
    fn get_alpn_protocol(&self) -> crate::Result<Option<Vec<u8>>>;

    /// Implementation info for this stream (e. g. which crate provides it).
    fn impl_info(&self) -> ImplInfo;

    /// Get the underlying socket.
    fn get_socket_dyn_mut(&mut self) -> &mut dyn AsyncSocket;

    /// Get the underlying socket.
    fn get_socket_dyn_ref(&self) -> &dyn AsyncSocket;
}

/// Get the underlying socket.
pub trait TlsStreamWithSocketDyn<S>: TlsStreamDyn {
    /// Get the underlying socket.
    fn get_socket_mut(&mut self) -> &mut S;

    /// Get the underlying socket.
    fn get_socket_ref(&self) -> &S;
}

/// Interface upcast. This is an interface for API implementors.
pub trait TlsStreamWithUpcastDyn<S>: TlsStreamWithSocketDyn<S> {
    /// Upcast.
    fn upcast_box(self: Box<Self>) -> Box<dyn TlsStreamDyn>;
}