core_crypto/transaction_context/
key_package.rs1use openmls::prelude::{KeyPackage, KeyPackageRef};
4
5use super::{Result, TransactionContext};
6use crate::{MlsCiphersuite, MlsCredentialType, RecursiveError};
7
8impl TransactionContext {
9 pub async fn get_or_create_client_keypackages(
23 &self,
24 ciphersuite: MlsCiphersuite,
25 credential_type: MlsCredentialType,
26 amount_requested: usize,
27 ) -> Result<Vec<KeyPackage>> {
28 let session = self.session().await?;
29 session
30 .request_key_packages(
31 amount_requested,
32 ciphersuite,
33 credential_type,
34 &self.mls_provider().await?,
35 )
36 .await
37 .map_err(RecursiveError::mls_client("requesting key packages"))
38 .map_err(Into::into)
39 }
40
41 pub async fn client_valid_key_packages_count(
43 &self,
44 ciphersuite: MlsCiphersuite,
45 credential_type: MlsCredentialType,
46 ) -> Result<usize> {
47 let session = self.session().await?;
48 session
49 .valid_keypackages_count(&self.mls_provider().await?, ciphersuite, credential_type)
50 .await
51 .map_err(RecursiveError::mls_client("counting valid key packages"))
52 .map_err(Into::into)
53 }
54
55 pub async fn delete_keypackages(&self, refs: impl IntoIterator<Item = KeyPackageRef>) -> Result<()> {
58 let mut session = self.session().await?;
59 session
60 .prune_keypackages_and_credential(&self.mls_provider().await?, refs)
61 .await
62 .map_err(RecursiveError::mls_client("pruning key packages and credential"))
63 .map_err(Into::into)
64 }
65}