@@ -931,15 +931,11 @@ pub(crate) struct DecodedOnionFailure {
931
931
pub ( crate ) onion_error_data : Option < Vec < u8 > > ,
932
932
}
933
933
934
- /// Note that we always decrypt `packet` in-place here even if the deserialization into
935
- /// [`msgs::DecodedOnionErrorPacket`] ultimately fails.
936
- fn decrypt_onion_error_packet (
937
- packet : & mut Vec < u8 > , shared_secret : SharedSecret ,
938
- ) -> Result < msgs:: DecodedOnionErrorPacket , msgs:: DecodeError > {
934
+ /// Decrypt the error packet in-place.
935
+ fn decrypt_onion_error_packet ( packet : & mut Vec < u8 > , shared_secret : SharedSecret ) {
939
936
let ammag = gen_ammag_from_shared_secret ( shared_secret. as_ref ( ) ) ;
940
937
let mut chacha = ChaCha20 :: new ( & ammag, & [ 0u8 ; 8 ] ) ;
941
938
chacha. process_in_place ( packet) ;
942
- msgs:: DecodedOnionErrorPacket :: read ( & mut Cursor :: new ( packet) )
943
939
}
944
940
945
941
/// Process failure we got back from upstream on a payment we sent (implying htlc_source is an
@@ -1021,9 +1017,11 @@ where
1021
1017
{
1022
1018
// Actually parse the onion error data in tests so we can check that blinded hops fail
1023
1019
// back correctly.
1024
- let err_packet =
1025
- decrypt_onion_error_packet ( & mut encrypted_packet, shared_secret)
1026
- . unwrap ( ) ;
1020
+ decrypt_onion_error_packet ( & mut encrypted_packet, shared_secret) ;
1021
+ let err_packet = msgs:: DecodedOnionErrorPacket :: read ( & mut Cursor :: new (
1022
+ & encrypted_packet,
1023
+ ) )
1024
+ . unwrap ( ) ;
1027
1025
error_code_ret = Some ( u16:: from_be_bytes (
1028
1026
err_packet. failuremsg . get ( 0 ..2 ) . unwrap ( ) . try_into ( ) . unwrap ( ) ,
1029
1027
) ) ;
@@ -1044,10 +1042,12 @@ where
1044
1042
let amt_to_forward = htlc_msat - route_hop. fee_msat ;
1045
1043
htlc_msat = amt_to_forward;
1046
1044
1047
- let err_packet = match decrypt_onion_error_packet ( & mut encrypted_packet, shared_secret) {
1048
- Ok ( p) => p,
1049
- Err ( _) => return ,
1050
- } ;
1045
+ decrypt_onion_error_packet ( & mut encrypted_packet, shared_secret) ;
1046
+ let err_packet =
1047
+ match msgs:: DecodedOnionErrorPacket :: read ( & mut Cursor :: new ( & encrypted_packet) ) {
1048
+ Ok ( p) => p,
1049
+ Err ( _) => return ,
1050
+ } ;
1051
1051
let um = gen_um_from_shared_secret ( shared_secret. as_ref ( ) ) ;
1052
1052
let mut hmac = HmacEngine :: < Sha256 > :: new ( & um) ;
1053
1053
hmac. input ( & err_packet. encode ( ) [ 32 ..] ) ;
0 commit comments