Add PLAIN authentication mecanism
This commit is contained in:
22
src/client/authentication/mod.rs
Normal file
22
src/client/authentication/mod.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2014 Alexis Mousset. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! PLAIN authentication mecanism
|
||||
|
||||
pub mod plain;
|
||||
|
||||
/// Trait representing an authentication mecanism
|
||||
pub trait AuthenticationMecanism {
|
||||
/// Create an authentication
|
||||
fn new(username: String, password: String) -> Self;
|
||||
/// Initial response if available
|
||||
fn initial_response(&self) -> Option<String>;
|
||||
/// Response to the given challenge
|
||||
fn response(&self, challenge: &str) -> String;
|
||||
}
|
||||
39
src/client/authentication/plain.rs
Normal file
39
src/client/authentication/plain.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2014 Alexis Mousset. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Authentication mecanisms
|
||||
|
||||
use common::NUL;
|
||||
use client::authentication::AuthenticationMecanism;
|
||||
|
||||
struct Plain {
|
||||
identity: String,
|
||||
username: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
impl AuthenticationMecanism for Plain {
|
||||
fn new(username: String, password: String) -> Plain {
|
||||
Plain {
|
||||
identity: "".to_string(),
|
||||
username: username,
|
||||
password: password,
|
||||
}
|
||||
}
|
||||
|
||||
fn initial_response(&self) -> Option<String> {
|
||||
Some(self.response(""))
|
||||
}
|
||||
|
||||
fn response(&self, challenge: &str) -> String {
|
||||
// We do not need a challenge in PLAIN authentication
|
||||
let _ = challenge;
|
||||
format!("{}{}{}{}{}", self.identity, NUL, self.username, NUL, self.password)
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ use sendable_email::SendableEmail;
|
||||
pub mod server_info;
|
||||
pub mod connecter;
|
||||
pub mod stream;
|
||||
pub mod authentication;
|
||||
|
||||
/// Represents the configuration of a client
|
||||
#[derive(Debug)]
|
||||
|
||||
Reference in New Issue
Block a user