Skip to content

Commit 1feddae

Browse files
committed
Support WithoutLength for UntrustedString
1 parent d78dd48 commit 1feddae

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lightning/src/util/ser.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::ln::msgs::PartialSignatureWithNonce;
4343
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
4444

4545
use crate::util::byte_utils::{be48_to_array, slice_to_be48};
46+
use crate::util::string::UntrustedString;
4647

4748
/// serialization buffer size
4849
pub const MAX_BUF_SIZE: usize = 64 * 1024;
@@ -629,6 +630,21 @@ impl<'a> From<&'a String> for WithoutLength<&'a String> {
629630
fn from(s: &'a String) -> Self { Self(s) }
630631
}
631632

633+
634+
impl Writeable for WithoutLength<&UntrustedString> {
635+
#[inline]
636+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
637+
WithoutLength(&self.0.0).write(w)
638+
}
639+
}
640+
impl Readable for WithoutLength<UntrustedString> {
641+
#[inline]
642+
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
643+
let s: WithoutLength<String> = Readable::read(r)?;
644+
Ok(Self(UntrustedString(s.0)))
645+
}
646+
}
647+
632648
impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec<T>> {
633649
#[inline]
634650
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {

0 commit comments

Comments
 (0)