core_crypto/mls/conversation/
credential.rs1use std::collections::HashMap;
2
3use openmls::prelude::{Credential as MlsCredential, CredentialWithKey, SignaturePublicKey};
4
5use super::{Error, Result};
6use crate::{CredentialType, MlsConversation, RecursiveError};
7
8impl MlsConversation {
9 pub fn members(&self) -> HashMap<Vec<u8>, MlsCredential> {
11 self.group.members().fold(HashMap::new(), |mut acc, kp| {
12 let credential = kp.credential;
13 let id = credential.identity().to_vec();
14 acc.entry(id).or_insert(credential);
15 acc
16 })
17 }
18
19 pub fn members_with_key(&self) -> HashMap<Vec<u8>, CredentialWithKey> {
21 self.group.members().fold(HashMap::new(), |mut acc, kp| {
22 let credential = kp.credential;
23 let id = credential.identity().to_vec();
24 let signature_key = SignaturePublicKey::from(kp.signature_key);
25 let credential = CredentialWithKey {
26 credential,
27 signature_key,
28 };
29 acc.entry(id).or_insert(credential);
30 acc
31 })
32 }
33
34 pub(crate) fn own_mls_credential(&self) -> Result<&MlsCredential> {
35 let credential = self
36 .group
37 .own_leaf_node()
38 .ok_or(Error::MlsGroupInvalidState("own_leaf_node not present in group"))?
39 .credential();
40 Ok(credential)
41 }
42
43 pub(crate) fn own_credential_type(&self) -> Result<CredentialType> {
44 self.own_mls_credential().and_then(|credential| {
45 credential
46 .credential_type()
47 .try_into()
48 .map_err(RecursiveError::mls_credential(
49 "getting credential type from conversation",
50 ))
51 .map_err(Into::into)
52 })
53 }
54}