Skip to content

Commit 4e87efb

Browse files
refactor: remove MlsCredentialExt trait
1 parent d5d6bab commit 4e87efb

File tree

4 files changed

+6
-90
lines changed

4 files changed

+6
-90
lines changed

keystore/src/connection/platform/wasm/migrations/v6/v5_entities/credential.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use wasm_bindgen::JsValue;
21
use web_time::SystemTime;
32

43
use crate::{
54
CryptoKeystoreError, CryptoKeystoreResult, MissingKeyErrorKind,
6-
connection::{DatabaseConnection, KeystoreDatabaseConnection, storage::WasmStorageTransaction},
7-
entities::{Entity, EntityBase, EntityFindParams, EntityTransactionExt, MlsCredentialExt, StringEntityId},
5+
connection::{DatabaseConnection, KeystoreDatabaseConnection},
6+
entities::{Entity, EntityBase, EntityFindParams, EntityTransactionExt, StringEntityId},
87
migrations::V5Credential,
98
};
109

@@ -78,41 +77,3 @@ impl Entity for V5Credential {
7877
Ok(())
7978
}
8079
}
81-
82-
#[async_trait::async_trait(?Send)]
83-
impl MlsCredentialExt for V5Credential {
84-
async fn delete_by_credential(
85-
transaction: &WasmStorageTransaction<'_>,
86-
credential: Vec<u8>,
87-
) -> CryptoKeystoreResult<()> {
88-
match transaction {
89-
WasmStorageTransaction::Persistent {
90-
tx: transaction,
91-
cipher,
92-
} => {
93-
let store = transaction.object_store(Self::COLLECTION_NAME)?;
94-
let store_index = store.index("credential")?;
95-
let credential_js: wasm_bindgen::JsValue = js_sys::Uint8Array::from(&credential[..]).into();
96-
let request = store_index.get(credential_js)?;
97-
let Some(entity_raw) = request.await? else {
98-
let reason = "'credential' in 'mls_credentials' collection";
99-
let value = hex::encode(&credential);
100-
return Err(CryptoKeystoreError::NotFound(reason, value));
101-
};
102-
103-
let mut credential = serde_wasm_bindgen::from_value::<V5Credential>(entity_raw)?;
104-
credential.decrypt(cipher)?;
105-
106-
let id = JsValue::from(credential.id.clone());
107-
let request = store.delete(id)?;
108-
request.await?;
109-
}
110-
WasmStorageTransaction::InMemory { .. } => {
111-
// current table model does not fit in a hashmap (no more primary key)
112-
// memory keystore is never used in prod
113-
}
114-
}
115-
116-
Ok(())
117-
}
118-
}

keystore/src/connection/platform/wasm/migrations/v7/v6_entities.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use wasm_bindgen::JsValue;
21
use web_time::SystemTime;
32

43
use crate::{
54
CryptoKeystoreError, CryptoKeystoreResult, MissingKeyErrorKind,
6-
connection::{DatabaseConnection, KeystoreDatabaseConnection, storage::WasmStorageTransaction},
7-
entities::{Entity, EntityBase, EntityFindParams, EntityTransactionExt, MlsCredentialExt, StringEntityId},
5+
connection::{DatabaseConnection, KeystoreDatabaseConnection},
6+
entities::{Entity, EntityBase, EntityFindParams, EntityTransactionExt, StringEntityId},
87
migrations::V6Credential,
98
};
109

@@ -78,41 +77,3 @@ impl Entity for V6Credential {
7877
Ok(())
7978
}
8079
}
81-
82-
#[async_trait::async_trait(?Send)]
83-
impl MlsCredentialExt for V6Credential {
84-
async fn delete_by_credential(
85-
transaction: &WasmStorageTransaction<'_>,
86-
credential: Vec<u8>,
87-
) -> CryptoKeystoreResult<()> {
88-
match transaction {
89-
WasmStorageTransaction::Persistent {
90-
tx: transaction,
91-
cipher,
92-
} => {
93-
let store = transaction.object_store(Self::COLLECTION_NAME)?;
94-
let store_index = store.index("credential")?;
95-
let credential_js: wasm_bindgen::JsValue = js_sys::Uint8Array::from(&credential[..]).into();
96-
let request = store_index.get(credential_js)?;
97-
let Some(entity_raw) = request.await? else {
98-
let reason = "'credential' in 'mls_credentials' collection";
99-
let value = hex::encode(&credential);
100-
return Err(CryptoKeystoreError::NotFound(reason, value));
101-
};
102-
103-
let mut credential = serde_wasm_bindgen::from_value::<V6Credential>(entity_raw)?;
104-
credential.decrypt(cipher)?;
105-
106-
let id = JsValue::from(credential.session_id.clone());
107-
let request = store.delete(id)?;
108-
request.await?;
109-
}
110-
WasmStorageTransaction::InMemory { .. } => {
111-
// current table model does not fit in a hashmap (no more primary key)
112-
// memory keystore is never used in prod
113-
}
114-
}
115-
116-
Ok(())
117-
}
118-
}

keystore/src/entities/mls.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ pub struct StoredCredential {
143143
pub private_key: Vec<u8>,
144144
}
145145

146-
#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
147-
#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
148-
pub trait MlsCredentialExt: Entity {
149-
async fn delete_by_credential(tx: &TransactionWrapper<'_>, credential: Vec<u8>) -> CryptoKeystoreResult<()>;
150-
}
151-
152146
/// Entity representing a persisted `HpkePrivateKey` (related to LeafNode Private keys that the client is aware of)
153147
#[derive(core_crypto_macros::Debug, Clone, PartialEq, Eq, Zeroize, serde::Serialize, serde::Deserialize)]
154148
#[zeroize(drop)]

keystore/src/entities/platform/generic/mls/credential.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::{
99
CryptoKeystoreError, CryptoKeystoreResult, MissingKeyErrorKind,
1010
connection::{DatabaseConnection, KeystoreDatabaseConnection, TransactionWrapper},
1111
entities::{
12-
Entity, EntityBase, EntityFindParams, EntityIdStringExt as _, EntityTransactionExt, MlsCredentialExt,
13-
StoredCredential, StringEntityId,
12+
Entity, EntityBase, EntityFindParams, EntityIdStringExt as _, EntityTransactionExt, StoredCredential,
13+
StringEntityId,
1414
},
1515
};
1616

0 commit comments

Comments
 (0)