core_crypto_ffi/
decrypted_message.rs

1// We can't otherwise silence the deprecation warnings generated by macros on the message definitions
2#![allow(deprecated)]
3
4use core_crypto::prelude::{MlsBufferedConversationDecryptMessage, MlsConversationDecryptMessage};
5#[cfg(target_family = "wasm")]
6use wasm_bindgen::prelude::*;
7
8use crate::{ClientId, CoreCryptoError, CoreCryptoResult, NewCrlDistributionPoints, WireIdentity};
9
10/// See [core_crypto::prelude::MlsConversationDecryptMessage]
11#[derive(Debug)]
12#[cfg_attr(
13    target_family = "wasm",
14    wasm_bindgen(getter_with_clone),
15    derive(serde::Serialize, serde::Deserialize)
16)]
17#[cfg_attr(not(target_family = "wasm"), derive(uniffi::Record))]
18pub struct DecryptedMessage {
19    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly))]
20    pub message: Option<Vec<u8>>,
21    /// It is set to false if ingesting this MLS message has resulted in the client being removed from the group (i.e. a Remove commit)
22    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = isActive))]
23    pub is_active: bool,
24    /// Commit delay hint (in milliseconds) to prevent clients from hammering the server with epoch changes
25    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = commitDelay))]
26    pub commit_delay: Option<u64>,
27    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = senderClientId))]
28    pub sender_client_id: Option<ClientId>,
29    /// true when the decrypted message resulted in an epoch change i.e. it was a commit
30    ///
31    /// Deprecated: this member will be removed in the future. Prefer using the `EpochObserver` interface.
32    #[deprecated = "This member will be removed in the future. Prefer using the `EpochObserver` interface."]
33    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = hasEpochChanged))]
34    pub has_epoch_changed: bool,
35    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly))]
36    pub identity: WireIdentity,
37    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = bufferedMessages))]
38    pub buffered_messages: Option<Vec<BufferedDecryptedMessage>>,
39    /// New CRL Distribution of members of this group
40    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = crlNewDistributionPoints))]
41    pub crl_new_distribution_points: NewCrlDistributionPoints,
42}
43
44impl TryFrom<MlsConversationDecryptMessage> for DecryptedMessage {
45    type Error = CoreCryptoError;
46
47    fn try_from(from: MlsConversationDecryptMessage) -> Result<Self, Self::Error> {
48        let buffered_messages = from
49            .buffered_messages
50            .map(|bm| {
51                bm.into_iter()
52                    .map(TryInto::try_into)
53                    .collect::<CoreCryptoResult<Vec<_>>>()
54            })
55            .transpose()?;
56
57        #[expect(deprecated)]
58        Ok(Self {
59            message: from.app_msg,
60            is_active: from.is_active,
61            commit_delay: from.delay,
62            sender_client_id: from.sender_client_id.map(ClientId),
63            has_epoch_changed: from.has_epoch_changed,
64            identity: from.identity.into(),
65            buffered_messages,
66            crl_new_distribution_points: from.crl_new_distribution_points.into(),
67        })
68    }
69}
70
71/// to avoid recursive structs
72#[derive(Debug, Clone)]
73#[cfg_attr(
74    target_family = "wasm",
75    wasm_bindgen(getter_with_clone),
76    derive(serde::Serialize, serde::Deserialize)
77)]
78#[cfg_attr(not(target_family = "wasm"), derive(uniffi::Record))]
79pub struct BufferedDecryptedMessage {
80    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly))]
81    pub message: Option<Vec<u8>>,
82    /// It is set to false if ingesting this MLS message has resulted in the client being removed from the group (i.e. a Remove commit)
83    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = isActive))]
84    pub is_active: bool,
85    /// Commit delay hint (in milliseconds) to prevent clients from hammering the server with epoch changes
86    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = commitDelay))]
87    pub commit_delay: Option<u64>,
88    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = senderClientId))]
89    pub sender_client_id: Option<ClientId>,
90    /// true when the decrypted message resulted in an epoch change i.e. it was a commit
91    ///
92    /// Deprecated: this member will be removed in the future. Prefer using the `EpochObserver` interface.
93    #[deprecated = "This member will be removed in the future. Prefer using the `EpochObserver` interface."]
94    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = hasEpochChanged))]
95    pub has_epoch_changed: bool,
96    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly))]
97    pub identity: WireIdentity,
98    /// New CRL Distribution of members of this group
99    #[cfg_attr(target_family = "wasm", wasm_bindgen(readonly, js_name = crlNewDistributionPoints))]
100    pub crl_new_distribution_points: NewCrlDistributionPoints,
101}
102
103impl TryFrom<MlsBufferedConversationDecryptMessage> for BufferedDecryptedMessage {
104    type Error = CoreCryptoError;
105
106    fn try_from(from: MlsBufferedConversationDecryptMessage) -> Result<Self, Self::Error> {
107        #[expect(deprecated)]
108        Ok(Self {
109            message: from.app_msg,
110            is_active: from.is_active,
111            commit_delay: from.delay,
112            sender_client_id: from.sender_client_id.map(ClientId),
113            has_epoch_changed: from.has_epoch_changed,
114            identity: from.identity.into(),
115            crl_new_distribution_points: from.crl_new_distribution_points.into(),
116        })
117    }
118}