Skip to content

Commit

Permalink
belt-block: mark to_u32 function as private (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Jan 24, 2024
1 parent 801e36b commit bf57b43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion belt-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub struct InvalidLengthError;
/// # Panics
/// If length of `src` is not equal to `4 * N`.
#[inline(always)]
pub fn to_u32<const N: usize>(src: &[u8]) -> [u32; N] {
fn to_u32<const N: usize>(src: &[u8]) -> [u32; N] {
assert_eq!(src.len(), 4 * N);
let mut res = [0u32; N];
res.iter_mut()
Expand Down
11 changes: 10 additions & 1 deletion belt-block/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Example vectors from STB 34.101.31 (2020):
//! http://apmi.bsu.by/assets/files/std/belt-spec371.pdf
use belt_block::{belt_block_raw, belt_wblock_dec, belt_wblock_enc, to_u32};
use belt_block::{belt_block_raw, belt_wblock_dec, belt_wblock_enc};
#[cfg(feature = "cipher")]
use belt_block::{
cipher::{BlockCipherDecrypt, BlockCipherEncrypt, KeyInit},
Expand Down Expand Up @@ -124,3 +124,12 @@ fn belt_wblock() {
assert_eq!(t, x[..i]);
}
}

fn to_u32<const N: usize>(src: &[u8]) -> [u32; N] {
assert_eq!(src.len(), 4 * N);
let mut res = [0u32; N];
res.iter_mut()
.zip(src.chunks_exact(4))
.for_each(|(dst, src)| *dst = u32::from_le_bytes(src.try_into().unwrap()));
res
}

0 comments on commit bf57b43

Please sign in to comment.