@@ -1670,7 +1670,7 @@ mod fuzzy_internal_msgs {
1670
1670
use crate :: prelude:: * ;
1671
1671
use crate :: ln:: { PaymentPreimage , PaymentSecret } ;
1672
1672
use crate :: ln:: features:: BlindedHopFeatures ;
1673
- use crate :: ln:: msgs:: OnionPacket ;
1673
+ use crate :: ln:: msgs:: VariableLengthOnionPacket ;
1674
1674
1675
1675
// These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize
1676
1676
// them from untrusted input):
@@ -1728,7 +1728,7 @@ mod fuzzy_internal_msgs {
1728
1728
custom_tlvs : Vec < ( u64 , Vec < u8 > ) > ,
1729
1729
amt_msat : u64 ,
1730
1730
outgoing_cltv_value : u32 ,
1731
- trampoline_packet : Option < OnionPacket >
1731
+ trampoline_packet : Option < VariableLengthOnionPacket >
1732
1732
} ,
1733
1733
BlindedForward {
1734
1734
encrypted_tlvs : Vec < u8 > ,
@@ -1789,6 +1789,29 @@ impl fmt::Debug for OnionPacket {
1789
1789
}
1790
1790
}
1791
1791
1792
+ /// BOLT 4 onion packet including hop data for the next peer.
1793
+ #[ derive( Clone , Hash , PartialEq , Eq ) ]
1794
+ pub struct VariableLengthOnionPacket {
1795
+ /// BOLT 4 version number.
1796
+ pub version : u8 ,
1797
+ /// In order to ensure we always return an error on onion decode in compliance with [BOLT
1798
+ /// #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
1799
+ /// deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
1800
+ /// public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
1801
+ /// like.
1802
+ pub public_key : Result < PublicKey , secp256k1:: Error > ,
1803
+ /// Variable number of bytes encrypted payload for the next hop; 650 by default for Trampoline
1804
+ pub ( crate ) hop_data : Vec < u8 > ,
1805
+ /// HMAC to verify the integrity of hop_data.
1806
+ pub hmac : [ u8 ; 32 ] ,
1807
+ }
1808
+
1809
+ impl fmt:: Debug for VariableLengthOnionPacket {
1810
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1811
+ f. write_fmt ( format_args ! ( "VariableLengthOnionPacket version {} with hmac {:?}" , self . version, & self . hmac[ ..] ) )
1812
+ }
1813
+ }
1814
+
1792
1815
#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
1793
1816
pub ( crate ) struct OnionErrorPacket {
1794
1817
// This really should be a constant size slice, but the spec lets these things be up to 128KB?
@@ -2217,6 +2240,22 @@ impl Readable for OnionPacket {
2217
2240
}
2218
2241
}
2219
2242
2243
+ // This will be written as the value of a TLV, so when reading, the length of the hop data will be
2244
+ // inferred from a ReadableArg containing the total length. The standard hop data for Trampoline
2245
+ // onions will prospectively be 650 bytes.
2246
+ impl Writeable for VariableLengthOnionPacket {
2247
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
2248
+ self . version . write ( w) ?;
2249
+ match self . public_key {
2250
+ Ok ( pubkey) => pubkey. write ( w) ?,
2251
+ Err ( _) => [ 0u8 ; 33 ] . write ( w) ?,
2252
+ }
2253
+ & self . hop_data . write ( w) ?;
2254
+ & self . hmac . write ( w) ?;
2255
+ Ok ( ( ) )
2256
+ }
2257
+ }
2258
+
2220
2259
impl_writeable_msg ! ( UpdateAddHTLC , {
2221
2260
channel_id,
2222
2261
htlc_id,
0 commit comments