core_crypto/e2e_identity/
crypto.rs1use super::error::*;
2use crate::{MlsError, prelude::MlsCiphersuite};
3use mls_crypto_provider::PkiKeypair;
4use openmls_basic_credential::SignatureKeyPair as OpenMlsSignatureKeyPair;
5use openmls_traits::types::{Ciphersuite, SignatureScheme};
6use wire_e2e_identity::prelude::JwsAlgorithm;
7use zeroize::Zeroize;
8
9impl TryFrom<MlsCiphersuite> for JwsAlgorithm {
10 type Error = Error;
11
12 fn try_from(cs: MlsCiphersuite) -> Result<Self> {
13 let cs = openmls_traits::types::Ciphersuite::from(cs);
14 Ok(match cs {
15 Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
16 | Ciphersuite::MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 => JwsAlgorithm::Ed25519,
17 Ciphersuite::MLS_128_DHKEMP256_AES128GCM_SHA256_P256 => JwsAlgorithm::P256,
18 Ciphersuite::MLS_256_DHKEMP384_AES256GCM_SHA384_P384 => JwsAlgorithm::P384,
19 Ciphersuite::MLS_256_DHKEMP521_AES256GCM_SHA512_P521 => JwsAlgorithm::P521,
20 Ciphersuite::MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448
21 | Ciphersuite::MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 => return Err(Error::NotYetSupported),
22 })
23 }
24}
25
26#[derive(Debug, serde::Serialize, serde::Deserialize, Zeroize, derive_more::From, derive_more::Deref)]
27#[zeroize(drop)]
28pub struct E2eiSignatureKeypair(Vec<u8>);
29
30impl E2eiSignatureKeypair {
31 pub fn try_new(sc: SignatureScheme, sk: Vec<u8>) -> Result<Self> {
32 let keypair = PkiKeypair::new(sc, sk).map_err(MlsError::wrap("creating new pki keypair"))?;
33 Ok(Self(keypair.signing_key_bytes()))
34 }
35}
36
37impl TryFrom<&OpenMlsSignatureKeyPair> for E2eiSignatureKeypair {
38 type Error = Error;
39
40 fn try_from(kp: &OpenMlsSignatureKeyPair) -> Result<Self> {
41 Self::try_new(kp.signature_scheme(), kp.private().to_vec())
42 }
43}