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