clean up naming, add advertising that the client thinks channel binding is unsupported

This commit is contained in:
lumi 2017-03-07 17:02:57 +01:00
commit 2d8fffdbfc
5 changed files with 50 additions and 46 deletions

View file

@ -1,8 +1,8 @@
//! Provides the SASL "ANONYMOUS" mechanism.
use SaslCredentials;
use SaslMechanism;
use SaslSecret;
use Credentials;
use Mechanism;
use Secret;
/// A struct for the SASL ANONYMOUS mechanism.
pub struct Anonymous;
@ -10,20 +10,20 @@ pub struct Anonymous;
impl Anonymous {
/// Constructs a new struct for authenticating using the SASL ANONYMOUS mechanism.
///
/// It is recommended that instead you use a `SaslCredentials` struct and turn it into the
/// It is recommended that instead you use a `Credentials` struct and turn it into the
/// requested mechanism using `from_credentials`.
pub fn new() -> Anonymous {
Anonymous
}
}
impl SaslMechanism for Anonymous {
impl Mechanism for Anonymous {
fn name(&self) -> &str {
"ANONYMOUS"
}
fn from_credentials(credentials: SaslCredentials) -> Result<Anonymous, String> {
if let SaslSecret::None = credentials.secret {
fn from_credentials(credentials: Credentials) -> Result<Anonymous, String> {
if let Secret::None = credentials.secret {
Ok(Anonymous)
} else {
Err("the anonymous sasl mechanism requires no credentials".to_owned())

View file

@ -1,8 +1,8 @@
//! Provides the SASL "PLAIN" mechanism.
use SaslCredentials;
use SaslMechanism;
use SaslSecret;
use Credentials;
use Mechanism;
use Secret;
/// A struct for the SASL PLAIN mechanism.
pub struct Plain {
@ -13,7 +13,7 @@ pub struct Plain {
impl Plain {
/// Constructs a new struct for authenticating using the SASL PLAIN mechanism.
///
/// It is recommended that instead you use a `SaslCredentials` struct and turn it into the
/// It is recommended that instead you use a `Credentials` struct and turn it into the
/// requested mechanism using `from_credentials`.
pub fn new<N: Into<String>, P: Into<String>>(username: N, password: P) -> Plain {
Plain {
@ -23,13 +23,13 @@ impl Plain {
}
}
impl SaslMechanism for Plain {
impl Mechanism for Plain {
fn name(&self) -> &str {
"PLAIN"
}
fn from_credentials(credentials: SaslCredentials) -> Result<Plain, String> {
if let SaslSecret::Password(password) = credentials.secret {
fn from_credentials(credentials: Credentials) -> Result<Plain, String> {
if let Secret::Password(password) = credentials.secret {
if let Some(username) = credentials.username {
Ok(Plain::new(username, password))
} else {

View file

@ -3,9 +3,9 @@
use base64;
use ChannelBinding;
use SaslCredentials;
use SaslMechanism;
use SaslSecret;
use Credentials;
use Mechanism;
use Secret;
use error::Error;
@ -162,7 +162,7 @@ impl<S: ScramProvider> Scram<S> {
/// Constructs a new struct for authenticating using the SASL SCRAM-* and SCRAM-*-PLUS
/// mechanisms, depending on the passed channel binding.
///
/// It is recommended that instead you use a `SaslCredentials` struct and turn it into the
/// It is recommended that instead you use a `Credentials` struct and turn it into the
/// requested mechanism using `from_credentials`.
pub fn new<N: Into<String>, P: Into<String>>(
username: N,
@ -200,14 +200,14 @@ impl<S: ScramProvider> Scram<S> {
}
}
impl<S: ScramProvider> SaslMechanism for Scram<S> {
impl<S: ScramProvider> Mechanism for Scram<S> {
fn name(&self) -> &str {
// TODO: this is quite the workaround…
&self.name
}
fn from_credentials(credentials: SaslCredentials) -> Result<Scram<S>, String> {
if let SaslSecret::Password(password) = credentials.secret {
fn from_credentials(credentials: Credentials) -> Result<Scram<S>, String> {
if let Secret::Password(password) = credentials.secret {
if let Some(username) = credentials.username {
Scram::new(username, password, credentials.channel_binding)
.map_err(|_| "can't generate nonce".to_owned())
@ -315,7 +315,7 @@ impl<S: ScramProvider> SaslMechanism for Scram<S> {
#[cfg(test)]
mod tests {
use SaslMechanism;
use Mechanism;
use super::*;