mls_rs_core/identity/
basic.rs1use core::{
6 convert::Infallible,
7 fmt::{self, Debug},
8};
9
10use alloc::vec::Vec;
11use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
12
13use super::{Credential, CredentialType, MlsCredential};
14
15#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, MlsSize, MlsEncode, MlsDecode)]
16#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
17#[cfg_attr(
18 all(feature = "ffi", not(test)),
19 safer_ffi_gen::ffi_type(clone, opaque)
20)]
21#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
22pub struct BasicCredential {
33 #[mls_codec(with = "mls_rs_codec::byte_vec")]
35 #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
36 pub identifier: Vec<u8>,
37}
38
39impl Debug for BasicCredential {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 crate::debug::pretty_bytes(&self.identifier)
42 .named("BasicCredential")
43 .fmt(f)
44 }
45}
46
47#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)]
48impl BasicCredential {
49 pub fn new(identifier: Vec<u8>) -> BasicCredential {
51 BasicCredential { identifier }
52 }
53
54 #[cfg(feature = "ffi")]
56 pub fn identifier(&self) -> &[u8] {
57 &self.identifier
58 }
59}
60
61impl BasicCredential {
62 pub fn credential_type() -> CredentialType {
63 CredentialType::BASIC
64 }
65
66 pub fn into_credential(self) -> Credential {
67 Credential::Basic(self)
68 }
69}
70
71impl MlsCredential for BasicCredential {
72 type Error = Infallible;
73
74 fn credential_type() -> CredentialType {
75 Self::credential_type()
76 }
77
78 fn into_credential(self) -> Result<Credential, Self::Error> {
79 Ok(self.into_credential())
80 }
81}