Skip to main content

MlsContext

Struct MlsContext 

Source
pub struct MlsContext { /* private fields */ }
Expand description

An SFrame context keyed by MLS epochs.

Every member derives its keys from the epoch’s exported secret and its own KIDs (MlsKeyIdLayout): the KIDs with this member’s index encrypt, all the others decrypt. Keys are derived on demand. A decryption key is kept only once a ciphertext has authenticated with it, so forged KIDs do not fill the store.

A new epoch whose low E bits equal an older one’s replaces it, with every key derived from the older one (RFC 9605 section 5.2). An epoch at or below one already introduced with the same low bits is refused, so a removed epoch cannot come back with its counters at 0.

Implementations§

Source§

impl MlsContext

Source

pub fn new( suite: CipherSuite, provider: Arc<dyn RTCCryptoProvider>, layout: MlsKeyIdLayout, sender_index: u64, ) -> Result<Self>

A context for the member at sender_index of the MLS group, with no epoch yet.

Fails with Error::KeyIdLayout when the index does not fit the layout’s S bits.

Source

pub fn with_config( suite: CipherSuite, provider: Arc<dyn RTCCryptoProvider>, layout: MlsKeyIdLayout, sender_index: u64, config: SFrameConfig, ) -> Result<Self>

new with explicit options for the underlying SFrameContext.

Source

pub fn set_max_keys(&mut self, max_keys: usize)

Sets how many derived keys the context holds at most. Beyond it, a KID that needs a new key fails with Error::TooManyKeys until an epoch is replaced or removed.

Source

pub fn layout(&self) -> MlsKeyIdLayout

The KID layout.

Source

pub fn sender_index(&self) -> u64

This member’s index in the MLS group.

Source

pub fn context(&self) -> &SFrameContext

The underlying context: its cipher suite, statistics and stored keys.

Source

pub fn has_epoch(&self, epoch: u64) -> bool

Whether epoch has been introduced and not removed or replaced.

Source

pub fn add_epoch(&mut self, epoch: u64, base_key: &[u8]) -> Result<()>

Introduces epoch with its exported secret (see MLS_EXPORTER_LABEL).

An older epoch with the same low E bits is removed, with all its keys. Introducing an epoch again with the same secret changes nothing. Fails with Error::StaleEpoch when epoch is older than the one its low bits already stand for, was removed, or comes with another secret than before.

Source

pub fn remove_epoch(&mut self, epoch: u64) -> bool

Removes epoch, its secret and every key derived from it. Returns whether it was there. The epoch cannot be introduced again.

Source

pub fn key_id(&self, epoch: u64, context: u64) -> Result<u64>

The KID this member sends with in epoch for its context value.

Source

pub fn encrypt( &mut self, epoch: u64, context: u64, metadata: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>>

Encrypts plaintext as this member in epoch, under the KID of context, and returns the SFrame ciphertext. Fails with Error::UnknownEpoch when the epoch is not held.

Source

pub fn encrypt_into( &mut self, epoch: u64, context: u64, metadata: &[u8], plaintext: &[u8], out: &mut Vec<u8>, ) -> Result<Header>

encrypt, appending the ciphertext to out.

Source

pub fn decrypt(&mut self, metadata: &[u8], ciphertext: &[u8]) -> Result<Vec<u8>>

Decrypts an SFrame ciphertext from another member and returns the plaintext.

The key is found by the KID in the header: the epoch by its low E bits, the sender by its index. A KID with this member’s own index is refused (Error::KeyRoleConflict): its keys encrypt only.

Source

pub fn decrypt_into( &mut self, metadata: &[u8], ciphertext: &[u8], out: &mut Vec<u8>, ) -> Result<Header>

decrypt, appending the plaintext to out. On an error out is as it was.

Trait Implementations§

Source§

impl Debug for MlsContext

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.