core_crypto/mls/
proposal.rs

1use crate::mls::ClientId;
2use openmls::prelude::{KeyPackage, hash_ref::ProposalRef};
3
4/// Abstraction over a [openmls::prelude::hash_ref::ProposalRef] to deal with conversions
5#[derive(Debug, Clone, Eq, PartialEq, derive_more::From, derive_more::Deref, derive_more::Display)]
6pub struct MlsProposalRef(ProposalRef);
7
8impl From<Vec<u8>> for MlsProposalRef {
9    fn from(value: Vec<u8>) -> Self {
10        Self(ProposalRef::from_slice(value.as_slice()))
11    }
12}
13
14impl MlsProposalRef {
15    /// Duh
16    pub fn into_inner(self) -> ProposalRef {
17        self.0
18    }
19
20    pub(crate) fn to_bytes(&self) -> Vec<u8> {
21        self.0.as_slice().to_vec()
22    }
23}
24
25#[cfg(test)]
26impl From<MlsProposalRef> for Vec<u8> {
27    fn from(prop_ref: MlsProposalRef) -> Self {
28        prop_ref.0.as_slice().to_vec()
29    }
30}
31
32/// Internal representation of proposal to ease further additions
33// To solve the clippy issue we'd need to box the `KeyPackage`, but we can't because we need an
34// owned value of it. We can have it when Box::into_inner is stablized.
35// https://github.com/rust-lang/rust/issues/80437
36#[allow(clippy::large_enum_variant)]
37pub enum MlsProposal {
38    /// Requests that a client with a specified KeyPackage be added to the group
39    Add(KeyPackage),
40    /// Similar mechanism to Add with the distinction that it replaces
41    /// the sender's LeafNode in the tree instead of adding a new leaf to the tree
42    Update,
43    /// Requests that the member with LeafNodeRef removed be removed from the group
44    Remove(ClientId),
45}