1use crate::common::Credentials;
2
3/// A trait which defines SASL mechanisms.
4pub trait Mechanism {
5 /// The name of the mechanism.
6 fn name(&self) -> &str;
7
8 /// Creates this mechanism from `Credentials`.
9 fn from_credentials(credentials: Credentials) -> Result<Self, String>
10 where
11 Self: Sized;
12
13 /// Provides initial payload of the SASL mechanism.
14 fn initial(&mut self) -> Result<Vec<u8>, String> {
15 Ok(Vec::new())
16 }
17
18 /// Creates a response to the SASL challenge.
19 fn response(&mut self, _challenge: &[u8]) -> Result<Vec<u8>, String> {
20 Ok(Vec::new())
21 }
22
23 /// Verifies the server success response, if there is one.
24 fn success(&mut self, _data: &[u8]) -> Result<(), String> {
25 Ok(())
26 }
27}
28
29pub mod mechanisms;