core_crypto/mls/
proposal.rs

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