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
//! Generic types for building an auth scheme that can plug into the protocol with.

use rand::rngs::OsRng;
use rand::RngCore;

use crate::errors::*;
use crate::frame::*;
use crate::peer::Identity;
use crate::traits::AuthConfig;

/// Stub auth config for not doing any authentication.
impl AuthConfig for () {
    fn get_intent(&self) -> AuthIntent {
        AuthIntent::Neither
    }

    fn sign_challenge(
        &self,
        _client_chal: &ChallengeData,
        _server_chal: &ChallengeData,
        _side: Side,
    ) -> Result<Option<ResponseData>, AuthError> {
        Err(AuthError::Unsupported)
    }

    fn verify_response(
        &self,
        _client_chal: &ChallengeData,
        _server_chal: &ChallengeData,
        _producer_side: Side,
        _resp: &ResponseData,
    ) -> Result<Option<Identity>, AuthError> {
        Err(AuthError::Unsupported)
    }
}

/// Generates challenge data that can be sent over the wire.
pub fn gen_challenge() -> ChallengeData {
    let mut buf = [0; 16];
    OsRng.fill_bytes(&mut buf);
    ChallengeData::from_nonce_buf(buf)
}