mod.rs

 1use crate::common::Identity;
 2use crate::secret::Secret;
 3
 4#[macro_export]
 5macro_rules! impl_validator_using_provider {
 6    ( $validator:ty, $secret:ty ) => {
 7        impl $crate::server::Validator<$secret> for $validator {
 8            fn validate(
 9                &self,
10                identity: &$crate::common::Identity,
11                value: &$secret,
12            ) -> Result<(), String> {
13                if &(self as &$crate::server::Provider<$secret>).provide(identity)? == value {
14                    Ok(())
15                } else {
16                    Err("authentication failure".to_owned())
17                }
18            }
19        }
20    };
21}
22
23pub trait Provider<S: Secret>: Validator<S> {
24    fn provide(&self, identity: &Identity) -> Result<S, String>;
25}
26
27pub trait Validator<S: Secret> {
28    fn validate(&self, identity: &Identity, value: &S) -> Result<(), String>;
29}
30
31pub trait Mechanism {
32    fn name(&self) -> &str;
33    fn respond(&mut self, payload: &[u8]) -> Result<Response, String>;
34}
35
36#[derive(Debug, Clone, PartialEq, Eq)]
37pub enum Response {
38    Success(Identity, Vec<u8>),
39    Proceed(Vec<u8>),
40}
41
42pub mod mechanisms;