clean up SASL code
This commit is contained in:
parent
61e8124c75
commit
74fb4fd9ad
5 changed files with 70 additions and 60 deletions
60
src/sasl.rs
60
src/sasl.rs
|
@ -1,60 +0,0 @@
|
|||
//! Provides the `SaslMechanism` trait and some implementations.
|
||||
|
||||
pub trait SaslMechanism {
|
||||
/// The name of the mechanism.
|
||||
fn name() -> &'static str;
|
||||
|
||||
/// Provides initial payload of the SASL mechanism.
|
||||
fn initial(&mut self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Creates a response to the SASL challenge.
|
||||
fn response(&mut self, _challenge: &[u8]) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// A few SASL mechanisms.
|
||||
pub mod mechanisms {
|
||||
use super::SaslMechanism;
|
||||
|
||||
pub struct Anonymous;
|
||||
|
||||
impl Anonymous {
|
||||
pub fn new() -> Anonymous {
|
||||
Anonymous
|
||||
}
|
||||
}
|
||||
|
||||
impl SaslMechanism for Anonymous {
|
||||
fn name() -> &'static str { "ANONYMOUS" }
|
||||
}
|
||||
|
||||
pub struct Plain {
|
||||
name: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
impl Plain {
|
||||
pub fn new<N: Into<String>, P: Into<String>>(name: N, password: P) -> Plain {
|
||||
Plain {
|
||||
name: name.into(),
|
||||
password: password.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SaslMechanism for Plain {
|
||||
fn name() -> &'static str { "PLAIN" }
|
||||
|
||||
fn initial(&mut self) -> Vec<u8> {
|
||||
let mut auth = Vec::new();
|
||||
auth.push(0);
|
||||
auth.extend(self.name.bytes());
|
||||
auth.push(0);
|
||||
auth.extend(self.password.bytes());
|
||||
auth
|
||||
}
|
||||
}
|
||||
}
|
15
src/sasl/mechanisms/anonymous.rs
Normal file
15
src/sasl/mechanisms/anonymous.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
//! Provides the SASL "ANONYMOUS" mechanism.
|
||||
|
||||
use sasl::SaslMechanism;
|
||||
|
||||
pub struct Anonymous;
|
||||
|
||||
impl Anonymous {
|
||||
pub fn new() -> Anonymous {
|
||||
Anonymous
|
||||
}
|
||||
}
|
||||
|
||||
impl SaslMechanism for Anonymous {
|
||||
fn name() -> &'static str { "ANONYMOUS" }
|
||||
}
|
7
src/sasl/mechanisms/mod.rs
Normal file
7
src/sasl/mechanisms/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
///! Provides a few SASL mechanisms.
|
||||
|
||||
mod anonymous;
|
||||
mod plain;
|
||||
|
||||
pub use self::anonymous::Anonymous;
|
||||
pub use self::plain::Plain;
|
30
src/sasl/mechanisms/plain.rs
Normal file
30
src/sasl/mechanisms/plain.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
//! Provides the SASL "PLAIN" mechanism.
|
||||
|
||||
use sasl::SaslMechanism;
|
||||
|
||||
pub struct Plain {
|
||||
name: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
impl Plain {
|
||||
pub fn new<N: Into<String>, P: Into<String>>(name: N, password: P) -> Plain {
|
||||
Plain {
|
||||
name: name.into(),
|
||||
password: password.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SaslMechanism for Plain {
|
||||
fn name() -> &'static str { "PLAIN" }
|
||||
|
||||
fn initial(&mut self) -> Vec<u8> {
|
||||
let mut auth = Vec::new();
|
||||
auth.push(0);
|
||||
auth.extend(self.name.bytes());
|
||||
auth.push(0);
|
||||
auth.extend(self.password.bytes());
|
||||
auth
|
||||
}
|
||||
}
|
18
src/sasl/mod.rs
Normal file
18
src/sasl/mod.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
//! Provides the `SaslMechanism` trait and some implementations.
|
||||
|
||||
pub trait SaslMechanism {
|
||||
/// The name of the mechanism.
|
||||
fn name() -> &'static str;
|
||||
|
||||
/// Provides initial payload of the SASL mechanism.
|
||||
fn initial(&mut self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Creates a response to the SASL challenge.
|
||||
fn response(&mut self, _challenge: &[u8]) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod mechanisms;
|
Loading…
Reference in a new issue