use serde::{Deserialize, Serialize};
use tls_codec::*;
use crate::{
ciphersuite::*,
credentials::*,
group::*,
messages::{proposals::*, *},
schedule::{message_secrets::*, *},
};
pub(crate) mod codec;
pub(crate) mod message_in;
pub(crate) mod message_out;
pub(crate) mod mls_auth_content;
pub(crate) mod mls_auth_content_in;
pub(crate) mod mls_content;
pub(crate) mod mls_content_in;
pub(crate) mod private_message;
pub(crate) mod private_message_in;
pub(crate) mod public_message;
pub(crate) mod public_message_in;
pub(crate) mod sender;
pub(crate) mod validation;
pub(crate) use errors::*;
#[cfg(test)]
pub(crate) use mls_auth_content::*;
#[cfg(test)]
pub(crate) use mls_auth_content_in::*;
#[cfg(test)]
pub(crate) use mls_content::*;
#[cfg(test)]
pub(crate) use mls_content_in::*;
pub(crate) use sender::*;
pub mod errors;
pub use message_in::*;
pub use message_out::*;
pub use private_message::*;
pub use private_message_in::*;
pub use public_message::*;
pub use public_message_in::*;
pub use sender::*;
pub use validation::*;
#[cfg(test)]
pub(crate) mod tests;
#[derive(
PartialEq,
Eq,
Clone,
Copy,
Debug,
Serialize,
Deserialize,
TlsDeserialize,
TlsDeserializeBytes,
TlsSerialize,
TlsSize,
)]
#[repr(u16)]
pub enum WireFormat {
PublicMessage = 1,
PrivateMessage = 2,
Welcome = 3,
GroupInfo = 4,
KeyPackage = 5,
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub(crate) struct FramingParameters<'a> {
aad: &'a [u8],
wire_format: WireFormat,
}
impl<'a> FramingParameters<'a> {
pub(crate) fn new(aad: &'a [u8], wire_format: impl Into<WireFormat>) -> Self {
Self {
aad,
wire_format: wire_format.into(),
}
}
pub(crate) fn aad(&self) -> &'a [u8] {
self.aad
}
pub(crate) fn wire_format(&self) -> WireFormat {
self.wire_format
}
}
#[derive(
PartialEq,
Eq,
Clone,
Copy,
Debug,
Serialize,
Deserialize,
TlsDeserialize,
TlsDeserializeBytes,
TlsSerialize,
TlsSize,
)]
#[repr(u8)]
pub enum ContentType {
Application = 1,
Proposal = 2,
Commit = 3,
}
impl TryFrom<u8> for ContentType {
type Error = tls_codec::Error;
fn try_from(value: u8) -> Result<Self, tls_codec::Error> {
match value {
1 => Ok(ContentType::Application),
2 => Ok(ContentType::Proposal),
3 => Ok(ContentType::Commit),
_ => Err(tls_codec::Error::DecodingError(format!(
"{value} is not a valid content type"
))),
}
}
}
impl ContentType {
pub(crate) fn is_handshake_message(&self) -> bool {
self == &ContentType::Proposal || self == &ContentType::Commit
}
}