X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fonion_utils.rs;h=6ca8811e444aa5b3fcca7546e47a486e07f601f7;hb=refs%2Fheads%2F2019-07-new-warnings;hp=8783aa0bde0e107708122c62fb06f2dd9102bbf4;hpb=f0bcb7dba0360f04afacfff63ec2598d39bddc5f;p=rust-lightning diff --git a/src/ln/onion_utils.rs b/src/ln/onion_utils.rs index 8783aa0b..6ca8811e 100644 --- a/src/ln/onion_utils.rs +++ b/src/ln/onion_utils.rs @@ -1,7 +1,7 @@ use ln::channelmanager::{PaymentHash, HTLCSource}; use ln::msgs; use ln::router::{Route,RouteHop}; -use util::{byte_utils, internal_traits}; +use util::byte_utils; use util::chacha20::ChaCha20; use util::errors::{self, APIError}; use util::ser::{Readable, Writeable}; @@ -17,7 +17,6 @@ use secp256k1::Secp256k1; use secp256k1::ecdh::SharedSecret; use secp256k1; -use std::ptr; use std::io::Cursor; use std::sync::Arc; @@ -114,16 +113,14 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) -> let mut cur_cltv = starting_htlc_offset; let mut last_short_channel_id = 0; let mut res: Vec = Vec::with_capacity(route.hops.len()); - internal_traits::test_no_dealloc::(None); - unsafe { res.set_len(route.hops.len()); } - for (idx, hop) in route.hops.iter().enumerate().rev() { + for hop in route.hops.iter().rev() { // First hop gets special values so that it can check, on receipt, that everything is // exactly as it should be (and the next hop isn't trying to probe to find out if we're // the intended recipient). let value_msat = if cur_value_msat == 0 { hop.fee_msat } else { cur_value_msat }; let cltv = if cur_cltv == starting_htlc_offset { hop.cltv_expiry_delta + starting_htlc_offset } else { cur_cltv }; - res[idx] = msgs::OnionHopData { + res.insert(0, msgs::OnionHopData { realm: 0, data: msgs::OnionRealm0HopData { short_channel_id: last_short_channel_id, @@ -131,7 +128,7 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) -> outgoing_cltv_value: cltv, }, hmac: [0; 32], - }; + }); cur_value_msat += hop.fee_msat; if cur_value_msat >= 21000000 * 100000000 * 1000 { return Err(APIError::RouteError{err: "Channel fees overflowed?!"}); @@ -147,8 +144,8 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) -> #[inline] fn shift_arr_right(arr: &mut [u8; 20*65]) { - unsafe { - ptr::copy(arr[0..].as_ptr(), arr[65..].as_mut_ptr(), 19*65); + for i in (65..20*65).rev() { + arr[i] = arr[i-65]; } for i in 0..65 { arr[i] = 0;