ecksport_core/
auth.rs

1//! Generic types for building an auth scheme that can plug into the protocol with.
2
3use rand::rngs::OsRng;
4use rand::RngCore;
5
6use crate::errors::*;
7use crate::frame::*;
8use crate::peer::Identity;
9use crate::traits::AuthConfig;
10
11/// Stub auth config for not doing any authentication.
12impl AuthConfig for () {
13    fn get_intent(&self) -> AuthIntent {
14        AuthIntent::Neither
15    }
16
17    fn sign_challenge(
18        &self,
19        _client_chal: &ChallengeData,
20        _server_chal: &ChallengeData,
21        _side: Side,
22    ) -> Result<Option<ResponseData>, AuthError> {
23        Err(AuthError::Unsupported)
24    }
25
26    fn verify_response(
27        &self,
28        _client_chal: &ChallengeData,
29        _server_chal: &ChallengeData,
30        _producer_side: Side,
31        _resp: &ResponseData,
32    ) -> Result<Option<Identity>, AuthError> {
33        Err(AuthError::Unsupported)
34    }
35}
36
37/// Generates challenge data that can be sent over the wire.
38pub fn gen_challenge() -> ChallengeData {
39    let mut buf = [0; 16];
40    OsRng.fill_bytes(&mut buf);
41    ChallengeData::from_nonce_buf(buf)
42}