Manually implement Debug for onion message packets.
authorValentine Wallace <vwallace@protonmail.com>
Wed, 27 Mar 2024 15:06:33 +0000 (11:06 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Thu, 9 May 2024 19:29:44 +0000 (15:29 -0400)
Previously we derived Debug, but that caused a lot of unreadable encrypted
bytes to be printed.

lightning/src/onion_message/packet.rs

index 510f0ea025a0d615b0f54292d865602ac7e103a6..7483888d137132ec2b0bdd3719a461280c4aa6cb 100644 (file)
@@ -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<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
                self.version.write(w)?;