xmpp-rs/src/sasl/mechanisms/plain.rs

30 lines
664 B
Rust
Raw Normal View History

2017-02-24 18:29:10 +01:00
//! Provides the SASL "PLAIN" mechanism.
use sasl::SaslMechanism;
pub struct Plain {
username: String,
2017-02-24 18:29:10 +01:00
password: String,
}
impl Plain {
pub fn new<N: Into<String>, P: Into<String>>(username: N, password: P) -> Plain {
2017-02-24 18:29:10 +01:00
Plain {
username: username.into(),
2017-02-24 18:29:10 +01:00
password: password.into(),
}
}
}
impl SaslMechanism for Plain {
fn name(&self) -> &str { "PLAIN" }
2017-02-24 18:29:10 +01:00
2017-02-24 23:42:08 +01:00
fn initial(&mut self) -> Result<Vec<u8>, String> {
2017-02-24 18:29:10 +01:00
let mut auth = Vec::new();
auth.push(0);
auth.extend(self.username.bytes());
2017-02-24 18:29:10 +01:00
auth.push(0);
auth.extend(self.password.bytes());
2017-02-24 23:42:08 +01:00
Ok(auth)
2017-02-24 18:29:10 +01:00
}
}