1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-31 09:24:31 +03:00

Convert many match/if expressions to let-else

This commit is contained in:
Quentin Gliech
2023-02-01 10:15:35 +01:00
parent d9649975b9
commit 792d3c793b
22 changed files with 51 additions and 107 deletions

View File

@ -190,26 +190,23 @@ pub fn verify_id_token<'a>(
// Subject identifier must be present.
let sub = claims::SUB.extract_required(&mut claims)?;
// No more checks if there is no previous ID token.
let auth_id_token = match auth_id_token {
Some(id_token) => id_token,
None => return Ok(id_token),
};
// More checks if there is a previous ID token.
if let Some(auth_id_token) = auth_id_token {
let mut auth_claims = auth_id_token.payload().clone();
let mut auth_claims = auth_id_token.payload().clone();
// Subject identifier must always be the same.
let auth_sub = claims::SUB.extract_required(&mut auth_claims)?;
if sub != auth_sub {
return Err(IdTokenError::WrongSubjectIdentifier);
}
// Subject identifier must always be the same.
let auth_sub = claims::SUB.extract_required(&mut auth_claims)?;
if sub != auth_sub {
return Err(IdTokenError::WrongSubjectIdentifier);
}
// If the authentication time is present, it must be unchanged.
if let Some(auth_time) = claims::AUTH_TIME.extract_optional(&mut claims)? {
let prev_auth_time = claims::AUTH_TIME.extract_required(&mut auth_claims)?;
// If the authentication time is present, it must be unchanged.
if let Some(auth_time) = claims::AUTH_TIME.extract_optional(&mut claims)? {
let prev_auth_time = claims::AUTH_TIME.extract_required(&mut auth_claims)?;
if prev_auth_time != auth_time {
return Err(IdTokenError::WrongAuthTime);
if prev_auth_time != auth_time {
return Err(IdTokenError::WrongAuthTime);
}
}
}

View File

@ -28,14 +28,8 @@ where
}
pub fn http_all_error_status_codes() -> impl RangeBounds<StatusCode> {
let client_errors_start_code = match StatusCode::from_u16(400) {
Ok(code) => code,
Err(_) => unreachable!(),
};
let server_errors_end_code = match StatusCode::from_u16(599) {
Ok(code) => code,
Err(_) => unreachable!(),
};
let Ok(client_errors_start_code) = StatusCode::from_u16(400) else { unreachable!() };
let Ok(server_errors_end_code) = StatusCode::from_u16(599) else { unreachable!() };
client_errors_start_code..=server_errors_end_code
}