@@ -589,31 +589,6 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
589589 } else { unreachable ! ( ) ; }
590590}
591591
592- /// An input used when decoding an onion packet.
593- pub ( crate ) trait DecodeInput {
594- type Arg ;
595- /// If Some, this is the input when checking the hmac of the onion packet.
596- fn payment_hash ( & self ) -> Option < & PaymentHash > ;
597- /// Read argument when decrypting our hop payload.
598- fn read_arg ( self ) -> Self :: Arg ;
599- }
600-
601- impl DecodeInput for PaymentHash {
602- type Arg = ( ) ;
603- fn payment_hash ( & self ) -> Option < & PaymentHash > {
604- Some ( self )
605- }
606- fn read_arg ( self ) -> Self :: Arg { ( ) }
607- }
608-
609- impl DecodeInput for SharedSecret {
610- type Arg = SharedSecret ;
611- fn payment_hash ( & self ) -> Option < & PaymentHash > {
612- None
613- }
614- fn read_arg ( self ) -> Self :: Arg { self }
615- }
616-
617592/// Allows `decode_next_hop` to return the next hop packet bytes for either payments or onion
618593/// message forwards.
619594pub ( crate ) trait NextPacketBytes : AsMut < [ u8 ] > {
@@ -664,7 +639,7 @@ pub(crate) enum OnionDecodeErr {
664639}
665640
666641pub ( crate ) fn decode_next_payment_hop ( shared_secret : [ u8 ; 32 ] , hop_data : & [ u8 ] , hmac_bytes : [ u8 ; 32 ] , payment_hash : PaymentHash ) -> Result < Hop , OnionDecodeErr > {
667- match decode_next_hop ( shared_secret, hop_data, hmac_bytes, payment_hash) {
642+ match decode_next_hop ( shared_secret, hop_data, hmac_bytes, Some ( payment_hash) , ( ) ) {
668643 Ok ( ( next_hop_data, None ) ) => Ok ( Hop :: Receive ( next_hop_data) ) ,
669644 Ok ( ( next_hop_data, Some ( ( next_hop_hmac, FixedSizeOnionPacket ( new_packet_bytes) ) ) ) ) => {
670645 Ok ( Hop :: Forward {
@@ -677,12 +652,16 @@ pub(crate) fn decode_next_payment_hop(shared_secret: [u8; 32], hop_data: &[u8],
677652 }
678653}
679654
680- pub ( crate ) fn decode_next_hop < D : DecodeInput , R : ReadableArgs < D :: Arg > , N : NextPacketBytes > ( shared_secret : [ u8 ; 32 ] , hop_data : & [ u8 ] , hmac_bytes : [ u8 ; 32 ] , decode_input : D ) -> Result < ( R , Option < ( [ u8 ; 32 ] , N ) > ) , OnionDecodeErr > {
655+ pub ( crate ) fn decode_next_untagged_hop < T , R : ReadableArgs < T > , N : NextPacketBytes > ( shared_secret : [ u8 ; 32 ] , hop_data : & [ u8 ] , hmac_bytes : [ u8 ; 32 ] , read_args : T ) -> Result < ( R , Option < ( [ u8 ; 32 ] , N ) > ) , OnionDecodeErr > {
656+ decode_next_hop ( shared_secret, hop_data, hmac_bytes, None , read_args)
657+ }
658+
659+ fn decode_next_hop < T , R : ReadableArgs < T > , N : NextPacketBytes > ( shared_secret : [ u8 ; 32 ] , hop_data : & [ u8 ] , hmac_bytes : [ u8 ; 32 ] , payment_hash : Option < PaymentHash > , read_args : T ) -> Result < ( R , Option < ( [ u8 ; 32 ] , N ) > ) , OnionDecodeErr > {
681660 let ( rho, mu) = gen_rho_mu_from_shared_secret ( & shared_secret) ;
682661 let mut hmac = HmacEngine :: < Sha256 > :: new ( & mu) ;
683662 hmac. input ( hop_data) ;
684- if let Some ( payment_hash ) = decode_input . payment_hash ( ) {
685- hmac. input ( & payment_hash . 0 [ ..] ) ;
663+ if let Some ( tag ) = payment_hash {
664+ hmac. input ( & tag . 0 [ ..] ) ;
686665 }
687666 if !fixed_time_eq ( & Hmac :: from_engine ( hmac) . into_inner ( ) , & hmac_bytes) {
688667 return Err ( OnionDecodeErr :: Malformed {
@@ -693,7 +672,7 @@ pub(crate) fn decode_next_hop<D: DecodeInput, R: ReadableArgs<D::Arg>, N: NextPa
693672
694673 let mut chacha = ChaCha20 :: new ( & rho, & [ 0u8 ; 8 ] ) ;
695674 let mut chacha_stream = ChaChaReader { chacha : & mut chacha, read : Cursor :: new ( & hop_data[ ..] ) } ;
696- match R :: read ( & mut chacha_stream, decode_input . read_arg ( ) ) {
675+ match R :: read ( & mut chacha_stream, read_args ) {
697676 Err ( err) => {
698677 let error_code = match err {
699678 msgs:: DecodeError :: UnknownVersion => 0x4000 | 1 , // unknown realm byte
0 commit comments