Skip to main content

core_crypto/mls/conversation/mutable/
wipe.rs

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