state-res: Reduce indentation by adding early returns

This commit is contained in:
Jonas Platte 2022-01-13 13:52:43 +01:00
parent ee977b48f0
commit 1bdeebbd00
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -902,9 +902,13 @@ fn verify_third_party_invite(
return false; return false;
} }
// If there is no m.room.third_party_invite event in the current room state // If there is no m.room.third_party_invite event in the current room state with state_key
// with state_key matching token, reject // matching token, reject
if let Some(current_tpid) = current_third_party_invite { let current_tpid = match current_third_party_invite {
Some(id) => id,
None => return false,
};
if current_tpid.state_key() != Some(&tp_id.signed.token) { if current_tpid.state_key() != Some(&tp_id.signed.token) {
return false; return false;
} }
@ -915,23 +919,21 @@ fn verify_third_party_invite(
// If any signature in signed matches any public key in the m.room.third_party_invite event, // If any signature in signed matches any public key in the m.room.third_party_invite event,
// allow // allow
if let Ok(tpid_ev) = let tpid_ev =
from_json_str::<RoomThirdPartyInviteEventContent>(current_tpid.content().get()) match from_json_str::<RoomThirdPartyInviteEventContent>(current_tpid.content().get()) {
{ Ok(ev) => ev,
Err(_) => return false,
};
// A list of public keys in the public_keys field // A list of public keys in the public_keys field
for key in tpid_ev.public_keys.unwrap_or_default() { for key in tpid_ev.public_keys.unwrap_or_default() {
if key.public_key == tp_id.signed.token { if key.public_key == tp_id.signed.token {
return true; return true;
} }
} }
// A single public key in the public_key field // A single public key in the public_key field
tpid_ev.public_key == tp_id.signed.token tpid_ev.public_key == tp_id.signed.token
} else {
false
}
} else {
false
}
} }
#[cfg(test)] #[cfg(test)]