From: Jeffrey Czyz Date: Mon, 5 Jun 2023 20:55:13 +0000 (-0500) Subject: Support WithoutLength for UntrustedString X-Git-Tag: v0.0.116-alpha1~11^2~14 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1feddaeafd343c50f29fd79a33a00bc7282b802a;p=rust-lightning Support WithoutLength for UntrustedString --- 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> {