Skip to content

Commit 3df0d24

Browse files
committed
Init authentication submodule and AuthenticationScheme
1 parent 82e3d5e commit 3df0d24

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

src/auth/authentication_scheme.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}

src/auth/authorization.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// Credentials to authenticate a user agent with a server.
2+
#[derive(Debug)]
3+
pub struct Authorization;

src/auth/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! HTTP authentication and authorization.
2+
3+
mod authentication_scheme;
4+
mod authorization;
5+
6+
pub use authentication_scheme::AuthenticationScheme;
7+
pub use authorization::Authorization;

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub mod url {
117117
#[macro_use]
118118
mod utils;
119119

120+
pub mod auth;
120121
pub mod cache;
121122
pub mod conditional;
122123
pub mod content;

0 commit comments

Comments
 (0)