pub mod scram;
#[derive(Debug, Clone)]
pub struct SaslCredentials {
mechanism: SaslMechanismType,
username: String,
password: String,
authzid: Option<String>,
}
impl SaslCredentials {
pub fn new(
mechanism: SaslMechanismType,
username: impl Into<String>,
password: impl Into<String>,
) -> Self {
Self {
mechanism,
username: username.into(),
password: password.into(),
authzid: None,
}
}
pub fn plain(username: impl Into<String>, password: impl Into<String>) -> Self {
Self::new(SaslMechanismType::Plain, username, password)
}
pub fn scram_sha256(username: impl Into<String>, password: impl Into<String>) -> Self {
Self::new(SaslMechanismType::ScramSha256, username, password)
}
pub fn scram_sha512(username: impl Into<String>, password: impl Into<String>) -> Self {
Self::new(SaslMechanismType::ScramSha512, username, password)
}
pub fn mechanism(&self) -> SaslMechanismType {
self.mechanism
}
pub fn username(&self) -> &str {
&self.username
}
pub fn password(&self) -> &str {
&self.password
}
pub fn authzid(&self) -> Option<&str> {
self.authzid.as_deref()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SaslMechanismType {
Plain,
ScramSha256,
ScramSha512,
}
impl SaslMechanismType {
pub fn as_str(&self) -> &'static str {
match self {
Self::Plain => "PLAIN",
Self::ScramSha256 => "SCRAM-SHA-256",
Self::ScramSha512 => "SCRAM-SHA-512",
}
}
}