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
34
35
36
37
38
39
40
41
42
43
44
use std::future::Future;

use crate::errors::{AuthError, ConnError};
use crate::frame::{AuthIntent, ChallengeData, FrameBody, ResponseData, Side};
use crate::peer::Identity;

pub trait AsyncSendFrame {
    /// Writes a frame to the other side.
    fn send_frame_async(
        &mut self,
        body: &FrameBody,
    ) -> impl Future<Output = Result<(), ConnError>> + Send;
}

pub trait AsyncRecvFrame {
    /// Reads a frame from the other side.
    fn recv_frame_async(&mut self) -> impl Future<Output = Result<FrameBody, ConnError>> + Send;
}

/// Represents authentication scheme's configuration data that we use during
/// connection setup.
pub trait AuthConfig: Clone {
    /// Returns if we even want to do auth.
    fn get_intent(&self) -> AuthIntent;

    /// Potentially produces a challenge's response, given the two challenge
    /// datas and where we are.
    fn sign_challenge(
        &self,
        client_chal: &ChallengeData,
        server_chal: &ChallengeData,
        side: Side,
    ) -> Result<Option<ResponseData>, AuthError>;

    /// Verifies a response to a pair of challenge datas and the side that
    /// produced it.  Returns the signed for identity, if possible.
    fn verify_response(
        &self,
        client_chal: &ChallengeData,
        server_chal: &ChallengeData,
        producer_side: Side,
        resp: &ResponseData,
    ) -> Result<Option<Identity>, AuthError>;
}