openmls/messages/proposals/
app_data_update.rs1use super::*;
2use crate::component::ComponentId;
3
4#[repr(u8)]
6#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Serialize, Deserialize, Hash)]
7pub enum AppDataUpdateOperationType {
8 Update = 1,
10 Remove = 2,
12}
13
14#[repr(u8)]
15#[derive(
16 Debug,
17 PartialEq,
18 Eq,
19 Clone,
20 Serialize,
21 Deserialize,
22 TlsDeserialize,
23 TlsDeserializeBytes,
24 TlsSerialize,
25 TlsSize,
26)]
27pub enum AppDataUpdateOperation {
29 #[tls_codec(discriminant = 1)]
31 Update(VLBytes) = 1,
32 #[tls_codec(discriminant = 2)]
34 Remove = 2,
35}
36
37impl AppDataUpdateOperation {
38 pub fn operation_type(&self) -> AppDataUpdateOperationType {
40 match self {
41 AppDataUpdateOperation::Update(_) => AppDataUpdateOperationType::Update,
42 AppDataUpdateOperation::Remove => AppDataUpdateOperationType::Remove,
43 }
44 }
45}
46
47#[derive(
61 Debug,
62 PartialEq,
63 Clone,
64 Serialize,
65 Deserialize,
66 TlsSize,
67 TlsSerialize,
68 TlsDeserialize,
69 TlsDeserializeBytes,
70)]
71pub struct AppDataUpdateProposal {
72 component_id: ComponentId,
73 operation: AppDataUpdateOperation,
74}
75
76impl AppDataUpdateProposal {
77 pub fn update(component_id: ComponentId, data: impl Into<VLBytes>) -> Self {
79 Self::new(component_id, AppDataUpdateOperation::Update(data.into()))
80 }
81 pub fn remove(component_id: ComponentId) -> Self {
83 Self::new(component_id, AppDataUpdateOperation::Remove)
84 }
85 pub(crate) fn new(component_id: ComponentId, operation: AppDataUpdateOperation) -> Self {
86 Self {
87 component_id,
88 operation,
89 }
90 }
91
92 pub fn component_id(&self) -> ComponentId {
94 self.component_id
95 }
96 pub fn operation(&self) -> &AppDataUpdateOperation {
98 &self.operation
99 }
100}