wire_e2e_identity/legacy/
crypto.rs1use openmls_traits::types::{Ciphersuite, SignatureScheme};
2use zeroize::Zeroize;
3
4use crate::{
5 JwsAlgorithm,
6 error::{E2eIdentityError, E2eIdentityResult},
7 pki::PkiKeypair,
8};
9
10pub(crate) fn ciphersuite_to_jws_algo(cs: Ciphersuite) -> E2eIdentityResult<JwsAlgorithm> {
11 match cs {
12 Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
13 | Ciphersuite::MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 => Ok(JwsAlgorithm::Ed25519),
14 Ciphersuite::MLS_128_DHKEMP256_AES128GCM_SHA256_P256 => Ok(JwsAlgorithm::P256),
15 Ciphersuite::MLS_256_DHKEMP384_AES256GCM_SHA384_P384 => Ok(JwsAlgorithm::P384),
16 Ciphersuite::MLS_256_DHKEMP521_AES256GCM_SHA512_P521 => Ok(JwsAlgorithm::P521),
17 Ciphersuite::MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448
18 | Ciphersuite::MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 => Err(E2eIdentityError::NotSupported),
19 }
20}
21
22#[derive(Debug, serde::Serialize, serde::Deserialize, Zeroize, derive_more::From, derive_more::Deref)]
23#[zeroize(drop)]
24pub struct E2eiSignatureKeypair(Vec<u8>);
25
26impl E2eiSignatureKeypair {
27 pub fn try_new(sc: SignatureScheme, sk: Vec<u8>) -> E2eIdentityResult<Self> {
28 let keypair = PkiKeypair::new(sc, sk)?;
29 Ok(Self(keypair.signing_key_bytes()))
30 }
31}