diff options
Diffstat (limited to 'src/http/auth.rs')
| -rw-r--r-- | src/http/auth.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/http/auth.rs b/src/http/auth.rs index 6720607..0f174ef 100644 --- a/src/http/auth.rs +++ b/src/http/auth.rs @@ -28,7 +28,7 @@ fn counter() -> u64 { C.fetch_add(1, std::sync::atomic::Ordering::Relaxed) } -pub fn new_session() -> Option<String> { +pub(crate) fn new_session() -> Option<String> { let sid = random_hex()?; if let Ok(mut s) = sessions().lock() { s.insert(sid.clone(), false); @@ -36,11 +36,11 @@ pub fn new_session() -> Option<String> { Some(sid) } -pub fn is_valid_session(sid: &str) -> bool { +pub(crate) fn is_valid_session(sid: &str) -> bool { sessions().lock().map(|s| s.contains_key(sid)).unwrap_or(false) } -pub fn authenticate(sid: &str) { +pub(crate) fn authenticate(sid: &str) { if let Ok(mut s) = sessions().lock() { if let Some(authenticated) = s.get_mut(sid) { *authenticated = true; @@ -48,21 +48,21 @@ pub fn authenticate(sid: &str) { } } -pub fn is_authenticated(sid: &str) -> bool { +pub(crate) fn is_authenticated(sid: &str) -> bool { sessions().lock().map(|s| s.get(sid).copied().unwrap_or(false)).unwrap_or(false) } -pub fn drop_session(sid: &str) { +pub(crate) fn drop_session(sid: &str) { if let Ok(mut s) = sessions().lock() { s.remove(sid); } } -pub fn csrf_token(sid: &str) -> String { +pub(crate) fn csrf_token(sid: &str) -> String { hash::hex(format!("csrf|{sid}").as_bytes())[..32].to_string() } -pub fn csrf_ok(sid: &str, token: &str) -> bool { +pub(crate) fn csrf_ok(sid: &str, token: &str) -> bool { !token.is_empty() && is_valid_session(sid) && constant_time_eq(&csrf_token(sid), token) } @@ -78,7 +78,7 @@ fn constant_time_eq(a: &str, b: &str) -> bool { diff == 0 } -pub fn parse_cookies(header: &str) -> Vec<(String, String)> { +pub(crate) fn parse_cookies(header: &str) -> Vec<(String, String)> { header .split(';') .filter_map(|p| { @@ -89,10 +89,10 @@ pub fn parse_cookies(header: &str) -> Vec<(String, String)> { .collect() } -pub fn password_ok(cfg: &crate::config::Config, given: &str) -> bool { +pub(crate) fn password_ok(cfg: &crate::config::Config, given: &str) -> bool { cfg.password.is_empty() || constant_time_eq(&cfg.password, given) } -pub fn auth_required(cfg: &crate::config::Config) -> bool { +pub(crate) fn auth_required(cfg: &crate::config::Config) -> bool { !cfg.password.is_empty() } |
