Support WithoutLength for UntrustedString
authorJeffrey Czyz <jkczyz@gmail.com>
Mon, 5 Jun 2023 20:55:13 +0000 (15:55 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 13 Jun 2023 18:07:41 +0000 (13:07 -0500)
lightning/src/util/ser.rs

index cbdb5485e7bd984312c5a139e220835769f8f73b..fb0d0ad8e44e9eb40d203c50b4cf2efaa8af88a3 100644 (file)
@@ -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<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+               WithoutLength(&self.0.0).write(w)
+       }
+}
+impl Readable for WithoutLength<UntrustedString> {
+       #[inline]
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               let s: WithoutLength<String> = Readable::read(r)?;
+               Ok(Self(UntrustedString(s.0)))
+       }
+}
+
 impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec<T>> {
        #[inline]
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {