1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use tls_codec::{TlsDeserialize, TlsDeserializeBytes, TlsSerialize, TlsSize};

use super::{Deserialize, Serialize};
use crate::treesync::{RatchetTree, RatchetTreeIn};

/// # Ratchet Tree Extension.
///
/// The ratchet tree extension contains a list of (optional) [`Node`](crate::treesync::node::Node)s that
/// represent the public state of the tree in an MLS group.
///
/// ```c
/// // draft-ietf-mls-protocol-17
/// optional<Node> ratchet_tree<V>;
/// ```
#[derive(
    PartialEq,
    Eq,
    Clone,
    Debug,
    Serialize,
    Deserialize,
    TlsSerialize,
    TlsDeserialize,
    TlsDeserializeBytes,
    TlsSize,
)]
pub struct RatchetTreeExtension {
    ratchet_tree: RatchetTreeIn,
}

impl RatchetTreeExtension {
    /// Build a new extension from a vector of [`Node`](crate::treesync::node::Node)s.
    pub fn new(ratchet_tree: RatchetTree) -> Self {
        RatchetTreeExtension {
            ratchet_tree: ratchet_tree.into(),
        }
    }

    /// Return the [`RatchetTreeIn`] from this extension.
    pub fn ratchet_tree(&self) -> &RatchetTreeIn {
        &self.ratchet_tree
    }
}