From: Valentine Wallace Date: Thu, 30 Mar 2023 03:55:59 +0000 (-0400) Subject: Move Padding into blinded_path module for use in blinded payments X-Git-Tag: v0.0.117-alpha1~45^2~9 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1b356619b3b178ef5a4f392056ed2fd5b7de2541;p=rust-lightning Move Padding into blinded_path module for use in blinded payments --- diff --git a/lightning/src/blinded_path/utils.rs b/lightning/src/blinded_path/utils.rs index c1ecff4b4..a188274a5 100644 --- a/lightning/src/blinded_path/utils.rs +++ b/lightning/src/blinded_path/utils.rs @@ -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(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(reader: &mut R) -> Result { + loop { + let mut buf = [0; 8192]; + if reader.read(&mut buf[..])? == 0 { break; } + } + Ok(Self {}) + } +} diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index 9eb48a310..8b677e7bb 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -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(reader: &mut R) -> Result { - loop { - let mut buf = [0; 8192]; - if reader.read(&mut buf[..])? == 0 { break; } - } - Ok(Self {}) - } -}