|
| 1 | +use std::fmt::{self, Display}; |
| 2 | +use std::str::FromStr; |
| 3 | + |
| 4 | +use crate::bail; |
| 5 | + |
| 6 | +/// HTTP Mutual Authentication Algorithms |
| 7 | +#[derive(Debug, PartialEq, Eq)] |
| 8 | +#[non_exhaustive] |
| 9 | +pub enum AuthenticationScheme { |
| 10 | + /// Basic auth |
| 11 | + Basic, |
| 12 | + /// Bearer auth |
| 13 | + Bearer, |
| 14 | + /// Digest auth |
| 15 | + Digest, |
| 16 | + /// HOBA |
| 17 | + Hoba, |
| 18 | + /// Mutual auth |
| 19 | + Mutual, |
| 20 | + /// Negotiate auth |
| 21 | + Negotiate, |
| 22 | + /// Oauth |
| 23 | + OAuth, |
| 24 | + /// SCRAM SHA1 auth |
| 25 | + ScramSha1, |
| 26 | + /// SCRAM SHA256 auth |
| 27 | + ScramSha256, |
| 28 | + /// Vapid auth |
| 29 | + Vapid, |
| 30 | +} |
| 31 | + |
| 32 | +impl 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 | + |
| 49 | +impl FromStr for AuthenticationScheme { |
| 50 | + type Err = crate::Error; |
| 51 | + |
| 52 | + fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 53 | + match s { |
| 54 | + "Basic" => Ok(Self::Basic), |
| 55 | + "Bearer" => Ok(Self::Bearer), |
| 56 | + "Digest" => Ok(Self::Digest), |
| 57 | + "HOBA" => Ok(Self::Hoba), |
| 58 | + "Mutual" => Ok(Self::Mutual), |
| 59 | + "Negotiate" => Ok(Self::Negotiate), |
| 60 | + "OAuth" => Ok(Self::OAuth), |
| 61 | + "SCRAM-SHA-1" => Ok(Self::ScramSha1), |
| 62 | + "SCRAM-SHA-256" => Ok(Self::ScramSha256), |
| 63 | + "vapid" => Ok(Self::Vapid), |
| 64 | + s => bail!("`{}` is not a recognized authentication scheme", s), |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments