Skip to content

Commit

Permalink
clean up the vec u8 usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 4, 2025
1 parent f7ddaf2 commit fc9f905
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
7 changes: 5 additions & 2 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ impl FfiXmtpClient {
) -> Result<Arc<FfiSignatureRequest>, GenericError> {
let installation_id = self.inner_client.installation_public_key();

if installation_ids.iter().any(|id| id == &installation_id) {
if installation_ids.iter().any(|id| id == installation_id) {
return Err(GenericError::Generic {
err: "Cannot revoke the current installation ID.".to_string(),
});
Expand Down Expand Up @@ -4304,7 +4304,10 @@ mod tests {
assert_eq!(client_1_state.installations.len(), 2);
assert_eq!(client_2_state.installations.len(), 2);

let signature_request = client_1.revoke_installations(vec![client_2.installation_id()]).await.unwrap();
let signature_request = client_1
.revoke_installations(vec![client_2.installation_id()])
.await
.unwrap();
signature_request.add_wallet_signature(&wallet).await;
client_1
.apply_signature_request(signature_request)
Expand Down
14 changes: 11 additions & 3 deletions bindings_node/src/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,28 @@ impl Client {
#[napi]
pub async fn revoke_installations_signature_text(
&self,
installation_ids: Vec<Vec<u8>>,
installation_ids: Vec<Uint8Array>,
) -> Result<String> {
let installation_id = self.inner_client().installation_public_key();

let installation_ids_bytes: Vec<Vec<u8>> = installation_ids
.iter()
.map(|id| id.deref().to_vec())
.collect();

// Check if the current installation ID is in the list
if installation_ids.iter().any(|id| id == &installation_id) {
if installation_ids_bytes
.iter()
.any(|id| id == installation_id)
{
return Err(Error::from_reason(
"Cannot revoke the current installation ID.",
));
}

let signature_request = self
.inner_client()
.revoke_installations(installation_ids)
.revoke_installations(installation_ids_bytes)
.await
.map_err(ErrorWrapper::from)?;
let signature_text = signature_request.signature_text();
Expand Down
13 changes: 9 additions & 4 deletions bindings_wasm/src/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,23 @@ impl Client {
#[wasm_bindgen(js_name = revokeInstallationsSignatureText)]
pub async fn revoke_installations_signature_text(
&self,
installation_ids: Vec<Vec<u8>>,
installation_ids: Vec<Uint8Array>,
) -> Result<String, JsError> {
let installation_id = self.inner_client().installation_public_key();

// Check if the current installation ID is in the list
if installation_ids.iter().any(|id| id == &installation_id) {
let installation_ids_bytes: Vec<Vec<u8>> =
installation_ids.iter().map(|id| id.to_vec()).collect();

if installation_ids_bytes
.iter()
.any(|id| id == &installation_id)
{
return Err(JsError::new("Cannot revoke the current installation ID."));
}

let signature_request = self
.inner_client()
.revoke_installations(installation_ids)
.revoke_installations(installation_ids_bytes)
.await
.map_err(|e| JsError::new(format!("{}", e).as_str()))?;
let signature_text = signature_request.signature_text();
Expand Down

0 comments on commit fc9f905

Please sign in to comment.