obfuscate/impls/
openmls.rs1use openmls::credentials::Certificate;
2use openmls::prelude::{
3 BasicCredential, Credential, KeyPackageSecretEncapsulation, Member, MlsCredentialType, Proposal, QueuedProposal,
4 Sender,
5};
6use std::fmt::Formatter;
7
8use crate::{Obfuscate, compute_hash};
9
10impl Obfuscate for Proposal {
11 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
12 f.write_str(match self {
13 Proposal::Add(_) => "Add",
14 Proposal::Update(_) => "Update",
15 Proposal::Remove(_) => "Remove",
16 Proposal::PreSharedKey(_) => "PreSharedKey",
17 Proposal::ReInit(_) => "ReInit",
18 Proposal::ExternalInit(_) => "ExternalInit",
19 Proposal::AppAck(_) => "AppAck",
20 Proposal::GroupContextExtensions(_) => "GroupContextExtensions",
21 })
22 }
23}
24
25impl Obfuscate for KeyPackageSecretEncapsulation {
26 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
27 f.write_str("<secret>")
28 }
29}
30
31impl Obfuscate for QueuedProposal {
32 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
33 self.proposal.obfuscate(f)
34 }
35}
36
37impl Obfuscate for Sender {
38 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
39 match self {
40 Sender::Member(leaf_node_index) => write!(f, "Member{leaf_node_index}"),
41 Sender::External(external_sender_index) => write!(f, "External{external_sender_index:?}"),
42 Sender::NewMemberProposal => write!(f, "NewMemberProposal"),
43 Sender::NewMemberCommit => write!(f, "NewMemberCommit"),
44 }
45 }
46}
47
48impl Obfuscate for Member {
49 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
50 f.write_str("Member { ")?;
51 write!(f, "index: {:?}", self.index)?;
52 f.write_str(", credential: ")?;
53 self.credential.obfuscate(f)?;
54 f.write_str(" }")
55 }
56}
57
58impl Obfuscate for Credential {
59 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
60 self.mls_credential().obfuscate(f)
61 }
62}
63
64impl Obfuscate for BasicCredential {
65 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
66 write!(
67 f,
68 "BasicCredential( {} )",
69 hex::encode(compute_hash(format!("{:?}", self).as_bytes())).as_str()
70 )
71 }
72}
73
74impl Obfuscate for Certificate {
75 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
76 f.write_str("Certificate( ")?;
77 self.identity.obfuscate(f)?;
78 f.write_str(")")
79 }
80}
81
82impl Obfuscate for MlsCredentialType {
83 fn obfuscate(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
84 match self {
85 MlsCredentialType::Basic(basic_credential) => basic_credential.obfuscate(f),
86 MlsCredentialType::X509(identity_cert) => identity_cert.obfuscate(f),
87 }
88 }
89}