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