1//! Provides the SASL "ANONYMOUS" mechanism.
2
3use crate::client::{Mechanism, MechanismError};
4use crate::common::{Credentials, Secret};
5
6/// A struct for the SASL ANONYMOUS mechanism.
7pub struct Anonymous;
8
9impl Anonymous {
10 /// Constructs a new struct for authenticating using the SASL ANONYMOUS mechanism.
11 ///
12 /// It is recommended that instead you use a `Credentials` struct and turn it into the
13 /// requested mechanism using `from_credentials`.
14 #[allow(clippy::new_without_default)]
15 pub fn new() -> Anonymous {
16 Anonymous
17 }
18}
19
20impl Mechanism for Anonymous {
21 fn name(&self) -> &str {
22 "ANONYMOUS"
23 }
24
25 fn from_credentials(credentials: Credentials) -> Result<Anonymous, MechanismError> {
26 if let Secret::None = credentials.secret {
27 Ok(Anonymous)
28 } else {
29 Err(MechanismError::AnonymousRequiresNoCredentials)
30 }
31 }
32}