// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // Copyright by contributors to this project. // SPDX-License-Identifier: (Apache-2.0 OR MIT)
use core::{
fmt::{self, Debug},
ops::Deref,
};
use alloc::vec::Vec; use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
impl Deref for CredentialType { type Target = u16;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone, MlsSize, MlsEncode, MlsDecode, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] // #[cfg_attr( // all(feature = "ffi", not(test)), // safer_ffi_gen::ffi_type(clone, opaque) // )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// Custom user created credential type. /// /// # Warning /// /// In order to use a custom credential within an MLS group, a supporting /// [`IdentityProvider`](crate::identity::IdentityProvider) must be created that can /// authenticate the credential. pubstruct CustomCredential { /// Unique credential type to identify this custom credential. pub credential_type: CredentialType, /// Opaque data representing this custom credential. #[mls_codec(with = "mls_rs_codec::byte_vec")] #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))] pub data: Vec<u8>,
}
// #[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)] impl CustomCredential { /// Create a new custom credential with opaque data. /// /// # Warning /// /// Using any of the constants defined within [`CredentialType`] will /// result in unspecified behavior. pubfn new(credential_type: CredentialType, data: Vec<u8>) -> CustomCredential {
CustomCredential {
credential_type,
data,
}
}
/// Unique credential type to identify this custom credential. #[cfg(feature = "ffi")] pubfn credential_type(&self) -> CredentialType { self.credential_type
}
/// Opaque data representing this custom credential. #[cfg(feature = "ffi")] pubfn data(&self) -> &[u8] {
&self.data
}
}
/// A MLS credential used to authenticate a group member. #[derive(Clone, Debug, PartialEq, Ord, PartialOrd, Eq, Hash)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] // #[cfg_attr( // all(feature = "ffi", not(test)), // safer_ffi_gen::ffi_type(clone, opaque) // )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[non_exhaustive] pubenum Credential { /// Basic identifier-only credential. /// /// # Warning /// /// Basic credentials are inherently insecure since they can not be /// properly validated. It is not recommended to use [`BasicCredential`] /// in production applications.
Basic(BasicCredential), #[cfg(feature = "x509")] /// X.509 Certificate chain.
X509(CertificateChain), /// User provided custom credential.
Custom(CustomCredential),
}
/// Convert this enum into a [`BasicCredential`] /// /// Returns `None` if this credential is any other type. pubfn as_basic(&self) -> Option<&BasicCredential> { matchself {
Credential::Basic(basic) => Some(basic),
_ => None,
}
}
/// Convert this enum into a [`CertificateChain`] /// /// Returns `None` if this credential is any other type. #[cfg(feature = "x509")] pubfn as_x509(&self) -> Option<&CertificateChain> { matchself {
Credential::X509(chain) => Some(chain),
_ => None,
}
}
/// Convert this enum into a [`CustomCredential`] /// /// Returns `None` if this credential is any other type. pubfn as_custom(&self) -> Option<&CustomCredential> { matchself {
Credential::Custom(custom) => Some(custom),
_ => None,
}
}
}
/// Trait that provides a conversion between an underlying credential type and /// the [`Credential`] enum. pubtrait MlsCredential: Sized { /// Conversion error type. type Error;
/// Credential type represented by this type. fn credential_type() -> CredentialType;
/// Function to convert this type into a [`Credential`] enum. fn into_credential(self) -> Result<Credential, Self::Error>;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-22)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.