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