more API simplifications

This commit is contained in:
lumi 2017-03-25 23:45:30 +01:00
commit 97f597d89d
6 changed files with 34 additions and 55 deletions

View file

@ -33,8 +33,7 @@ impl<V: Validator<secret::Plain>> Mechanism for Plain<V> {
let password =
String::from_utf8(password.to_vec()).map_err(|_| "error decoding password")?;
let ident = Identity::Username(username);
self.validator
.validate(&ident, &secret::PlainValue(password))?;
self.validator.validate(&ident, &secret::Plain(password))?;
Ok(Response::Success(ident, Vec::new()))
}
}

View file

@ -5,7 +5,7 @@ use base64;
use common::scram::{generate_nonce, ScramProvider};
use common::{parse_frame, xor, ChannelBinding, Identity};
use secret;
use secret::Pbkdf2SecretValue;
use secret::Pbkdf2Secret;
use server::{Mechanism, Provider, Response};
enum ScramState {
@ -24,8 +24,8 @@ enum ScramState {
pub struct Scram<S, P>
where
S: ScramProvider,
P: Provider<S::SecretKind>,
<S::SecretKind as secret::SecretKind>::Value: secret::Pbkdf2SecretValue,
P: Provider<S::Secret>,
S::Secret: secret::Pbkdf2Secret,
{
name: String,
state: ScramState,
@ -37,8 +37,8 @@ where
impl<S, P> Scram<S, P>
where
S: ScramProvider,
P: Provider<S::SecretKind>,
<S::SecretKind as secret::SecretKind>::Value: secret::Pbkdf2SecretValue,
P: Provider<S::Secret>,
S::Secret: secret::Pbkdf2Secret,
{
pub fn new(provider: P, channel_binding: ChannelBinding) -> Scram<S, P> {
Scram {
@ -54,8 +54,8 @@ where
impl<S, P> Mechanism for Scram<S, P>
where
S: ScramProvider,
P: Provider<S::SecretKind>,
<S::SecretKind as secret::SecretKind>::Value: secret::Pbkdf2SecretValue,
P: Provider<S::Secret>,
S::Secret: secret::Pbkdf2Secret,
{
fn name(&self) -> &str {
&self.name

View file

@ -1,5 +1,5 @@
use common::Identity;
use secret::SecretKind;
use secret::Secret;
#[macro_export]
macro_rules! impl_validator_using_provider {
@ -8,7 +8,7 @@ macro_rules! impl_validator_using_provider {
fn validate(
&self,
identity: &$crate::common::Identity,
value: &<$secret as sasl::secret::SecretKind>::Value,
value: &$secret,
) -> Result<(), String> {
if &(self as &$crate::server::Provider<$secret>).provide(identity)? == value {
Ok(())
@ -20,12 +20,12 @@ macro_rules! impl_validator_using_provider {
};
}
pub trait Provider<S: SecretKind>: Validator<S> {
fn provide(&self, identity: &Identity) -> Result<S::Value, String>;
pub trait Provider<S: Secret>: Validator<S> {
fn provide(&self, identity: &Identity) -> Result<S, String>;
}
pub trait Validator<S: SecretKind> {
fn validate(&self, identity: &Identity, value: &S::Value) -> Result<(), String>;
pub trait Validator<S: Secret> {
fn validate(&self, identity: &Identity, value: &S) -> Result<(), String>;
}
pub trait Mechanism {