diff options
author | Mathijs van Veluw <[email protected]> | 2024-12-14 00:55:34 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-12-14 00:55:34 +0100 |
commit | 9cd400db6c5da858a4f49eb883469cbd6cb7337d (patch) | |
tree | 1c1d1900c1e1ba20da64e4c2052285b2d81317e8 /src/auth.rs | |
parent | fd512300448995735961cbeedcbe4b684be1c5fd (diff) | |
download | vaultwarden-9cd400db6c5da858a4f49eb883469cbd6cb7337d.tar.gz vaultwarden-9cd400db6c5da858a4f49eb883469cbd6cb7337d.zip |
Some refactoring and optimizations (#5291)
- Refactored several code to use more modern syntax
- Made some checks a bit more strict
- Updated crates
Signed-off-by: BlackDex <[email protected]>
Diffstat (limited to 'src/auth.rs')
-rw-r--r-- | src/auth.rs | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/auth.rs b/src/auth.rs index 809ef9fd..15910679 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -471,9 +471,8 @@ impl<'r> FromRequest<'r> for Headers { }; // Check JWT token is valid and get device and user from it - let claims = match decode_login(access_token) { - Ok(claims) => claims, - Err(_) => err_handler!("Invalid claim"), + let Ok(claims) = decode_login(access_token) else { + err_handler!("Invalid claim") }; let device_uuid = claims.device; @@ -484,23 +483,20 @@ impl<'r> FromRequest<'r> for Headers { _ => err_handler!("Error getting DB"), }; - let device = match Device::find_by_uuid_and_user(&device_uuid, &user_uuid, &mut conn).await { - Some(device) => device, - None => err_handler!("Invalid device id"), + let Some(device) = Device::find_by_uuid_and_user(&device_uuid, &user_uuid, &mut conn).await else { + err_handler!("Invalid device id") }; - let user = match User::find_by_uuid(&user_uuid, &mut conn).await { - Some(user) => user, - None => err_handler!("Device has no user associated"), + let Some(user) = User::find_by_uuid(&user_uuid, &mut conn).await else { + err_handler!("Device has no user associated") }; if user.security_stamp != claims.sstamp { if let Some(stamp_exception) = user.stamp_exception.as_deref().and_then(|s| serde_json::from_str::<UserStampException>(s).ok()) { - let current_route = match request.route().and_then(|r| r.name.as_deref()) { - Some(name) => name, - _ => err_handler!("Error getting current route for stamp exception"), + let Some(current_route) = request.route().and_then(|r| r.name.as_deref()) else { + err_handler!("Error getting current route for stamp exception") }; // Check if the stamp exception has expired first. |