zebra_chain/primitives/byte_array.rs
1//! Functions for modifying byte arrays.
2
3/// Increments `byte_array` by 1, interpreting it as a big-endian integer.
4/// If the big-endian integer overflowed, sets all the bytes to zero, and returns `true`.
5pub fn increment_big_endian(byte_array: &mut [u8]) -> bool {
6 // Increment the last byte in the array that is less than u8::MAX, and clear any bytes after it
7 // to increment the next value in big-endian (lexicographic) order.
8 let is_wrapped_overflow = byte_array.iter_mut().rev().all(|v| {
9 *v = v.wrapping_add(1);
10 v == &0
11 });
12
13 is_wrapped_overflow
14}