Converts the given `checksum` into a vector of digits. ## Output format - sequence of `n_digits` many digits - each digit a `u32` value in range `0..base` - checksum converted into BE bytes, in turn converted into digits
(mut checksum: u32, base: u32, n_digits: u32)
| 19 | /// - each digit a `u32` value in range `0..base` |
| 20 | /// - checksum converted into BE bytes, in turn converted into digits |
| 21 | pub(super) fn checksum_to_digits(mut checksum: u32, base: u32, n_digits: u32) -> Vec<u32> { |
| 22 | debug_assert!((16..=256).contains(&base)); |
| 23 | debug_assert!( |
| 24 | base.checked_pow(n_digits) |
| 25 | .map(|upper_limit| checksum < upper_limit) |
| 26 | .unwrap_or(true), |
| 27 | "Checksum is too large to fit into the given number of digits" |
| 28 | ); |
| 29 | |
| 30 | let mut digits = vec![0; n_digits as usize]; // cast safety: 32-bit machine or higher |
| 31 | |
| 32 | for digit in digits.iter_mut().rev() { |
| 33 | *digit = checksum % base; |
| 34 | checksum = (checksum - *digit) / base; |
| 35 | } |
| 36 | |
| 37 | digits |
| 38 | } |
| 39 | |
| 40 | /// Converts the given `message` into a vector of digits. |
| 41 | /// |
no outgoing calls
no test coverage detected