sasl/server/mechanisms/
anonymous.rs1use crate::common::Identity;
2use crate::server::{Mechanism, MechanismError, Response};
3use alloc::format;
4use alloc::vec::Vec;
5
6use getrandom::getrandom;
7
8pub struct Anonymous;
9
10impl Anonymous {
11 #[allow(clippy::new_without_default)]
12 pub fn new() -> Anonymous {
13 Anonymous
14 }
15}
16
17impl Mechanism for Anonymous {
18 fn name(&self) -> &str {
19 "ANONYMOUS"
20 }
21
22 fn respond(&mut self, payload: &[u8]) -> Result<Response, MechanismError> {
23 if !payload.is_empty() {
24 return Err(MechanismError::FailedToDecodeMessage);
25 }
26 let mut rand = [0u8; 16];
27 getrandom(&mut rand)?;
28 let username = format!("{:02x?}", rand);
29 let ident = Identity::Username(username);
30 Ok(Response::Success(ident, Vec::new()))
31 }
32}