diff options
Diffstat (limited to 'src/http/auth.rs')
| -rw-r--r-- | src/http/auth.rs | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/http/auth.rs b/src/http/auth.rs index 0f174ef..9c7a733 100644 --- a/src/http/auth.rs +++ b/src/http/auth.rs @@ -15,10 +15,7 @@ fn random_hex() -> Option<String> { let mut buf = [0u8; 32]; let mut f = std::fs::File::open("/dev/urandom").ok()?; f.read_exact(&mut buf).ok()?; - let nanos = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .map(|d| d.as_nanos()) - .unwrap_or(0); + let nanos = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_nanos()); let salt = format!("{:?}", (buf, nanos, std::process::id(), counter())); Some(hash::hex(salt.as_bytes())) } @@ -37,7 +34,7 @@ pub(crate) fn new_session() -> Option<String> { } pub(crate) fn is_valid_session(sid: &str) -> bool { - sessions().lock().map(|s| s.contains_key(sid)).unwrap_or(false) + sessions().lock().is_ok_and(|s| s.contains_key(sid)) } pub(crate) fn authenticate(sid: &str) { @@ -49,7 +46,7 @@ pub(crate) fn authenticate(sid: &str) { } pub(crate) fn is_authenticated(sid: &str) -> bool { - sessions().lock().map(|s| s.get(sid).copied().unwrap_or(false)).unwrap_or(false) + sessions().lock().is_ok_and(|s| s.get(sid).copied().unwrap_or(false)) } pub(crate) fn drop_session(sid: &str) { |
