use std::fmt::Display;
use serde::{Deserialize, Serialize};
use tls_codec::*;
use crate::extensions::*;
use openmls_traits::random::OpenMlsRand;
#[cfg(test)]
use crate::ciphersuite::*;
#[cfg(test)]
use crate::utils::*;
pub(crate) mod errors;
pub(crate) mod mls_group;
pub(crate) mod public_group;
pub use errors::*;
pub use group_context::GroupContext;
pub use mls_group::config::*;
pub use mls_group::membership::*;
pub use mls_group::proposal_store::*;
pub use mls_group::staged_commit::StagedCommit;
pub use mls_group::{Member, *};
pub use public_group::*;
mod group_context;
#[cfg(any(feature = "test-utils", test))]
pub(crate) mod tests_and_kats;
#[derive(
Clone,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Deserialize,
Serialize,
TlsDeserialize,
TlsDeserializeBytes,
TlsSerialize,
TlsSize,
)]
pub struct GroupId {
value: VLBytes,
}
impl GroupId {
pub fn random(rng: &impl OpenMlsRand) -> Self {
Self {
value: rng.random_vec(16).expect("Not enough randomness.").into(),
}
}
pub fn from_slice(bytes: &[u8]) -> Self {
GroupId {
value: bytes.into(),
}
}
pub fn as_slice(&self) -> &[u8] {
self.value.as_slice()
}
pub fn to_vec(&self) -> Vec<u8> {
self.value.clone().into()
}
}
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Deserialize,
Serialize,
TlsDeserialize,
TlsDeserializeBytes,
TlsSerialize,
TlsSize,
)]
pub struct GroupEpoch(u64);
impl GroupEpoch {
pub(crate) fn increment(&mut self) {
self.0 += 1;
}
pub fn as_u64(&self) -> u64 {
self.0
}
}
impl From<u64> for GroupEpoch {
fn from(val: u64) -> Self {
Self(val)
}
}
impl Display for GroupEpoch {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.0))
}
}