Skip to content

Commit 8a0c253

Browse files
committed
chore(keystore): clean up dead code
1 parent d716c58 commit 8a0c253

File tree

3 files changed

+6
-116
lines changed

3 files changed

+6
-116
lines changed

keystore/src/entities/mls.rs

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use zeroize::{Zeroize, ZeroizeOnDrop};
1+
use zeroize::Zeroize;
22

33
use crate::{
44
CryptoKeystoreResult,
5-
traits::{EntityBase, EntityGetBorrowed as _, KeyType, OwnedKeyType, PrimaryKey, SearchableEntity as _},
5+
traits::{EntityBase, EntityGetBorrowed as _, KeyType, PrimaryKey, SearchableEntity as _},
66
};
77

88
/// This type exists so that we can efficiently search for the children of a given group.
@@ -88,77 +88,6 @@ impl<'a> KeyType for ConversationId<'a> {
8888
}
8989
}
9090

91-
/// [`MlsPendingMessage`]s have no distinct primary key;
92-
/// they must always be accessed via [`MlsPendingMessage::find_all_by_conversation_id`] and
93-
/// cleaned up with [`MlsPendingMessage::delete_by_conversation_id`]
94-
///
95-
/// However, we have to fake a primary key type in order to support
96-
/// `KeystoreTransaction::remove_pending_messages_by_conversation_id`. Additionally we need the same one in WASM, where
97-
/// it's necessary for item-level encryption.
98-
///
99-
/// This implementation is fairly inefficient and hopefully temporary. But it at least implements the correct semantics.
100-
#[derive(ZeroizeOnDrop)]
101-
pub struct MlsPendingMessagePrimaryKey {
102-
pub(crate) foreign_id: Vec<u8>,
103-
message: Vec<u8>,
104-
}
105-
106-
impl MlsPendingMessagePrimaryKey {
107-
/// Construct a partial mls pending message primary key from only the conversation id.
108-
///
109-
/// This does not in fact uniquely identify a single pending message--it should always uniquely
110-
/// identify exactly 0 pending messages--but we have to have it so that we can search and delete
111-
/// by conversation id within transactions.
112-
pub(crate) fn from_conversation_id(conversation_id: impl AsRef<[u8]>) -> Self {
113-
Self {
114-
foreign_id: conversation_id.as_ref().to_owned(),
115-
message: Vec::new(),
116-
}
117-
}
118-
}
119-
120-
impl From<&MlsPendingMessage> for MlsPendingMessagePrimaryKey {
121-
fn from(value: &MlsPendingMessage) -> Self {
122-
Self {
123-
foreign_id: value.foreign_id.clone(),
124-
message: value.message.clone(),
125-
}
126-
}
127-
}
128-
129-
impl KeyType for MlsPendingMessagePrimaryKey {
130-
fn bytes(&self) -> std::borrow::Cow<'_, [u8]> {
131-
// run-length encoding: 32 bits of size for each field, followed by the field
132-
let fields = [&self.foreign_id, &self.message];
133-
let mut key = Vec::with_capacity(
134-
((u32::BITS / u8::BITS) as usize * fields.len()) + self.foreign_id.len() + self.message.len(),
135-
);
136-
for field in fields {
137-
key.extend((field.len() as u32).to_le_bytes());
138-
key.extend(field.as_slice());
139-
}
140-
key.into()
141-
}
142-
}
143-
144-
impl OwnedKeyType for MlsPendingMessagePrimaryKey {
145-
fn from_bytes(bytes: &[u8]) -> Option<Self> {
146-
// run-length decoding: 32 bits of size for each field, followed by the field
147-
let (len, bytes) = bytes.split_at_checked(4)?;
148-
let len = u32::from_le_bytes(len.try_into().ok()?);
149-
let (foreign_id, bytes) = bytes.split_at_checked(len as _)?;
150-
151-
let (len, bytes) = bytes.split_at_checked(4)?;
152-
let len = u32::from_le_bytes(len.try_into().ok()?);
153-
let (message, bytes) = bytes.split_at_checked(len as _)?;
154-
155-
bytes.is_empty().then(|| Self {
156-
foreign_id: foreign_id.to_owned(),
157-
message: message.to_owned(),
158-
})
159-
}
160-
}
161-
16291
/// Entity representing a buffered message
16392
#[derive(core_crypto_macros::Debug, Clone, PartialEq, Eq, Zeroize, serde::Serialize, serde::Deserialize)]
16493
#[zeroize(drop)]
@@ -168,11 +97,11 @@ pub struct MlsPendingMessage {
16897
pub message: Vec<u8>,
16998
}
17099

100+
/// [`MlsPendingMessage`] has no real primary key, but we have to fake it for the trait hierarchy,
101+
/// so here we are.
171102
impl PrimaryKey for MlsPendingMessage {
172-
type PrimaryKey = MlsPendingMessagePrimaryKey;
173-
fn primary_key(&self) -> Self::PrimaryKey {
174-
self.into()
175-
}
103+
type PrimaryKey = ();
104+
fn primary_key(&self) -> Self::PrimaryKey {}
176105
}
177106

178107
/// Entity representing a buffered commit.

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@ impl MlsPendingMessage {
2121
let message = row.get("message")?;
2222
Ok(Self { foreign_id, message })
2323
}
24-
25-
pub async fn find_all_by_conversation_id(
26-
conn: &mut <Self as EntityBase>::ConnectionType,
27-
conversation_id: &[u8],
28-
) -> CryptoKeystoreResult<Vec<Self>> {
29-
let conn = conn.conn().await;
30-
let mut stmt = conn.prepare_cached("SELECT * FROM mls_pending_messages WHERE id = ?")?;
31-
let values = stmt
32-
.query_map([conversation_id], Self::from_row)?
33-
.collect::<Result<_, _>>()?;
34-
Ok(values)
35-
}
36-
37-
pub async fn delete_by_conversation_id(
38-
tx: &TransactionWrapper<'_>,
39-
conversation_id: &[u8],
40-
) -> CryptoKeystoreResult<bool> {
41-
// a slight misuse of this helper, but SQL doesn't care if we end up deleting N rows instead of 1
42-
// with this query
43-
delete_helper::<Self>(tx, "id", conversation_id).await
44-
}
4524
}
4625

4726
impl EntityBase for MlsPendingMessage {

keystore/src/entities/platform/wasm/mls/pending_message.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,6 @@ use crate::{
1414
},
1515
};
1616

17-
impl MlsPendingMessage {
18-
pub async fn find_all_by_conversation_id(
19-
conn: &mut <Self as EntityBase>::ConnectionType,
20-
conversation_id: &[u8],
21-
) -> crate::CryptoKeystoreResult<Vec<Self>> {
22-
let storage = conn.storage();
23-
let id = JsValue::from(Uint8Array::from(conversation_id));
24-
storage.get_all_with_query(Some(id.into())).await
25-
}
26-
27-
pub async fn delete_by_conversation_id(
28-
tx: &<Self as EntityDatabaseMutation<'_>>::Transaction,
29-
conversation_id: &[u8],
30-
) -> crate::CryptoKeystoreResult<bool> {
31-
tx.delete::<Self>(conversation_id).await
32-
}
33-
}
34-
3517
impl EntityBase for MlsPendingMessage {
3618
type ConnectionType = KeystoreDatabaseConnection;
3719
type AutoGeneratedFields = ();

0 commit comments

Comments
 (0)