core_crypto/mls/conversation/
group_info.rs1use openmls::prelude::{MlsMessageOut, group_info::GroupInfo};
2use serde::{Deserialize, Serialize};
3
4use super::Result;
5use crate::TlsCodecError;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct GroupInfoBundle {
10 pub encryption_type: GroupInfoEncryptionType,
12 pub ratchet_tree_type: RatchetTreeType,
14 pub payload: GroupInfoPayload,
16}
17
18impl GroupInfoBundle {
19 pub(crate) fn try_new_full_plaintext(gi: GroupInfo) -> Result<Self> {
21 use tls_codec::Serialize as _;
22
23 let payload = MlsMessageOut::from(gi);
24 let payload = payload
25 .tls_serialize_detached()
26 .map_err(TlsCodecError::serialize("unencrypted mls message"))?;
27 Ok(Self {
28 encryption_type: GroupInfoEncryptionType::Plaintext,
29 ratchet_tree_type: RatchetTreeType::Full,
30 payload: GroupInfoPayload::Plaintext(payload),
31 })
32 }
33}
34
35#[cfg(test)]
36impl GroupInfoBundle {
37 #![allow(missing_docs)]
39
40 pub fn get_group_info(self) -> openmls::prelude::group_info::VerifiableGroupInfo {
41 match self.get_payload().extract() {
42 openmls::prelude::MlsMessageInBody::GroupInfo(vgi) => vgi,
43 _ => panic!("This payload should contain a GroupInfo"),
44 }
45 }
46
47 pub fn get_payload(mut self) -> openmls::prelude::MlsMessageIn {
48 use tls_codec::Deserialize as _;
49 match &mut self.payload {
50 GroupInfoPayload::Plaintext(gi) => {
51 openmls::prelude::MlsMessageIn::tls_deserialize(&mut gi.as_slice()).unwrap()
52 }
53 }
54 }
55}
56
57#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
70#[repr(u8)]
71pub enum GroupInfoEncryptionType {
72 Plaintext = 1,
74 JweEncrypted = 2,
76}
77
78#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
91#[repr(u8)]
92pub enum RatchetTreeType {
93 Full = 1,
95 Delta = 2,
98 ByRef = 3,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
104pub enum GroupInfoPayload {
105 Plaintext(Vec<u8>),
107 }
110
111impl GroupInfoPayload {
112 pub fn bytes(self) -> Vec<u8> {
114 match self {
115 GroupInfoPayload::Plaintext(gi) => gi,
116 }
117 }
118}