replaced an assertion with an error return instead

This commit is contained in:
Jędrzej Stuczyński
2024-09-19 15:55:54 +01:00
parent f5863b9668
commit be7f00fe52
2 changed files with 12 additions and 3 deletions
+5
View File
@@ -214,6 +214,11 @@ pub enum ClientCoreError {
#[error("this client has already registered with gateway {gateway_id}")]
AlreadyRegistered { gateway_id: String },
#[error(
"fresh registration with gateway {gateway_id} somehow requires an additional key upgrade!"
)]
UnexpectedKeyUpgrade { gateway_id: String },
}
/// Set of messages that the client can send to listeners via the task manager
+7 -3
View File
@@ -331,9 +331,13 @@ pub(super) async fn register_with_gateway(
}
})?;
// we can ignore the authentication result because we have **REGISTERED** a fresh client
// (we didn't have a prior key to upgrade/authenticate with)
assert!(!auth_response.requires_key_upgrade);
// this should NEVER happen, if it did, it means the function was misused,
// because for any fresh **registration**, the derived key is always up to date
if auth_response.requires_key_upgrade {
return Err(ClientCoreError::UnexpectedKeyUpgrade {
gateway_id: gateway_id.to_base58_string(),
});
}
Ok(RegistrationResult {
shared_keys: auth_response.initial_shared_key,