simplify the API regarding authentication
This commit is contained in:
parent
a0685e2dc6
commit
6579ce6563
6 changed files with 99 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
|||
//! Provides the SASL "PLAIN" mechanism.
|
||||
|
||||
use sasl::SaslMechanism;
|
||||
use sasl::{SaslMechanism, SaslCredentials, SaslSecret};
|
||||
|
||||
pub struct Plain {
|
||||
username: String,
|
||||
|
|
@ -19,6 +19,15 @@ impl Plain {
|
|||
impl SaslMechanism for Plain {
|
||||
fn name(&self) -> &str { "PLAIN" }
|
||||
|
||||
fn from_credentials(credentials: SaslCredentials) -> Result<Plain, String> {
|
||||
if let SaslSecret::Password(password) = credentials.secret {
|
||||
Ok(Plain::new(credentials.username, password))
|
||||
}
|
||||
else {
|
||||
Err("PLAIN requires a password".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
fn initial(&mut self) -> Result<Vec<u8>, String> {
|
||||
let mut auth = Vec::new();
|
||||
auth.push(0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue