2017-03-25 23:15:34 +01:00
|
|
|
use common::Identity;
|
|
|
|
|
use secret::SecretKind;
|
|
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! impl_validator_using_provider {
|
2017-03-25 23:25:28 +01:00
|
|
|
( $validator:ty, $secret:ty ) => {
|
|
|
|
|
impl $crate::server::Validator<$secret> for $validator {
|
2017-03-25 23:15:34 +01:00
|
|
|
fn validate(
|
|
|
|
|
&self,
|
|
|
|
|
identity: &$crate::common::Identity,
|
|
|
|
|
value: &<$secret as sasl::secret::SecretKind>::Value,
|
|
|
|
|
) -> Result<(), String> {
|
|
|
|
|
if &(self as &$crate::server::Provider<$secret>).provide(identity)? == value {
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
Err("authentication failure".to_owned())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-03-25 14:44:22 +01:00
|
|
|
|
2017-03-25 23:15:34 +01:00
|
|
|
pub trait Provider<S: SecretKind>: Validator<S> {
|
|
|
|
|
fn provide(&self, identity: &Identity) -> Result<S::Value, String>;
|
|
|
|
|
}
|
2017-03-25 14:44:22 +01:00
|
|
|
|
2017-03-25 23:15:34 +01:00
|
|
|
pub trait Validator<S: SecretKind> {
|
|
|
|
|
fn validate(&self, identity: &Identity, value: &S::Value) -> Result<(), String>;
|
2017-03-16 20:04:22 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-25 23:15:34 +01:00
|
|
|
pub trait Mechanism {
|
2017-03-16 20:04:22 +01:00
|
|
|
fn name(&self) -> &str;
|
|
|
|
|
fn respond(&mut self, payload: &[u8]) -> Result<Response, String>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum Response {
|
|
|
|
|
Success(Identity, Vec<u8>),
|
|
|
|
|
Proceed(Vec<u8>),
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 23:15:34 +01:00
|
|
|
pub mod mechanisms;
|