[−][src]Struct tokio_libtls::TlsStream
Wrapper for async I/O operations with Tls
.
Methods
impl TlsStream
[src]
pub fn new(tls: Tls, tcp: TcpStream) -> Self
[src]
Create new TlsStream
from Tls
object and TcpStream
.
Methods from Deref<Target = Tls>
pub fn configure(&mut self, config: &TlsConfig) -> Result<(), TlsError>
[src]
Configure the TLS context.
The configure
method configures a TLS connection. The
same TlsConfig
object can be used to configure multiple
contexts.
See also
pub fn reset(&mut self)
[src]
pub fn accept_fds(
&mut self,
fd_read: i32,
fd_write: i32
) -> Result<Tls, TlsError>
[src]
&mut self,
fd_read: i32,
fd_write: i32
) -> Result<Tls, TlsError>
Accept a new TLS connection on a pair of existing file descriptors.
The accept_fds
method can accept a new client connection on a pair
of existing file descriptors.
See also
pub fn accept_socket(&mut self, socket: i32) -> Result<Tls, TlsError>
[src]
Accept a new TLS connection on a socket.
The accept_socket
method can accept a new client
connection on an already established
socket connection.
The socket RawFd
is not closed after dropping the object.
See also
pub fn accept_raw_fd<T>(&mut self, raw_fd: &T) -> Result<Tls, TlsError> where
T: AsRawFd,
[src]
T: AsRawFd,
Accept a new TLS connection on an established connection.
The accept_raw_fd
method can accept a new client connection on an
already established connection that implements the AsRawFd
trait,
e.g. TcpStream
.
It is a wrapper function on top of accept_socket
.
See also
pub unsafe fn accept_cbs(
&mut self,
read_cb: Option<unsafe extern "C" fn(*mut tls, *mut c_void, usize, *mut c_void) -> isize>,
write_cb: Option<unsafe extern "C" fn(*mut tls, *const c_void, usize, *mut c_void) -> isize>,
cb_arg: Option<*mut c_void>
) -> Result<Tls, TlsError>
[src]
&mut self,
read_cb: Option<unsafe extern "C" fn(*mut tls, *mut c_void, usize, *mut c_void) -> isize>,
write_cb: Option<unsafe extern "C" fn(*mut tls, *const c_void, usize, *mut c_void) -> isize>,
cb_arg: Option<*mut c_void>
) -> Result<Tls, TlsError>
Accept a new TLS connection with custom I/O callbacks.
The accept_cbs
method allows read and write callback functions to
handle data transfers. The specified cb_arg
parameter is passed back to
the functions, and can contain a pointer to any caller-specified data.
See also
pub fn connect(
&mut self,
host: &str,
port: Option<&str>
) -> Result<(), TlsError>
[src]
&mut self,
host: &str,
port: Option<&str>
) -> Result<(), TlsError>
Initiate a new TLS connection.
The connect
method initiates a new client connection on a
Tls
object that has been configured with configure
.
This method will create a new socket, connect to the specified host and port,
and then establish a secure connection. The port may be numeric or a
service name. If it is None, then a host of the format "hostname:port"
is permitted. The name to use for verification is inferred from the host value.
See also
pub fn connect_fds(
&mut self,
fd_read: i32,
fd_write: i32,
servername: &str
) -> Result<(), TlsError>
[src]
&mut self,
fd_read: i32,
fd_write: i32,
servername: &str
) -> Result<(), TlsError>
Initiate a new TLS connection over a pair of existing file descriptors.
The connect_fds
method is a variant of connect
that
establishes a secure connection over a pair of existing file
descriptors. The servername
argument is used for verification of
the TLS server name.
See also
pub fn connect_servername<A>(
&mut self,
host: A,
servername: &str
) -> Result<(), TlsError> where
A: ToSocketAddrs,
[src]
&mut self,
host: A,
servername: &str
) -> Result<(), TlsError> where
A: ToSocketAddrs,
Initiate a new TLS connection with a specified server name.
The connect_servername
method has the same behaviour as connect
,
however the name to use for verification is explicitly provided,
for the case where the TLS server name differs from the DNS name.
See also
pub fn connect_socket(
&mut self,
socket: i32,
servername: &str
) -> Result<(), TlsError>
[src]
&mut self,
socket: i32,
servername: &str
) -> Result<(), TlsError>
Initiate a new TLS connection over an established socket.
The connect_socket
method is a variant of connect_servername
that
can upgrade an already existing socket to TLS.
The socket RawFd
is not closed after dropping the object.
See also
pub fn connect_raw_fd<T>(
&mut self,
raw_fd: &T,
servername: &str
) -> Result<(), TlsError> where
T: AsRawFd,
[src]
&mut self,
raw_fd: &T,
servername: &str
) -> Result<(), TlsError> where
T: AsRawFd,
Initiate a new TLS connection over an established connection.
The connect_raw_fd
method can upgrade a connection to TLS on an
already established connection that implements the [AsRawFd] trait, e.g. [
TcpStream]. It is a wrapper function on top of [
connect_socket`].
See also
pub unsafe fn connect_cbs(
&mut self,
read_cb: Option<unsafe extern "C" fn(*mut tls, *mut c_void, usize, *mut c_void) -> isize>,
write_cb: Option<unsafe extern "C" fn(*mut tls, *const c_void, usize, *mut c_void) -> isize>,
cb_arg: Option<*mut c_void>,
servername: &str
) -> Result<(), TlsError>
[src]
&mut self,
read_cb: Option<unsafe extern "C" fn(*mut tls, *mut c_void, usize, *mut c_void) -> isize>,
write_cb: Option<unsafe extern "C" fn(*mut tls, *const c_void, usize, *mut c_void) -> isize>,
cb_arg: Option<*mut c_void>,
servername: &str
) -> Result<(), TlsError>
Initiate a new TLS connection with custom I/O callbacks.
The connect_cbs
method allows read and write callback functions to
handle data transfers. The specified cb_arg
parameter is passed back to
the functions, and can contain a pointer to any caller-specified data.
The servername
is used to validate the TLS server name.
See also
pub fn tls_handshake(&mut self) -> Result<isize, TlsError>
[src]
Explicitly perform the TLS handshake.
The tls_handshake
method explicitly performs the TLS handshake. It is only
necessary to call this method if you need to guarantee that the
handshake has completed, as both tls_read
and tls_write
automatically
perform the TLS handshake when necessary.
The tls_read
, tls_write
, tls_handshake
, and tls_close
methods
return -1 on error and also have two special return values:
TLS_WANT_POLLIN
: The underlying read file descriptor needs to be readable in order to continue.TLS_WANT_POLLOUT
: The underlying write file descriptor needs to be writeable in order to continue.
In the case of blocking file descriptors, the same function call should be repeated immediately. In the case of non-blocking file descriptors, the same function call should be repeated when the required condition has been met.
On success, the tls_read
and tls_write
methods return a size and
the tls_handshake
and tls_close
methods return 0.
See also
pub fn tls_read(&mut self, buf: &mut [u8]) -> Result<isize, TlsError>
[src]
Read bytes from the TLS connection.
The tls_read
method reads bytes of data from the connection into buf
. It
returns the amount of data read or an error as described in tls_handshake
.
This function is provided for the completeness of the API, programs should
use the implemented read
function of the Read
trait instead.
See also
pub fn tls_write(&mut self, buf: &[u8]) -> Result<isize, TlsError>
[src]
Write bytes to the TLS connection.
The tls_write
method writes bytes of data from buf
to connection. It
returns the amount of data written or an error as described in tls_handshake
.
This function is provided for the completeness of the API, programs should
use the implemented write
function of the Write
trait instead.
See also
pub fn tls_close(&mut self) -> Result<isize, TlsError>
[src]
Close the TLS connection.
The tls_close
method closes a connection after use. Only the TLS layer will be
shut down and the caller is responsible for closing the file descriptors,
unless the connection was established using connect
or
connect_servername
.
It returns 0 on success or an error as decribed in tls_handshake
.
See also
pub fn close(&mut self) -> Result<(), Error>
[src]
Close the TLS connection.
The close
method closes a connection after use.
It calls tls_close
and converts the result into an io::Error
.
See also
pub fn peer_cert_provided(&mut self) -> bool
[src]
Check for peer certificate.
The peer_cert_provided
methods checks if the peer has provided a
certificate.
See also
pub fn peer_cert_contains_name(&mut self, name: &str) -> Result<bool, TlsError>
[src]
Check if the peer certificate includes a matching name.
The peer_cert_contains_name
method checks if the peer has
provided a certificate that contains a SAN or CN that matches name.
See also
pub fn peer_cert_hash(&mut self) -> Result<String, TlsError>
[src]
Return hash of the peer certificate.
The peer_cert_hash
method returns a string corresponding to a hash
of the raw peer certificate prefixed by a hash name followed by a colon.
The hash currently used is SHA256, though this could change in the
future.
The hash string for a certificate in file mycert.crt
can be
generated using the commands:
h=$(openssl x509 -outform der -in mycert.crt | sha256)
printf "SHA256:${h}\n"
See also
pub fn peer_cert_issuer(&mut self) -> Result<String, TlsError>
[src]
Return the issuer of the peer certificate.
The peer_cert_issuer
method returns a string corresponding to the issuer of
the peer certificate.
See also
pub fn peer_cert_subject(&mut self) -> Result<String, TlsError>
[src]
Return the subject of the peer certificate.
The peer_cert_subject
method returns a string corresponding to the subject of
the peer certificate.
See also
pub fn peer_cert_notbefore(&mut self) -> Result<SystemTime, TlsError>
[src]
Return the start of the validity period of the peer certififcate.
The peer_cert_notbefore
method returns the time corresponding to the start of
the validity period of the peer certificate.
See also
pub fn peer_cert_notafter(&mut self) -> Result<SystemTime, TlsError>
[src]
Return the end of the validity period of the peer certififcate.
The peer_cert_notafter
method returns the time corresponding to the end of
the validity period of the peer certificate.
The peer_cert_notafter
method
See also
pub fn peer_cert_chain_pem(&mut self) -> Result<Vec<u8>, TlsError>
[src]
Return the PEM-encoded peer certificate.
The peer_cert_chain_pem
method returns a vector of memory containing a PEM-
encoded certificate chain for the peer certificate.
See also
pub fn conn_alpn_selected(&mut self) -> Option<String>
[src]
Return the selected ALPN protocol.
The conn_alpn_selected
method returns a string that specifies the ALPN
protocol selected for use with the peer. If no protocol
was selected then None
is returned.
See also
pub fn conn_cipher(&mut self) -> Result<String, TlsError>
[src]
Return the negotiated cipher suite.
The conn_cipher
method returns a string corresponding to the cipher suite
negotiated with the peer.
See also
pub fn conn_servername(&mut self) -> Result<String, TlsError>
[src]
Return the client's server name.
The conn_servername
method returns a string corresponding to the servername
that the client connected to the server requested by sending a TLS Server Name
Indication extension (server only).
See also
pub fn conn_session_resumed(&mut self) -> bool
[src]
Check if a TLS session has been resumed.
The conn_session_resumed
method indicates whether a TLS session has been
resumed during the handshake with the server connected to the client (client
only).
See also
pub fn conn_version(&mut self) -> Result<String, TlsError>
[src]
Return the negotiated TLS version as a string.
The conn_version
method returns a string corresponding to a TLS version
negotiated with the peer.
See also
pub fn ocsp_process_response(&mut self, response: &[u8]) -> Result<(), TlsError>
[src]
Process a raw OCSP response.
The ocsp_process_response
method processes a raw OCSP response in response of
size size to check the revocation status of the peer certificate.
A successful result indicates that the certificate has not been revoked.
See also
pub fn peer_ocsp_cert_status(&mut self) -> Result<isize, TlsError>
[src]
OCSP certificate status.
The peer_ocsp_cert_status
method returns the OCSP certificate status code as
per RFC 6960 section 2.2.
See also
pub fn peer_ocsp_crl_reason(&mut self) -> Result<isize, TlsError>
[src]
OCSP certificate revocation reason.
The peer_ocsp_crl_reason
method returns the OCSP certificate revocation reason
status code as per RFC 5280 section 5.3.1.
See also
pub fn peer_ocsp_next_update(&mut self) -> Result<SystemTime, TlsError>
[src]
pub fn peer_ocsp_response_status(&mut self) -> Result<isize, TlsError>
[src]
OCSP response status.
The peer_ocsp_response_status
method returns the OCSP response status as per
RFC 6960 section 2.3.
See also
pub fn peer_ocsp_result(&mut self) -> Result<String, TlsError>
[src]
Textual representation of the OCSP status code.
The peer_ocsp_result
method returns a textual representation of the OCSP
status code returned by one of the previous three functions. If the OCSP
response was valid and the certificate was not revoked, the string
indicates the OCSP certificate status. Otherwise, the string indicates
the OCSP certificate revocation reason or the OCSP error.
See also
pub fn peer_ocsp_revocation_time(&mut self) -> Result<SystemTime, TlsError>
[src]
OCSP revocation time.
The peer_ocsp_revocation_time
method returns the OCSP revocation time.
See also
pub fn peer_ocsp_this_update(&mut self) -> Result<SystemTime, TlsError>
[src]
pub fn peer_ocsp_url(&mut self) -> Result<String, TlsError>
[src]
OCSP validation URL.
The peer_ocsp_url
method returns the URL for OCSP validation of the peer
certificate.
See also
Trait Implementations
impl DerefMut for TlsStream
[src]
impl Deref for TlsStream
[src]
impl Debug for TlsStream
[src]
impl Read for TlsStream
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>
1.36.0[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
ⓘImportant traits for &'_ mut Ffn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
impl Write for TlsStream
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>
1.36.0[src]
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
ⓘImportant traits for &'_ mut Ffn by_ref(&mut self) -> &mut Self
1.0.0[src]
impl AsRawFd for TlsStream
[src]
impl AsyncWrite for TlsStream
[src]
fn poll_write(
self: Pin<&mut Self>,
_cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_flush(
self: Pin<&mut Self>,
_cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context
) -> Poll<Result<(), Error>>
fn poll_close(
self: Pin<&mut Self>,
_cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context
) -> Poll<Result<(), Error>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
impl AsyncRead for TlsStream
[src]
fn poll_read(
self: Pin<&mut Self>,
_cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
impl Evented for TlsStream
[src]
Auto Trait Implementations
impl Send for TlsStream
impl Unpin for TlsStream
impl Sync for TlsStream
impl !UnwindSafe for TlsStream
impl !RefUnwindSafe for TlsStream
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Ffn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
[src]
W: AsyncWrite + ?Sized,
ⓘImportant traits for Flush<'_, W>fn flush(&mut self) -> Flush<Self> where
Self: Unpin,
[src]
Self: Unpin,
ⓘImportant traits for Close<'_, W>fn close(&mut self) -> Close<Self> where
Self: Unpin,
[src]
Self: Unpin,
ⓘImportant traits for Write<'_, W>fn write(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
ⓘImportant traits for WriteVectored<'_, W>fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self> where
Self: Unpin,
ⓘImportant traits for WriteAll<'_, W>fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn into_sink<Item>(self) -> IntoSink<Self, Item> where
Item: AsRef<[u8]>,
[src]
Item: AsRef<[u8]>,
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
[src]
R: AsyncRead + ?Sized,
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
[src]
R: AsyncRead,
ⓘImportant traits for Read<'_, R>fn read(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
ⓘImportant traits for ReadVectored<'_, R>fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> where
Self: Unpin,
ⓘImportant traits for ReadExact<'_, R>fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
ⓘImportant traits for ReadToEnd<'_, A>fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
ⓘImportant traits for ReadToString<'_, A>fn read_to_string(&'a mut self, buf: &'a mut String) -> ReadToString<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>) where
Self: AsyncWrite,
[src]
Self: AsyncWrite,