From 1feddaeafd343c50f29fd79a33a00bc7282b802a Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 5 Jun 2023 15:55:13 -0500 Subject: [PATCH] Support WithoutLength for UntrustedString --- lightning/src/util/ser.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index cbdb5485e..fb0d0ad8e 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -43,6 +43,7 @@ use crate::ln::msgs::PartialSignatureWithNonce; use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret}; use crate::util::byte_utils::{be48_to_array, slice_to_be48}; +use crate::util::string::UntrustedString; /// serialization buffer size pub const MAX_BUF_SIZE: usize = 64 * 1024; @@ -629,6 +630,21 @@ impl<'a> From<&'a String> for WithoutLength<&'a String> { fn from(s: &'a String) -> Self { Self(s) } } + +impl Writeable for WithoutLength<&UntrustedString> { + #[inline] + fn write(&self, w: &mut W) -> Result<(), io::Error> { + WithoutLength(&self.0.0).write(w) + } +} +impl Readable for WithoutLength { + #[inline] + fn read(r: &mut R) -> Result { + let s: WithoutLength = Readable::read(r)?; + Ok(Self(UntrustedString(s.0))) + } +} + impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec> { #[inline] fn write(&self, writer: &mut W) -> Result<(), io::Error> { -- 2.39.5