http_types/auth/
authentication_scheme.rs
1use std::fmt::{self, Display};
2use std::str::FromStr;
3
4use crate::bail_status as bail;
5
6#[derive(Debug, PartialEq, Eq, Clone, Copy)]
8#[non_exhaustive]
9pub enum AuthenticationScheme {
10 Basic,
12 Bearer,
14 Digest,
16 Hoba,
18 Mutual,
20 Negotiate,
22 OAuth,
24 ScramSha1,
26 ScramSha256,
28 Vapid,
30}
31
32impl Display for AuthenticationScheme {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 match self {
35 Self::Basic => write!(f, "Basic"),
36 Self::Bearer => write!(f, "Bearer"),
37 Self::Digest => write!(f, "Digest"),
38 Self::Hoba => write!(f, "HOBA"),
39 Self::Mutual => write!(f, "Mutual"),
40 Self::Negotiate => write!(f, "Negotiate"),
41 Self::OAuth => write!(f, "OAuth"),
42 Self::ScramSha1 => write!(f, "SCRAM-SHA-1"),
43 Self::ScramSha256 => write!(f, "SCRAM-SHA-256"),
44 Self::Vapid => write!(f, "vapid"),
45 }
46 }
47}
48
49impl FromStr for AuthenticationScheme {
50 type Err = crate::Error;
51
52 fn from_str(s: &str) -> Result<Self, Self::Err> {
53 match s.to_lowercase().as_str() {
57 "basic" => Ok(Self::Basic),
58 "bearer" => Ok(Self::Bearer),
59 "digest" => Ok(Self::Digest),
60 "hoba" => Ok(Self::Hoba),
61 "mutual" => Ok(Self::Mutual),
62 "negotiate" => Ok(Self::Negotiate),
63 "oauth" => Ok(Self::OAuth),
64 "scram-sha-1" => Ok(Self::ScramSha1),
65 "scram-sha-256" => Ok(Self::ScramSha256),
66 "vapid" => Ok(Self::Vapid),
67 s => bail!(400, "`{}` is not a recognized authentication scheme", s),
68 }
69 }
70}