httpd: Refactor auth and session handling

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-02-04 19:38:26 +01:00
committed by Alexis Sellier
parent f689cb2c9f
commit ffdf7c171d
3 changed files with 28 additions and 32 deletions
+5 -13
View File
@@ -11,25 +11,17 @@ impl Serialize for DateTime {
}
}
#[derive(Clone)]
#[derive(Clone, Serialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum AuthState {
Authorized(Session),
Unauthorized(Session),
Authorized,
Unauthorized,
}
#[derive(Clone)]
pub struct Session {
pub status: String,
pub status: AuthState,
pub public_key: PublicKey,
pub issued_at: DateTime,
pub expires_at: DateTime,
}
impl From<AuthState> for Session {
fn from(other: AuthState) -> Self {
match other {
AuthState::Authorized(s) => s,
AuthState::Unauthorized(s) => s,
}
}
}