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(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18pub struct BasicCredential {
29 #[mls_codec(with = "mls_rs_codec::byte_vec")]
31 #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
32 pub identifier: Vec<u8>,
33}
34
35impl Debug for BasicCredential {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 crate::debug::pretty_bytes(&self.identifier)
38 .named("BasicCredential")
39 .fmt(f)
40 }
41}
42
43impl BasicCredential {
44 pub fn new(identifier: Vec<u8>) -> BasicCredential {
46 BasicCredential { identifier }
47 }
48
49 pub fn identifier(&self) -> &[u8] {
51 &self.identifier
52 }
53}
54
55impl BasicCredential {
56 pub fn credential_type() -> CredentialType {
57 CredentialType::BASIC
58 }
59
60 pub fn into_credential(self) -> Credential {
61 Credential::Basic(self)
62 }
63}
64
65impl MlsCredential for BasicCredential {
66 type Error = Infallible;
67
68 fn credential_type() -> CredentialType {
69 Self::credential_type()
70 }
71
72 fn into_credential(self) -> Result<Credential, Self::Error> {
73 Ok(self.into_credential())
74 }
75}