I'm trying to write a test and running into a problem. Here's the code:
fn test_mix3parts_1(plain:&[u8],cipher:&[u8]) {
let mut text_copy=plain.clone();
let len=plain.len();
let third=len/3;
let rprime=find_max_order(third as u64) as usize;
mix3parts(&mut text_copy,len,rprime);
assert_eq!(text_copy,cipher);
mix3parts(&mut text_copy,len,rprime);
assert_eq!(text_copy,plain);
}
#[test]
fn test_mix3parts() {
test_mix3parts_1(&[0x00,0x0d,0x1a,0x27,0x34,0x41,0x4e,0x5b,0x68,0x75,0x82,0x8f,0x9c,0xa9,0xb6,0xc3],
&[0xd9,0x74,0xd1,0xbc,0x29,0x5a,0x42,0x2b,0x51,0x87,0xa0,0xcd,0x0a,0x16,0x41,0xc3]);
}
It's in mix3.rs in GitHub - phma/Kaftor.jl: Keyed affine transform · GitHub, and I got the test vector by running the corresponding Julia code. When I try to compile it, I get
error[E0596]: cannot borrow data in a `&` reference as mutable
--> src/mix3.rs:161:15
|
161 | mix3parts(&mut text_copy,len,rprime);
| ^^^^^^^^^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow data in a `&` reference as mutable
--> src/mix3.rs:163:15
|
163 | mix3parts(&mut text_copy,len,rprime);
| ^^^^^^^^^^^^^^ cannot borrow as mutable
along with warnings about unused code because I haven't finished writing it. text_copy was created with let mut, so why can't it be borrowed as mutable?