Skip to content

Commit

Permalink
chore: don't deem credential unique by id
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonThormeyer committed Oct 9, 2024
1 parent 17bd012 commit e3516dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions keystore/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ cfg_if::cfg_if! {

pub trait Entity: EntityBase {
fn id_raw(&self) -> &[u8];

/// The query results that are obtained during a transaction
/// from the transaction cache and the database are merged by this key.
fn merge_key(&self) -> Vec<u8> {
self.id_raw().into()
}
}

pub trait EntityIdStringExt: Entity {
Expand Down
6 changes: 6 additions & 0 deletions keystore/src/entities/platform/generic/mls/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ impl Entity for MlsCredential {
fn id_raw(&self) -> &[u8] {
self.id.as_slice()
}

fn merge_key(&self) -> Vec<u8> {
let mut merge_key = self.id_raw().to_vec();
merge_key.extend(self.created_at.to_be_bytes().to_vec());
merge_key
}
}

#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
Expand Down
2 changes: 1 addition & 1 deletion keystore/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl KeystoreTransaction {
let merged = records_a
.into_iter()
.chain(records_b)
.unique_by(|e| e.id_raw().to_vec());
.unique_by(|e| e.merge_key());

// The alternative to giving up laziness here would be to use a dynamically
// typed iterator Box<dyn Iterator<Item = E>> assigned to `merged`. The below approach
Expand Down

0 comments on commit e3516dd

Please sign in to comment.