From 6613f1f0d2b8c8967e8c98efda136cdbe837ae9a Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 27 Mar 2024 11:06:33 -0400 Subject: [PATCH] Manually implement Debug for onion message packets. Previously we derived Debug, but that caused a lot of unreadable encrypted bytes to be printed. --- lightning/src/onion_message/packet.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index 510f0ea02..7483888d1 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -24,6 +24,7 @@ use crate::util::logger::Logger; use crate::util::ser::{BigSize, FixedLengthReader, LengthRead, LengthReadable, LengthReadableArgs, Readable, ReadableArgs, Writeable, Writer}; use core::cmp; +use core::fmt; use crate::io::{self, Read}; use crate::prelude::*; @@ -33,7 +34,7 @@ pub(super) const SMALL_PACKET_HOP_DATA_LEN: usize = 1300; pub(super) const BIG_PACKET_HOP_DATA_LEN: usize = 32768; /// Packet of hop data for next peer -#[derive(Clone, Debug, Hash, PartialEq, Eq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct Packet { /// Bolt 04 version number pub version: u8, @@ -62,6 +63,12 @@ impl onion_utils::Packet for Packet { } } +impl fmt::Debug for Packet { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_fmt(format_args!("Onion message packet version {} with hmac {:?}", self.version, &self.hmac[..])) + } +} + impl Writeable for Packet { fn write(&self, w: &mut W) -> Result<(), io::Error> { self.version.write(w)?; -- 2.39.5