Newer
Older
use arrayvec::ArrayVec;
const WHITE: [u8; 16] = [
0xe9, 0xcf, 0x67, 0x20, 0x19, 0x1a, 0x07, 0xdc, 0xc0, 0x72, 0x79, 0x97, 0x51, 0xf7, 0xdd, 0x93,
];
pub(crate) fn whiten<const N: usize>(data: &mut ArrayVec<u8, N>) {
for (i, d) in data.iter_mut().enumerate() {
*d ^= WHITE[i % 15];
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn basic() {
let mut data: ArrayVec<u8, 512> =
ArrayVec::try_from(&b"Hello world! The quick brown fox jumped over the lazy dog"[..])
.unwrap();
let orig = data.clone();
whiten(&mut data);
assert_ne!(orig, data);
whiten(&mut data);
assert_eq!(orig, data);
}
}