ecksport_core/
traits.rs

1use std::future::Future;
2
3use crate::errors::{AuthError, ConnError};
4use crate::frame::{AuthIntent, ChallengeData, FrameBody, ResponseData, Side};
5use crate::peer::Identity;
6
7pub trait AsyncSendFrame {
8    /// Writes a frame to the other side.
9    fn send_frame_async(
10        &mut self,
11        body: &FrameBody,
12    ) -> impl Future<Output = Result<(), ConnError>> + Send;
13}
14
15pub trait AsyncRecvFrame {
16    /// Reads a frame from the other side.
17    fn recv_frame_async(&mut self) -> impl Future<Output = Result<FrameBody, ConnError>> + Send;
18}
19
20/// Represents authentication scheme's configuration data that we use during
21/// connection setup.
22pub trait AuthConfig: Clone {
23    /// Returns if we even want to do auth.
24    fn get_intent(&self) -> AuthIntent;
25
26    /// Potentially produces a challenge's response, given the two challenge
27    /// datas and where we are.
28    fn sign_challenge(
29        &self,
30        client_chal: &ChallengeData,
31        server_chal: &ChallengeData,
32        side: Side,
33    ) -> Result<Option<ResponseData>, AuthError>;
34
35    /// Verifies a response to a pair of challenge datas and the side that
36    /// produced it.  Returns the signed for identity, if possible.
37    fn verify_response(
38        &self,
39        client_chal: &ChallengeData,
40        server_chal: &ChallengeData,
41        producer_side: Side,
42        resp: &ResponseData,
43    ) -> Result<Option<Identity>, AuthError>;
44}