Skip to main content

core_crypto/mls/conversation/mutable/
wipe.rs

1use openmls_traits::OpenMlsCryptoProvider as _;
2
3use super::Result;
4use crate::{KeystoreError, OpenMlsError, RecursiveError, mls::conversation::ConversationMut};
5
6impl ConversationMut {
7    /// Destroys a group locally
8    ///
9    /// # Errors
10    /// KeyStore errors, such as IO
11    pub async fn wipe(&mut self) -> Result<()> {
12        // to the degree that it's easy, fallibly get things before doing any mutation
13        let provider = self.crypto_provider().await?;
14        let mut conversation_cache = self
15            .tx_context
16            .mls_groups()
17            .await
18            .map_err(RecursiveError::transaction("getting mls conversation cache"))?;
19
20        self.mutate_group(async |transaction, group, _| {
21            // the own client may or may not have generated an epoch keypair in the previous epoch
22            // Since it is a terminal operation, ignoring the error is fine here.
23            let _ = group.delete_previous_epoch_keypairs(&provider).await;
24
25            // collect all the relevant proposal refs without holding onto the group;
26            // we'll need to mutate the group in shortly
27            let proposals = group
28                .pending_proposals()
29                .map(|proposal| proposal.proposal_reference().to_owned())
30                .collect::<Vec<_>>();
31            for proposal in proposals {
32                // Update proposals rekey the own leaf node. Hence the associated encryption keypair has to be cleared
33                group
34                    .remove_pending_proposal(transaction, &proposal)
35                    .await
36                    .map_err(OpenMlsError::wrap("removing pending proposal"))?;
37            }
38
39            Ok(())
40        })
41        .await?;
42
43        let id = self.id();
44
45        provider
46            .key_store()
47            .mls_group_delete(id)
48            .await
49            .map_err(KeystoreError::wrap("deleting mls group"))?;
50        let _ = conversation_cache.remove(id);
51
52        Ok(())
53    }
54}