zbus/connection/handshake/
auth_mechanism.rs1use std::{fmt, str::FromStr};
2
3use crate::{Error, Result};
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum AuthMechanism {
10 External,
14
15 Cookie,
18
19 Anonymous,
22}
23
24impl fmt::Display for AuthMechanism {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 let mech = match self {
27 AuthMechanism::External => "EXTERNAL",
28 AuthMechanism::Cookie => "DBUS_COOKIE_SHA1",
29 AuthMechanism::Anonymous => "ANONYMOUS",
30 };
31 write!(f, "{mech}")
32 }
33}
34
35impl FromStr for AuthMechanism {
36 type Err = Error;
37
38 fn from_str(s: &str) -> Result<Self> {
39 match s {
40 "EXTERNAL" => Ok(AuthMechanism::External),
41 "DBUS_COOKIE_SHA1" => Ok(AuthMechanism::Cookie),
42 "ANONYMOUS" => Ok(AuthMechanism::Anonymous),
43 _ => Err(Error::Handshake(format!("Unknown mechanism: {s}"))),
44 }
45 }
46}