core_crypto/mls/
ciphersuite.rs1use crate::prelude::CiphersuiteName;
2use crate::{CryptoError, CryptoResult};
3use openmls_traits::types::{Ciphersuite, HashType};
4use wire_e2e_identity::prelude::HashAlgorithm;
5
6#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, derive_more::Deref, serde::Serialize, serde::Deserialize)]
7#[serde(transparent)]
8#[repr(transparent)]
9pub struct MlsCiphersuite(pub(crate) Ciphersuite);
11
12impl MlsCiphersuite {
13 pub(crate) fn e2ei_hash_alg(&self) -> HashAlgorithm {
14 match self.0.hash_algorithm() {
15 HashType::Sha2_256 => HashAlgorithm::SHA256,
16 HashType::Sha2_384 => HashAlgorithm::SHA384,
17 HashType::Sha2_512 => HashAlgorithm::SHA512,
18 }
19 }
20}
21
22impl Default for MlsCiphersuite {
23 fn default() -> Self {
24 Self(Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519)
25 }
26}
27
28impl From<Ciphersuite> for MlsCiphersuite {
29 fn from(value: Ciphersuite) -> Self {
30 Self(value)
31 }
32}
33
34impl From<MlsCiphersuite> for Ciphersuite {
35 fn from(ciphersuite: MlsCiphersuite) -> Self {
36 ciphersuite.0
37 }
38}
39
40impl From<MlsCiphersuite> for u16 {
41 fn from(cs: MlsCiphersuite) -> Self {
42 (&cs.0).into()
43 }
44}
45
46impl TryFrom<u16> for MlsCiphersuite {
47 type Error = CryptoError;
48
49 fn try_from(c: u16) -> CryptoResult<Self> {
50 Ok(CiphersuiteName::try_from(c)
51 .map_err(|_| CryptoError::ImplementationError)?
52 .into())
53 }
54}