Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log verbosity and sanitization #335

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading