core_crypto/transaction_context/
key_package.rs1use openmls::prelude::{KeyPackage, KeyPackageRef};
4
5use super::{Result, TransactionContext};
6use crate::{Ciphersuite, CredentialType, RecursiveError};
7
8impl TransactionContext {
9 pub async fn get_or_create_client_keypackages(
23 &self,
24 ciphersuite: Ciphersuite,
25 credential_type: CredentialType,
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(
44 &self,
45 ciphersuite: Ciphersuite,
46 credential_type: CredentialType,
47 ) -> Result<usize> {
48 let session = self.session().await?;
49 session
50 .valid_keypackages_count(&self.mls_provider().await?, ciphersuite, credential_type)
51 .await
52 .map_err(RecursiveError::mls_client("counting valid key packages"))
53 .map_err(Into::into)
54 }
55
56 pub async fn delete_keypackages(&self, refs: impl IntoIterator<Item = KeyPackageRef>) -> Result<()> {
59 let mut session = self.session().await?;
60 session
61 .prune_keypackages_and_credential(&self.mls_provider().await?, refs)
62 .await
63 .map_err(RecursiveError::mls_client("pruning key packages and credential"))
64 .map_err(Into::into)
65 }
66}