@@ -55,7 +55,7 @@ use crate::io_extras::read_to_end;
5555use crate :: events:: { EventsProvider , MessageSendEventsProvider } ;
5656use crate :: crypto:: streams:: ChaChaPolyReadAdapter ;
5757use crate :: util:: logger;
58- use crate :: util:: ser:: { LengthReadable , LengthReadableArgs , Readable , ReadableArgs , Writeable , Writer , WithoutLength , FixedLengthReader , HighZeroBytesDroppedBigSize , Hostname , TransactionU16LenLimited , BigSize } ;
58+ use crate :: util:: ser:: { BigSize , FixedLengthReader , HighZeroBytesDroppedBigSize , Hostname , LengthRead , LengthReadable , LengthReadableArgs , Readable , ReadableArgs , TransactionU16LenLimited , WithoutLength , Writeable , Writer } ;
5959use crate :: util:: base32;
6060
6161use crate :: routing:: gossip:: { NodeAlias , NodeId } ;
@@ -1856,6 +1856,26 @@ impl Writeable for TrampolineOnionPacket {
18561856 }
18571857}
18581858
1859+ impl LengthReadable for TrampolineOnionPacket {
1860+ fn read < R : LengthRead > ( r : & mut R ) -> Result < Self , DecodeError > {
1861+ let version = Readable :: read ( r) ?;
1862+ let public_key = Readable :: read ( r) ?;
1863+
1864+ let hop_data_len = r. total_bytes ( ) . saturating_sub ( 66 ) ; // 1 (version) + 33 (pubkey) + 32 (HMAC) = 66
1865+ let mut rd = FixedLengthReader :: new ( r, hop_data_len) ;
1866+ let hop_data = WithoutLength :: < Vec < u8 > > :: read ( & mut rd) ?. 0 ;
1867+
1868+ let hmac = Readable :: read ( r) ?;
1869+
1870+ Ok ( TrampolineOnionPacket {
1871+ version,
1872+ public_key,
1873+ hop_data,
1874+ hmac,
1875+ } )
1876+ }
1877+ }
1878+
18591879impl Debug for TrampolineOnionPacket {
18601880 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
18611881 f. write_fmt ( format_args ! ( "TrampolineOnionPacket version {} with hmac {:?}" , self . version, & self . hmac[ ..] ) )
0 commit comments