use crate::transport::types::LegType;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Direction {
Send,
Recv,
}
impl Direction {
pub const fn as_str(self) -> &'static str {
match self {
Self::Send => "send",
Self::Recv => "recv",
}
}
}
pub fn leg_str(leg: LegType) -> &'static str {
match leg {
LegType::Kcp => "kcp",
LegType::Tcp => "tcp",
LegType::FakeTls => "faketls",
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HandshakeOutcome {
Success,
Failure,
}
impl HandshakeOutcome {
pub const fn as_str(self) -> &'static str {
match self {
Self::Success => "success",
Self::Failure => "failure",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ProtocolVersion {
Current,
}
impl ProtocolVersion {
pub const fn as_str(self) -> &'static str {
match self {
Self::Current => "v1",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AeadAlgorithm {
Aes256Gcm,
ChaCha20Poly1305,
}
impl AeadAlgorithm {
pub const fn as_str(self) -> &'static str {
match self {
Self::Aes256Gcm => "aes-256-gcm",
Self::ChaCha20Poly1305 => "chacha20-poly1305",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ReplayReason {
Old,
Duplicate,
}
impl ReplayReason {
pub const fn as_str(self) -> &'static str {
match self {
Self::Old => "old",
Self::Duplicate => "duplicate",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CookieOutcome {
Issued,
ValidatedOk,
ValidatedMismatch,
}
impl CookieOutcome {
pub const fn as_str(self) -> &'static str {
match self {
Self::Issued => "issued",
Self::ValidatedOk => "validated_ok",
Self::ValidatedMismatch => "validated_mismatch",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PowOutcome {
Solved,
Rejected,
}
impl PowOutcome {
pub const fn as_str(self) -> &'static str {
match self {
Self::Solved => "solved",
Self::Rejected => "rejected",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EarlyDataOutcome {
Accepted,
RejectedUnknownTicket,
RejectedOversized,
RejectedAead,
RejectedReplay,
}
impl EarlyDataOutcome {
pub const fn as_str(self) -> &'static str {
match self {
Self::Accepted => "accepted",
Self::RejectedUnknownTicket => "rejected_unknown_ticket",
Self::RejectedOversized => "rejected_oversized",
Self::RejectedAead => "rejected_aead",
Self::RejectedReplay => "rejected_replay",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ResumptionMode {
OneRtt,
ZeroRtt,
}
impl ResumptionMode {
pub const fn as_str(self) -> &'static str {
match self {
Self::OneRtt => "1rtt",
Self::ZeroRtt => "0rtt",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PathValidationOutcome {
Success,
Failure,
}
impl PathValidationOutcome {
pub const fn as_str(self) -> &'static str {
match self {
Self::Success => "success",
Self::Failure => "failure",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FallbackReason {
LossThreshold,
RttThreshold,
PathFailure,
Explicit,
}
impl FallbackReason {
pub const fn as_str(self) -> &'static str {
match self {
Self::LossThreshold => "loss_threshold",
Self::RttThreshold => "rtt_threshold",
Self::PathFailure => "path_failure",
Self::Explicit => "explicit",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn direction_strings_are_stable() {
assert_eq!(Direction::Send.as_str(), "send");
assert_eq!(Direction::Recv.as_str(), "recv");
}
#[test]
fn leg_str_covers_all_variants() {
assert_eq!(leg_str(LegType::Kcp), "kcp");
assert_eq!(leg_str(LegType::Tcp), "tcp");
assert_eq!(leg_str(LegType::FakeTls), "faketls");
}
#[test]
fn protocol_version_strings() {
assert_eq!(ProtocolVersion::Current.as_str(), "v1");
}
}