use core::{
convert::Infallible,
fmt::{self, Debug},
};
use alloc::vec::Vec;
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
use super::{Credential, CredentialType, MlsCredential};
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, MlsSize, MlsEncode, MlsDecode)]
#[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))]
pub struct BasicCredential {
#[mls_codec(with = "mls_rs_codec::byte_vec")]
#[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
pub identifier: Vec<u8>,
}
impl Debug for BasicCredential {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
crate::debug::pretty_bytes(&self.identifier)
.named("BasicCredential")
.fmt(f)
}
}
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)]
impl BasicCredential {
pub fn new(identifier: Vec<u8>) -> BasicCredential {
BasicCredential { identifier }
}
#[cfg(feature = "ffi")]
pub fn identifier(&self) -> &[u8] {
&self.identifier
}
}
impl BasicCredential {
pub fn credential_type() -> CredentialType {
CredentialType::BASIC
}
pub fn into_credential(self) -> Credential {
Credential::Basic(self)
}
}
impl MlsCredential for BasicCredential {
type Error = Infallible;
fn credential_type() -> CredentialType {
Self::credential_type()
}
fn into_credential(self) -> Result<Credential, Self::Error> {
Ok(self.into_credential())
}
}