use crate::{error::IntoAnyError, extension::ExtensionList, group::GroupContext, time::MlsTime};
#[cfg(mls_build_async)]
use alloc::boxed::Box;
use alloc::vec::Vec;
use super::{CredentialType, SigningIdentity};
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize,))]
#[non_exhaustive]
pub enum MemberValidationContext<'a> {
ForCommit {
current_context: &'a GroupContext,
new_extensions: &'a ExtensionList,
},
ForNewGroup {
current_context: &'a GroupContext,
},
None,
}
impl MemberValidationContext<'_> {
pub fn new_extensions(&self) -> Option<&ExtensionList> {
match self {
Self::ForCommit { new_extensions, .. } => Some(*new_extensions),
Self::ForNewGroup { current_context } => Some(¤t_context.extensions),
Self::None => None,
}
}
}
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)]
#[cfg_attr(mls_build_async, maybe_async::must_be_async)]
pub trait IdentityProvider: Send + Sync {
type Error: IntoAnyError;
async fn validate_member(
&self,
signing_identity: &SigningIdentity,
timestamp: Option<MlsTime>,
context: MemberValidationContext<'_>,
) -> Result<(), Self::Error>;
async fn validate_external_sender(
&self,
signing_identity: &SigningIdentity,
timestamp: Option<MlsTime>,
extensions: Option<&ExtensionList>,
) -> Result<(), Self::Error>;
async fn identity(
&self,
signing_identity: &SigningIdentity,
extensions: &ExtensionList,
) -> Result<Vec<u8>, Self::Error>;
async fn valid_successor(
&self,
predecessor: &SigningIdentity,
successor: &SigningIdentity,
extensions: &ExtensionList,
) -> Result<bool, Self::Error>;
fn supported_types(&self) -> Vec<CredentialType>;
}