Skip to content

Commit

Permalink
Log verbosity and sanitization (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos authored Oct 21, 2024
1 parent 158757c commit 54c39ed
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/content.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use libsignal_protocol::ProtocolAddress;
use std::fmt;
use uuid::Uuid;

pub use crate::{
Expand Down Expand Up @@ -31,6 +32,21 @@ pub struct Metadata {
pub server_guid: Option<Uuid>,
}

impl fmt::Display for Metadata {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Metadata {{ sender: {}, guid: {} }}",
self.sender.to_service_id(),
// XXX: should this still be optional?
self.server_guid
.map(|u| u.to_string())
.as_deref()
.unwrap_or("None"),
)
}
}

impl Metadata {
pub(crate) fn protocol_address(&self) -> ProtocolAddress {
self.sender.to_protocol_address(self.sender_device)
Expand Down Expand Up @@ -88,6 +104,46 @@ impl Content {
}
}

impl fmt::Display for ContentBody {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NullMessage(_) => write!(f, "NullMessage"),
Self::DataMessage(m) => {
match (&m.body, &m.reaction, m.attachments.len()) {
(Some(body), _, 0) => {
write!(f, "DataMessage({}", body)
},
(Some(body), _, n) => {
write!(f, "DataMessage({}, attachments: {n})", body)
},
(None, Some(emoji), _) => {
write!(
f,
"DataMessage(reaction: {})",
emoji.emoji.as_deref().unwrap_or("None")
)
},
(None, _, n) if n > 0 => {
write!(f, "DataMessage(attachments: {n})")
},
_ => {
write!(f, "{self:?}")
},
}
},
Self::SynchronizeMessage(_) => write!(f, "SynchronizeMessage"),
Self::CallMessage(_) => write!(f, "CallMessage"),
Self::ReceiptMessage(_) => write!(f, "ReceiptMessage"),
Self::TypingMessage(_) => write!(f, "TypingMessage"),
// Self::SenderKeyDistributionMessage(_) => write!(f, "SenderKeyDistributionMessage"),
// Self::DecryptionErrorMessage(_) => write!(f, "DecryptionErrorMessage"),
Self::StoryMessage(_) => write!(f, "StoryMessage"),
Self::PniSignatureMessage(_) => write!(f, "PniSignatureMessage"),
Self::EditMessage(_) => write!(f, "EditMessage"),
}
}
}

#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum ContentBody {
Expand Down
2 changes: 1 addition & 1 deletion src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl TryFrom<EnvelopeEntity> for Envelope {
}

impl Envelope {
#[tracing::instrument(skip(input, signaling_key), fields(input_size = input.len()))]
#[tracing::instrument(skip(input, signaling_key), fields(signaling_key_present = signaling_key.is_some(), input_size = input.len()))]
pub fn decrypt(
input: &[u8],
signaling_key: Option<&SignalingKey>,
Expand Down

0 comments on commit 54c39ed

Please sign in to comment.