openmls/
component.rs

1//! Components from the extensions draft.
2
3use tls_codec::{TlsSerialize, TlsSize, VLBytes};
4
5/// A ComponentId that uniquely identifies a component within the scope of an application.
6pub type ComponentId = u16;
7
8/// Label for safe encryption/decryption as defined in Section 4.2 of the MLS Extensions draft
9#[derive(Debug, TlsSerialize, TlsSize)]
10pub(crate) struct ComponentOperationLabel {
11    /// "Application"
12    base_label: VLBytes,
13    component_id: ComponentId,
14    label: VLBytes,
15}
16
17const COMPONENT_OPERATION_BASE_LABEL: &[u8] = b"Application";
18
19impl ComponentOperationLabel {
20    /// Creates a new ComponentOperationLabel, prefixed with "Application"
21    pub fn new(component_id: ComponentId, label: &str) -> Self {
22        Self {
23            base_label: COMPONENT_OPERATION_BASE_LABEL.into(),
24            component_id,
25            label: label.as_bytes().into(),
26        }
27    }
28}