mls_spec/messages/
content_type.rs1use crate::{
2 MlsSpecError,
3 group::{commits::Commit, proposals::Proposal},
4};
5
6#[derive(
7 Debug,
8 Clone,
9 Copy,
10 PartialEq,
11 Eq,
12 tls_codec::TlsSerialize,
13 tls_codec::TlsDeserialize,
14 tls_codec::TlsSize,
15 strum::Display,
16)]
17#[strum(prefix = "ContentType")]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19#[repr(u8)]
20#[non_exhaustive]
21pub enum ContentType {
22 Reserved = 0x00,
23 Application = 0x01,
24 Proposal = 0x02,
25 Commit = 0x03,
26 #[cfg(feature = "draft-mularczyk-mls-splitcommit")]
27 SplitCommit = 0x04,
28}
29
30impl TryFrom<u8> for ContentType {
31 type Error = MlsSpecError;
32
33 fn try_from(value: u8) -> Result<Self, Self::Error> {
34 let ct = match value {
35 0x00 => Self::Reserved,
36 0x01 => Self::Application,
37 0x02 => Self::Proposal,
38 0x03 => Self::Commit,
39 #[cfg(feature = "draft-mularczyk-mls-splitcommit")]
40 0x04 => Self::SplitCommit,
41 _ => return Err(MlsSpecError::InvalidContentType),
42 };
43
44 Ok(ct)
45 }
46}
47
48#[derive(
49 Debug,
50 Clone,
51 PartialEq,
52 Eq,
53 tls_codec::TlsSerialize,
54 tls_codec::TlsDeserialize,
55 tls_codec::TlsSize,
56)]
57#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
58#[repr(u8)]
59pub enum ContentTypeInner {
60 #[tls_codec(discriminant = "ContentType::Application")]
61 Application {
62 #[tls_codec(with = "crate::tlspl::bytes")]
63 application_data: Vec<u8>,
64 },
65 #[tls_codec(discriminant = "ContentType::Proposal")]
66 Proposal { proposal: Proposal },
67 #[tls_codec(discriminant = "ContentType::Commit")]
68 Commit { commit: Commit },
69 #[cfg(feature = "draft-mularczyk-mls-splitcommit")]
70 #[tls_codec(discriminant = "ContentType::SplitCommit")]
71 SplitCommit {
72 split_commit: crate::drafts::split_commit::SplitCommit,
73 },
74}
75
76impl From<&ContentTypeInner> for ContentType {
77 fn from(value: &ContentTypeInner) -> Self {
78 match value {
79 ContentTypeInner::Application { .. } => ContentType::Application,
80 ContentTypeInner::Proposal { .. } => ContentType::Proposal,
81 ContentTypeInner::Commit { .. } => ContentType::Commit,
82 #[cfg(feature = "draft-mularczyk-mls-splitcommit")]
83 ContentTypeInner::SplitCommit { .. } => ContentType::SplitCommit,
84 }
85 }
86}