core_crypto/transaction_context/e2e_identity/
enabled.rs

1//! Utility for clients to get the current state of E2EI when the app resumes
2
3use super::Result;
4use crate::{RecursiveError, transaction_context::TransactionContext};
5use openmls_traits::types::SignatureScheme;
6
7impl TransactionContext {
8    /// See [crate::mls::session::Session::e2ei_is_enabled]
9    pub async fn e2ei_is_enabled(&self, signature_scheme: SignatureScheme) -> Result<bool> {
10        let client = self
11            .session()
12            .await
13            .map_err(RecursiveError::transaction("getting mls client"))?;
14        client
15            .e2ei_is_enabled(signature_scheme)
16            .await
17            .map_err(RecursiveError::mls_client("is e2ei enabled for client?"))
18            .map_err(Into::into)
19    }
20}
21
22#[cfg(test)]
23mod tests {
24    use super::super::Error;
25    use crate::{RecursiveError, mls, prelude::MlsCredentialType, test_utils::*};
26    use openmls_traits::types::SignatureScheme;
27    use wasm_bindgen_test::*;
28
29    wasm_bindgen_test_configure!(run_in_browser);
30
31    #[apply(all_cred_cipher)]
32    #[wasm_bindgen_test]
33    async fn should_be_false_when_basic_and_true_when_x509(case: TestContext) {
34        let [cc] = case.sessions().await;
35        Box::pin(async move {
36            let e2ei_is_enabled = cc.transaction.e2ei_is_enabled(case.signature_scheme()).await.unwrap();
37            match case.credential_type {
38                MlsCredentialType::Basic => assert!(!e2ei_is_enabled),
39                MlsCredentialType::X509 => assert!(e2ei_is_enabled),
40            };
41        })
42        .await
43    }
44
45    #[apply(all_cred_cipher)]
46    #[wasm_bindgen_test]
47    async fn should_fail_when_no_client(case: TestContext) {
48        let cc = SessionContext::new_uninitialized(&case).await;
49        Box::pin(async move {
50            assert!(matches!(
51                cc.transaction.e2ei_is_enabled(case.signature_scheme()).await.unwrap_err(),
52                Error::Recursive(RecursiveError::MlsClient {  source, .. })
53                if matches!(*source, mls::session::Error::MlsNotInitialized)
54            ));
55        })
56        .await
57    }
58
59    #[apply(all_cred_cipher)]
60    #[wasm_bindgen_test]
61    async fn should_fail_when_no_credential_for_given_signature_scheme(case: TestContext) {
62        let [cc] = case.sessions().await;
63        Box::pin(async move {
64            // just return something different from the signature scheme the MlsCentral was initialized with
65            let other_sc = match case.signature_scheme() {
66                SignatureScheme::ED25519 => SignatureScheme::ECDSA_SECP256R1_SHA256,
67                _ => SignatureScheme::ED25519,
68            };
69            assert!(matches!(
70                cc.transaction.e2ei_is_enabled(other_sc).await.unwrap_err(),
71                Error::Recursive(RecursiveError::MlsClient {  source, .. })
72                if matches!(*source, mls::session::Error::CredentialNotFound(_))
73            ));
74        })
75        .await
76    }
77}