use gbp_mls::MlsContext;
use crate::error::SFrameError;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CipherSuite {
Aes128Gcm,
Aes256Gcm,
}
impl CipherSuite {
pub fn from_u8(v: u8) -> Option<Self> {
match v {
0 => Some(Self::Aes128Gcm),
1 => Some(Self::Aes256Gcm),
_ => None,
}
}
pub fn as_u8(self) -> u8 {
match self {
Self::Aes128Gcm => 0,
Self::Aes256Gcm => 1,
}
}
pub(crate) fn to_sframe(self) -> sframe::CipherSuite {
match self {
Self::Aes128Gcm => sframe::CipherSuite::AesGcm128Sha256,
Self::Aes256Gcm => sframe::CipherSuite::AesGcm256Sha512,
}
}
}
pub fn derive_base_key(mls: &MlsContext, label: &str, epoch: u64) -> Result<[u8; 32], SFrameError> {
let context = epoch.to_be_bytes();
let raw = mls
.export_raw(label, &context, 32)
.map_err(|e| SFrameError::MlsExport(e.to_string()))?;
let mut out = [0u8; 32];
out.copy_from_slice(&raw);
Ok(out)
}