clean up SASL code
This commit is contained in:
parent
61e8124c75
commit
74fb4fd9ad
5 changed files with 70 additions and 60 deletions
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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue