mod connection;
mod csms;
mod local_controller;
mod network_profile;
mod security;
mod station;
mod stream;
#[cfg(feature = "rustls")]
mod tls;
mod ws;
pub use connection::{
BoxFuture, Ctx, Event, Handle, Handler, Keepalive, NotImplemented, SessionContext, SessionState,
};
pub use csms::{
AcceptEveryStation, Auth, AuthOutcome, Authenticator, Csms, CsmsBuilder, CsmsHandle,
SessionEvent,
};
pub use local_controller::{
Direction, LocalController, LocalControllerBuilder, PassThrough, RefuseActions, Relay,
RelayDecision, UpstreamCredentials,
};
pub use network_profile::{NetworkProfile, NetworkProfiles};
pub use security::{
AUTHORIZATION_KEY_MAX_BYTES, AUTHORIZATION_KEY_MIN_BYTES, BASIC_AUTH_INTEROPERABLE_MAX_LEN,
BASIC_AUTH_MAX_LEN, BASIC_AUTH_MIN_LEN, BasicAuthPassword, CredentialError, Credentials,
SecurityProfile, basic_auth_header, constant_time_eq,
};
pub use station::{Station, StationBuilder};
pub use stream::MaybeTls;
#[cfg(feature = "compression")]
pub use ws::deflate::{DeflateError, DeflateParams, NegotiationError as DeflateNegotiationError};
pub use ws::{
CloseCode, CloseFrame, Config as WsConfig, Message as WsMessage, ProtocolError, Role as WsRole,
WsError,
};
#[doc(hidden)]
pub mod ws_test_support {
#[cfg(feature = "compression")]
#[must_use]
pub fn client_codec_with_deflate() -> super::ws::WsCodec {
super::ws::WsCodec::new(super::ws::Role::Client, super::ws::Config::default())
.with_deflate(super::ws::deflate::DeflateParams::default())
}
}
#[doc(hidden)]
pub mod ws_fuzz {
pub use super::ws::{Config, Message, Role, WsCodec, WsError};
use bytes::BytesMut;
use tokio_util::codec::{Decoder as _, Encoder as _};
pub fn decode(codec: &mut WsCodec, buffer: &mut BytesMut) -> Result<Option<Message>, WsError> {
codec.decode(buffer)
}
pub fn encode(
codec: &mut WsCodec,
message: Message,
buffer: &mut BytesMut,
) -> Result<(), WsError> {
codec.encode(message, buffer)
}
}
#[cfg(feature = "rustls")]
pub use tls::{ClientTls, ClientTlsBuilder, ServerTls, TlsError};
use core::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum TransportError {
Io(std::io::Error),
WebSocket(ws::WsError),
Negotiation(crate::version::NegotiationError),
Url(String),
Rejected {
status: u16,
},
Credential(CredentialError),
Configuration(String),
Store(crate::engine::StoreError),
Closed,
}
impl fmt::Display for TransportError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TransportError::Io(error) => write!(f, "i/o error: {error}"),
TransportError::WebSocket(error) => write!(f, "websocket error: {error}"),
TransportError::Negotiation(error) => write!(f, "{error}"),
TransportError::Url(url) => write!(f, "unusable URL: {url}"),
TransportError::Rejected { status } => {
write!(f, "the CSMS rejected the handshake with HTTP {status}")
}
TransportError::Credential(error) => write!(f, "{error}"),
TransportError::Configuration(what) => write!(f, "configuration error: {what}"),
TransportError::Store(error) => write!(f, "message store error: {error}"),
TransportError::Closed => f.write_str("the session is closed"),
}
}
}
impl std::error::Error for TransportError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
TransportError::Io(error) => Some(error),
TransportError::WebSocket(error) => Some(error),
_ => None,
}
}
}
impl From<std::io::Error> for TransportError {
fn from(error: std::io::Error) -> Self {
TransportError::Io(error)
}
}
impl From<ws::WsError> for TransportError {
fn from(error: ws::WsError) -> Self {
TransportError::WebSocket(error)
}
}
impl From<crate::version::NegotiationError> for TransportError {
fn from(error: crate::version::NegotiationError) -> Self {
TransportError::Negotiation(error)
}
}
impl From<CredentialError> for TransportError {
fn from(error: CredentialError) -> Self {
TransportError::Credential(error)
}
}
impl From<crate::engine::StoreError> for TransportError {
fn from(error: crate::engine::StoreError) -> Self {
TransportError::Store(error)
}
}