1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use super::{
    Challenge, ChallengeResponse, Error, Info, Verification, VerificationKind, VerificationResponse,
};
use async_trait::async_trait;
use std::io;

/// Interface for a handler of authentication requests for a specific authentication method.
#[async_trait]
pub trait AuthMethodHandler: Send {
    /// Callback when a challenge is received, returning answers to the given questions.
    async fn on_challenge(&mut self, challenge: Challenge) -> io::Result<ChallengeResponse>;

    /// Callback when a verification request is received, returning true if approvided or false if
    /// unapproved.
    async fn on_verification(
        &mut self,
        verification: Verification,
    ) -> io::Result<VerificationResponse>;

    /// Callback when information is received. To fail, return an error from this function.
    async fn on_info(&mut self, info: Info) -> io::Result<()>;

    /// Callback when an error is received. Regardless of the result returned, this will terminate
    /// the authenticator. In the situation where a custom error would be preferred, have this
    /// callback return an error.
    async fn on_error(&mut self, error: Error) -> io::Result<()>;
}

mod prompt;
pub use prompt::*;

mod static_key;
pub use static_key::*;