use std::fmt::{self, Debug, Formatter};
#[derive(Clone)]
#[non_exhaustive]
pub enum Socks5Auth {
None,
UsernamePassword {
username: Vec<u8>,
password: Vec<u8>,
},
}
impl Socks5Auth {
pub const fn none() -> Self {
Self::None
}
pub fn username_password<U, P>(username: U, password: P) -> Self
where
U: Into<Vec<u8>>,
P: Into<Vec<u8>>,
{
Self::UsernamePassword {
username: username.into(),
password: password.into(),
}
}
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}
}
impl Debug for Socks5Auth {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::None => f.debug_tuple("Socks5Auth::None").finish(),
Self::UsernamePassword { username, .. } => f
.debug_struct("Socks5Auth::UsernamePassword")
.field("username", &String::from_utf8_lossy(username).into_owned())
.field("password", &"<redacted>")
.finish(),
}
}
}
#[derive(Clone)]
#[non_exhaustive]
pub enum HttpProxyAuth {
None,
Basic { username: String, password: String },
}
impl HttpProxyAuth {
pub const fn none() -> Self {
Self::None
}
pub fn basic<U, P>(username: U, password: P) -> Self
where
U: Into<String>,
P: Into<String>,
{
Self::Basic {
username: username.into(),
password: password.into(),
}
}
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}
}
impl Debug for HttpProxyAuth {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::None => f.debug_tuple("HttpProxyAuth::None").finish(),
Self::Basic { username, .. } => f
.debug_struct("HttpProxyAuth::Basic")
.field("username", username)
.field("password", &"<redacted>")
.finish(),
}
}
}