core_crypto/mls/session/
credential.rs

1use std::sync::Arc;
2
3use core_crypto_keystore::traits::FetchFromDatabase;
4use openmls::prelude::SignaturePublicKey;
5
6use super::Result;
7use crate::{Credential, CredentialFindFilters, CredentialRef, RecursiveError, Session};
8
9impl<D> Session<D> {
10    /// Find all credentials known by this session which match the specified conditions.
11    ///
12    /// If no filters are set, this is equivalent to [`Self::get_credentials`].
13    pub async fn find_credentials(&self, find_filters: CredentialFindFilters<'_>) -> Result<Vec<CredentialRef>>
14    where
15        D: FetchFromDatabase,
16    {
17        CredentialRef::find(self.database(), find_filters)
18            .await
19            .map_err(RecursiveError::mls_credential_ref("finding credentials with filters"))
20            .map_err(Into::into)
21    }
22
23    /// Get all credentials known by this session.
24    pub async fn get_credentials(&self) -> Result<Vec<CredentialRef>>
25    where
26        D: FetchFromDatabase,
27    {
28        self.find_credentials(Default::default()).await
29    }
30
31    /// convenience function deferring to the implementation on the inner type
32    pub(crate) async fn find_credential_by_public_key(&self, public_key: &SignaturePublicKey) -> Result<Arc<Credential>>
33    where
34        D: FetchFromDatabase,
35    {
36        let credential = Credential::find_by_public_key(&self.database, public_key)
37            .await
38            .map_err(RecursiveError::mls_credential("getting credential by public key"))?;
39        Ok(Arc::new(credential))
40    }
41}