Skip to content

Commit

Permalink
replaced an assertion with an error return instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jstuczyn committed Sep 19, 2024
1 parent f5863b9 commit 69ab2b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions common/client-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions common/client-core/src/init/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ 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);
}

Ok(RegistrationResult {
shared_keys: auth_response.initial_shared_key,
Expand Down

0 comments on commit 69ab2b7

Please sign in to comment.