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