2026-06-02 15:21:21 -07:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
|
|
|
|
|
use openmls::credentials::{BasicCredential, CredentialWithKey};
|
|
|
|
|
use openmls_traits::{
|
|
|
|
|
signatures::{Signer, SignerError},
|
|
|
|
|
types::SignatureScheme,
|
|
|
|
|
};
|
2026-06-10 06:59:04 -07:00
|
|
|
use shared_traits::IdentIdRef;
|
2026-06-02 15:21:21 -07:00
|
|
|
|
2026-06-10 06:59:04 -07:00
|
|
|
use crate::IdentityProvider;
|
2026-06-02 15:21:21 -07:00
|
|
|
|
|
|
|
|
/// A Wrapper for an IdentityProvider which provides MLS specific functionality
|
|
|
|
|
///
|
|
|
|
|
/// This type stops OpenMLS internal from leaking outside of the crate.
|
|
|
|
|
/// Developers provider a simple IdentitityProvider, and Signer and Credential generation
|
|
|
|
|
/// is provided
|
|
|
|
|
pub struct MlsIdentityProvider<T: IdentityProvider>(T);
|
|
|
|
|
|
|
|
|
|
impl<T: IdentityProvider> MlsIdentityProvider<T> {
|
|
|
|
|
pub fn new(inner: T) -> Self {
|
|
|
|
|
Self(inner)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_credential(&self) -> CredentialWithKey {
|
|
|
|
|
CredentialWithKey {
|
2026-06-10 06:59:04 -07:00
|
|
|
credential: BasicCredential::new(self.id().as_str().as_bytes().to_vec()).into(),
|
2026-06-02 15:21:21 -07:00
|
|
|
signature_key: self.public_key().as_ref().into(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: IdentityProvider> Deref for MlsIdentityProvider<T> {
|
|
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
|
&self.0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: IdentityProvider> IdentityProvider for MlsIdentityProvider<T> {
|
2026-06-10 06:59:04 -07:00
|
|
|
fn id(&self) -> IdentIdRef<'_> {
|
|
|
|
|
self.0.id()
|
2026-06-02 15:21:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn display_name(&self) -> String {
|
|
|
|
|
self.0.display_name()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn sign(&self, payload: &[u8]) -> crypto::Ed25519Signature {
|
|
|
|
|
self.0.sign(payload)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn public_key(&self) -> &crypto::Ed25519VerifyingKey {
|
|
|
|
|
self.0.public_key()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Implement Signer directly for MlsIdentityProvider, so that openmls Signer contstraint
|
|
|
|
|
// does not leave the module.
|
|
|
|
|
impl<T: IdentityProvider> Signer for MlsIdentityProvider<T> {
|
|
|
|
|
fn sign(&self, payload: &[u8]) -> Result<Vec<u8>, SignerError> {
|
|
|
|
|
Ok(self.0.sign(payload).as_ref().to_vec())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn signature_scheme(&self) -> SignatureScheme {
|
|
|
|
|
SignatureScheme::ED25519
|
|
|
|
|
}
|
|
|
|
|
}
|