openmls/extensions/
ratchet_tree_extension.rs

1use tls_codec::{TlsDeserialize, TlsDeserializeBytes, TlsSerialize, TlsSize};
2
3use super::{Deserialize, Serialize};
4use crate::treesync::{RatchetTree, RatchetTreeIn};
5
6/// # Ratchet Tree Extension.
7///
8/// The ratchet tree extension contains a list of (optional) [`Node`](crate::treesync::node::Node)s that
9/// represent the public state of the tree in an MLS group.
10///
11/// ```c
12/// // draft-ietf-mls-protocol-17
13/// optional<Node> ratchet_tree<V>;
14/// ```
15#[derive(
16    PartialEq,
17    Eq,
18    Clone,
19    Debug,
20    Serialize,
21    Deserialize,
22    TlsSerialize,
23    TlsDeserialize,
24    TlsDeserializeBytes,
25    TlsSize,
26)]
27pub struct RatchetTreeExtension {
28    ratchet_tree: RatchetTreeIn,
29}
30
31impl RatchetTreeExtension {
32    /// Build a new extension from a vector of [`Node`](crate::treesync::node::Node)s.
33    pub fn new(ratchet_tree: RatchetTree) -> Self {
34        RatchetTreeExtension {
35            ratchet_tree: ratchet_tree.into(),
36        }
37    }
38
39    /// Return the [`RatchetTreeIn`] from this extension.
40    pub fn ratchet_tree(&self) -> &RatchetTreeIn {
41        &self.ratchet_tree
42    }
43}