Move TlsState to common
This commit is contained in:
parent
a9b20c509c
commit
074fe4a5ac
@ -7,6 +7,59 @@ use tokio::io::{ AsyncRead, AsyncWrite };
|
|||||||
use futures_core as futures;
|
use futures_core as futures;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum TlsState {
|
||||||
|
#[cfg(feature = "early-data")]
|
||||||
|
EarlyData(usize, Vec<u8>),
|
||||||
|
Stream,
|
||||||
|
ReadShutdown,
|
||||||
|
WriteShutdown,
|
||||||
|
FullyShutdown,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TlsState {
|
||||||
|
pub fn shutdown_read(&mut self) {
|
||||||
|
match *self {
|
||||||
|
TlsState::WriteShutdown | TlsState::FullyShutdown => *self = TlsState::FullyShutdown,
|
||||||
|
_ => *self = TlsState::ReadShutdown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn shutdown_write(&mut self) {
|
||||||
|
match *self {
|
||||||
|
TlsState::ReadShutdown | TlsState::FullyShutdown => *self = TlsState::FullyShutdown,
|
||||||
|
_ => *self = TlsState::WriteShutdown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn writeable(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
TlsState::WriteShutdown | TlsState::FullyShutdown => false,
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn readable(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
TlsState::ReadShutdown | TlsState::FullyShutdown => false,
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "early-data")]
|
||||||
|
pub fn is_early_data(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
TlsState::EarlyData(..) => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "early-data"))]
|
||||||
|
pub const fn is_early_data(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Stream<'a, IO, S> {
|
pub struct Stream<'a, IO, S> {
|
||||||
pub io: &'a mut IO,
|
pub io: &'a mut IO,
|
||||||
pub session: &'a mut S,
|
pub session: &'a mut S,
|
||||||
|
55
src/lib.rs
55
src/lib.rs
@ -13,64 +13,11 @@ use futures_core as futures;
|
|||||||
use tokio::io::{ AsyncRead, AsyncWrite };
|
use tokio::io::{ AsyncRead, AsyncWrite };
|
||||||
use webpki::DNSNameRef;
|
use webpki::DNSNameRef;
|
||||||
use rustls::{ ClientConfig, ClientSession, ServerConfig, ServerSession, Session };
|
use rustls::{ ClientConfig, ClientSession, ServerConfig, ServerSession, Session };
|
||||||
use common::Stream;
|
use common::{ Stream, TlsState };
|
||||||
|
|
||||||
pub use rustls;
|
pub use rustls;
|
||||||
pub use webpki;
|
pub use webpki;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum TlsState {
|
|
||||||
#[cfg(feature = "early-data")]
|
|
||||||
EarlyData(usize, Vec<u8>),
|
|
||||||
Stream,
|
|
||||||
ReadShutdown,
|
|
||||||
WriteShutdown,
|
|
||||||
FullyShutdown,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TlsState {
|
|
||||||
fn shutdown_read(&mut self) {
|
|
||||||
match *self {
|
|
||||||
TlsState::WriteShutdown | TlsState::FullyShutdown => *self = TlsState::FullyShutdown,
|
|
||||||
_ => *self = TlsState::ReadShutdown,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn shutdown_write(&mut self) {
|
|
||||||
match *self {
|
|
||||||
TlsState::ReadShutdown | TlsState::FullyShutdown => *self = TlsState::FullyShutdown,
|
|
||||||
_ => *self = TlsState::WriteShutdown,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn writeable(&self) -> bool {
|
|
||||||
match *self {
|
|
||||||
TlsState::WriteShutdown | TlsState::FullyShutdown => false,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn readable(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
TlsState::ReadShutdown | TlsState::FullyShutdown => false,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "early-data")]
|
|
||||||
fn is_early_data(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
TlsState::EarlyData(..) => true,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "early-data"))]
|
|
||||||
const fn is_early_data(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A wrapper around a `rustls::ClientConfig`, providing an async `connect` method.
|
/// A wrapper around a `rustls::ClientConfig`, providing an async `connect` method.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TlsConnector {
|
pub struct TlsConnector {
|
||||||
|
Loading…
Reference in New Issue
Block a user