Move Padding into blinded_path module for use in blinded payments
authorValentine Wallace <vwallace@protonmail.com>
Thu, 30 Mar 2023 03:55:59 +0000 (23:55 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 22 Aug 2023 17:26:12 +0000 (13:26 -0400)
lightning/src/blinded_path/utils.rs
lightning/src/onion_message/packet.rs

index c1ecff4b4af19155211fba89920b3852e8b22be1..a188274a5d2fccd0b2eeee67c77c16530c53e1aa 100644 (file)
@@ -16,11 +16,13 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey, Scalar};
 use bitcoin::secp256k1::ecdh::SharedSecret;
 
 use super::BlindedPath;
+use crate::ln::msgs::DecodeError;
 use crate::ln::onion_utils;
 use crate::onion_message::Destination;
 use crate::util::chacha20poly1305rfc::ChaChaPolyWriteAdapter;
-use crate::util::ser::{VecWriter, Writeable};
+use crate::util::ser::{Readable, VecWriter, Writeable};
 
+use crate::io;
 use crate::prelude::*;
 
 // TODO: DRY with onion_utils::construct_onion_keys_callback
@@ -107,3 +109,17 @@ pub(super) fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_ss: [u8;
        writer.0
 }
 
+/// Blinded path encrypted payloads may be padded to ensure they are equal length.
+///
+/// Reads padding to the end, ignoring what's read.
+pub(crate) struct Padding {}
+impl Readable for Padding {
+       #[inline]
+       fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+               loop {
+                       let mut buf = [0; 8192];
+                       if reader.read(&mut buf[..])? == 0 { break; }
+               }
+               Ok(Self {})
+       }
+}
index 9eb48a31086b24762c5924dd0d76635d9b5a7df9..8b677e7bb611ea307067493bc2252685e7632636 100644 (file)
@@ -14,6 +14,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
 
 use crate::blinded_path::BlindedPath;
 use crate::blinded_path::message::{ForwardTlvs, ReceiveTlvs};
+use crate::blinded_path::utils::Padding;
 use crate::ln::msgs::DecodeError;
 use crate::ln::onion_utils;
 use super::messenger::CustomOnionMessageHandler;
@@ -306,16 +307,3 @@ impl Readable for ControlTlvs {
                Ok(payload_fmt)
        }
 }
-
-/// Reads padding to the end, ignoring what's read.
-pub(crate) struct Padding {}
-impl Readable for Padding {
-       #[inline]
-       fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
-               loop {
-                       let mut buf = [0; 8192];
-                       if reader.read(&mut buf[..])? == 0 { break; }
-               }
-               Ok(Self {})
-       }
-}