Skip to content

Commit 1b35661

Browse files
Move Padding into blinded_path module for use in blinded payments
1 parent fe5a076 commit 1b35661

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

lightning/src/blinded_path/utils.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey, Scalar};
1616
use bitcoin::secp256k1::ecdh::SharedSecret;
1717

1818
use super::BlindedPath;
19+
use crate::ln::msgs::DecodeError;
1920
use crate::ln::onion_utils;
2021
use crate::onion_message::Destination;
2122
use crate::util::chacha20poly1305rfc::ChaChaPolyWriteAdapter;
22-
use crate::util::ser::{VecWriter, Writeable};
23+
use crate::util::ser::{Readable, VecWriter, Writeable};
2324

25+
use crate::io;
2426
use crate::prelude::*;
2527

2628
// 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;
107109
writer.0
108110
}
109111

112+
/// Blinded path encrypted payloads may be padded to ensure they are equal length.
113+
///
114+
/// Reads padding to the end, ignoring what's read.
115+
pub(crate) struct Padding {}
116+
impl Readable for Padding {
117+
#[inline]
118+
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
119+
loop {
120+
let mut buf = [0; 8192];
121+
if reader.read(&mut buf[..])? == 0 { break; }
122+
}
123+
Ok(Self {})
124+
}
125+
}

lightning/src/onion_message/packet.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
1414

1515
use crate::blinded_path::BlindedPath;
1616
use crate::blinded_path::message::{ForwardTlvs, ReceiveTlvs};
17+
use crate::blinded_path::utils::Padding;
1718
use crate::ln::msgs::DecodeError;
1819
use crate::ln::onion_utils;
1920
use super::messenger::CustomOnionMessageHandler;
@@ -306,16 +307,3 @@ impl Readable for ControlTlvs {
306307
Ok(payload_fmt)
307308
}
308309
}
309-
310-
/// Reads padding to the end, ignoring what's read.
311-
pub(crate) struct Padding {}
312-
impl Readable for Padding {
313-
#[inline]
314-
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
315-
loop {
316-
let mut buf = [0; 8192];
317-
if reader.read(&mut buf[..])? == 0 { break; }
318-
}
319-
Ok(Self {})
320-
}
321-
}

0 commit comments

Comments
 (0)