Skip to content

Commit 90dfbbc

Browse files
committed
Replace x.as_mut_ref() by &mut
1 parent a8b7202 commit 90dfbbc

18 files changed

+84
-84
lines changed

src/bcrypt_pbkdf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ pub fn bcrypt_pbkdf(password: &[u8], salt: &[u8], rounds: u32, output: &mut [u8]
4747

4848
let mut h = Sha512::new();
4949
h.input(password);
50-
h.result(hpass.as_mut_slice());
50+
h.result(&mut hpass);
5151

5252
for block in (1..(nblocks+1)) {
5353
let mut count = [0u8; 4];
5454
let mut hsalt = [0u8; 64];
5555
let mut out = [0u8; 32];
56-
write_u32_be(count.as_mut_slice(), block as u32);
56+
write_u32_be(&mut count, block as u32);
5757

5858
h.reset();
5959
h.input(salt);
@@ -276,7 +276,7 @@ mod bench {
276276
let mut out = [0u8; 32];
277277

278278
b.iter(|| {
279-
bcrypt_pbkdf(&pass, &salt, 5, out.as_mut_slice());
279+
bcrypt_pbkdf(&pass, &salt, 5, &mut out);
280280
});
281281
}
282282
}

src/blake2b.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl Mac for Blake2b {
383383
*/
384384
fn result(&mut self) -> MacResult {
385385
let mut mac: Vec<u8> = repeat(0).take(self.digest_length as usize).collect();
386-
self.raw_result(mac.as_mut_slice());
386+
self.raw_result(&mut mac);
387387
MacResult::new_from_owned(mac)
388388
}
389389

src/blockmodes.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ impl <P: BlockProcessor, X: PaddingProcessor> BlockEngine<P, X> {
200200
output.rewind(self.out_hist.len());
201201
let last_out = output.take_next(self.out_hist.len());
202202
update_history(
203-
self.in_hist.as_mut_slice(),
204-
self.out_hist.as_mut_slice(),
203+
&mut self.in_hist,
204+
&mut self.out_hist,
205205
last_in,
206206
last_out);
207207
}
@@ -233,8 +233,8 @@ impl <P: BlockProcessor, X: PaddingProcessor> BlockEngine<P, X> {
233233
next_in,
234234
next_out);
235235
update_history(
236-
me.in_hist.as_mut_slice(),
237-
me.out_hist.as_mut_slice(),
236+
&mut me.in_hist,
237+
&mut me.out_hist,
238238
next_in,
239239
next_out);
240240
}
@@ -412,8 +412,8 @@ impl <P: BlockProcessor, X: PaddingProcessor> BlockEngine<P, X> {
412412
}
413413
fn reset_with_history(&mut self, in_hist: &[u8], out_hist: &[u8]) {
414414
self.reset();
415-
slice::bytes::copy_memory(self.in_hist.as_mut_slice(), in_hist);
416-
slice::bytes::copy_memory(self.out_hist.as_mut_slice(), out_hist);
415+
slice::bytes::copy_memory(&mut self.in_hist, in_hist);
416+
slice::bytes::copy_memory(&mut self.out_hist, out_hist);
417417
}
418418
}
419419

@@ -575,7 +575,7 @@ impl <T: BlockEncryptor> BlockProcessor for CbcEncryptorProcessor<T> {
575575
for ((&x, &y), o) in input.iter().zip(out_hist.iter()).zip(self.temp.iter_mut()) {
576576
*o = x ^ y;
577577
}
578-
self.algo.encrypt_block(&self.temp[..], output.as_mut_slice());
578+
self.algo.encrypt_block(&self.temp[..], output);
579579
}
580580
}
581581

@@ -620,7 +620,7 @@ struct CbcDecryptorProcessor<T> {
620620

621621
impl <T: BlockDecryptor> BlockProcessor for CbcDecryptorProcessor<T> {
622622
fn process_block(&mut self, in_hist: &[u8], _: &[u8], input: &[u8], output: &mut [u8]) {
623-
self.algo.decrypt_block(input, self.temp.as_mut_slice());
623+
self.algo.decrypt_block(input, &mut self.temp);
624624
for ((&x, &y), o) in self.temp.iter().zip(in_hist.iter()).zip(output.iter_mut()) {
625625
*o = x ^ y;
626626
}
@@ -690,7 +690,7 @@ impl <A: BlockEncryptor> CtrMode<A> {
690690
}
691691
}
692692
pub fn reset(&mut self, ctr: &[u8]) {
693-
slice::bytes::copy_memory(self.ctr.as_mut_slice(), ctr);
693+
slice::bytes::copy_memory(&mut self.ctr, ctr);
694694
self.bytes.reset();
695695
}
696696
fn process(&mut self, input: &[u8], output: &mut [u8]) {
@@ -701,7 +701,7 @@ impl <A: BlockEncryptor> CtrMode<A> {
701701
if self.bytes.is_empty() {
702702
let mut wb = self.bytes.borrow_write_buffer();
703703
self.algo.encrypt_block(&self.ctr[..], wb.take_remaining());
704-
add_ctr(self.ctr.as_mut_slice(), 1);
704+
add_ctr(&mut self.ctr, 1);
705705
}
706706
let count = cmp::min(self.bytes.remaining(), len - i);
707707
let bytes_it = self.bytes.take_next(count).iter();
@@ -754,15 +754,15 @@ impl <A: BlockEncryptorX8> CtrModeX8<A> {
754754
pub fn new(algo: A, ctr: &[u8]) -> CtrModeX8<A> {
755755
let block_size = algo.block_size();
756756
let mut ctr_x8: Vec<u8> = repeat(0).take(block_size * 8).collect();
757-
construct_ctr_x8(ctr, ctr_x8.as_mut_slice());
757+
construct_ctr_x8(ctr, &mut ctr_x8);
758758
CtrModeX8 {
759759
algo: algo,
760760
ctr_x8: ctr_x8,
761761
bytes: OwnedReadBuffer::new_with_len(repeat(0).take(block_size * 8).collect(), 0)
762762
}
763763
}
764764
pub fn reset(&mut self, ctr: &[u8]) {
765-
construct_ctr_x8(ctr, self.ctr_x8.as_mut_slice());
765+
construct_ctr_x8(ctr, &mut self.ctr_x8);
766766
self.bytes.reset();
767767
}
768768
fn process(&mut self, input: &[u8], output: &mut [u8]) {
@@ -774,7 +774,7 @@ impl <A: BlockEncryptorX8> CtrModeX8<A> {
774774
if self.bytes.is_empty() {
775775
let mut wb = self.bytes.borrow_write_buffer();
776776
self.algo.encrypt_block_x8(&self.ctr_x8[..], wb.take_remaining());
777-
for ctr_i in self.ctr_x8.as_mut_slice().chunks_mut(self.algo.block_size()) {
777+
for ctr_i in &mut self.ctr_x8.chunks_mut(self.algo.block_size()) {
778778
add_ctr(ctr_i, 8);
779779
}
780780
}
@@ -986,7 +986,7 @@ mod test {
986986
let mut cipher_out: Vec<u8> = repeat(0).take(test.get_cipher().len()).collect();
987987
{
988988
let mut buff_in = RefReadBuffer::new(test.get_plain());
989-
let mut buff_out = RefWriteBuffer::new(cipher_out.as_mut_slice());
989+
let mut buff_out = RefWriteBuffer::new(&mut cipher_out);
990990
match enc.encrypt(&mut buff_in, &mut buff_out, true) {
991991
Ok(BufferUnderflow) => {}
992992
Ok(BufferOverflow) => panic!("Encryption not completed"),
@@ -998,7 +998,7 @@ mod test {
998998
let mut plain_out: Vec<u8> = repeat(0).take(test.get_plain().len()).collect();
999999
{
10001000
let mut buff_in = RefReadBuffer::new(test.get_cipher());
1001-
let mut buff_out = RefWriteBuffer::new(plain_out.as_mut_slice());
1001+
let mut buff_out = RefWriteBuffer::new(&mut plain_out);
10021002
match dec.decrypt(&mut buff_in, &mut buff_out, true) {
10031003
Ok(BufferUnderflow) => {}
10041004
Ok(BufferOverflow) => panic!("Decryption not completed"),
@@ -1127,7 +1127,7 @@ mod test {
11271127
let mut cipher_out: Vec<u8> = repeat(0).take(test.get_cipher().len()).collect();
11281128
run_inc(
11291129
test.get_plain(),
1130-
cipher_out.as_mut_slice(),
1130+
&mut cipher_out,
11311131
|in_buff: &mut RefReadBuffer, out_buff: &mut RefWriteBuffer, eof: bool| {
11321132
enc.encrypt(in_buff, out_buff, eof)
11331133
},
@@ -1139,7 +1139,7 @@ mod test {
11391139
let mut plain_out: Vec<u8> = repeat(0).take(test.get_plain().len()).collect();
11401140
run_inc(
11411141
test.get_cipher(),
1142-
plain_out.as_mut_slice(),
1142+
&mut plain_out,
11431143
|in_buff: &mut RefReadBuffer, out_buff: &mut RefWriteBuffer, eof: bool| {
11441144
dec.decrypt(in_buff, out_buff, eof)
11451145
},
@@ -1182,7 +1182,7 @@ mod test {
11821182
let mut cipher_out: Vec<u8> = repeat(0).take(test.get_cipher().len()).collect();
11831183
run_inc(
11841184
test.get_plain(),
1185-
cipher_out.as_mut_slice(),
1185+
&mut cipher_out,
11861186
|in_buff: &mut RefReadBuffer, out_buff: &mut RefWriteBuffer, eof: bool| {
11871187
enc.encrypt(in_buff, out_buff, eof)
11881188
},
@@ -1194,7 +1194,7 @@ mod test {
11941194
let mut plain_out: Vec<u8> = repeat(0).take(test.get_plain().len()).collect();
11951195
run_inc(
11961196
test.get_cipher(),
1197-
plain_out.as_mut_slice(),
1197+
&mut plain_out,
11981198
|in_buff: &mut RefReadBuffer, out_buff: &mut RefWriteBuffer, eof: bool| {
11991199
dec.decrypt(in_buff, out_buff, eof)
12001200
},

src/blowfish.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl BlockEncryptor for Blowfish {
314314
assert!(input.len() == 8);
315315
assert!(output.len() == 8);
316316
let mut block = [0u32, 0u32];
317-
read_u32v_be(block.as_mut_slice(), input);
317+
read_u32v_be(&mut block, input);
318318
let (l, r) = self.encrypt(block[0], block[1]);
319319
write_u32_be(&mut output[0..4], l);
320320
write_u32_be(&mut output[4..8], r);
@@ -330,7 +330,7 @@ impl BlockDecryptor for Blowfish {
330330
assert!(input.len() == 8);
331331
assert!(output.len() == 8);
332332
let mut block = [0u32, 0u32];
333-
read_u32v_be(block.as_mut_slice(), input);
333+
read_u32v_be(&mut block, input);
334334
let (l, r) = self.decrypt(block[0], block[1]);
335335
write_u32_be(&mut output[0..4], l);
336336
write_u32_be(&mut output[4..8], r);

src/curve25519.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,9 +2168,9 @@ mod tests {
21682168
fn from_to_bytes_preserves() {
21692169
for i in (0..50) {
21702170
let mut e: Vec<u8> = (0u32..32).map(|idx| (idx*(1289+i*761)) as u8).collect();
2171-
e.as_mut_slice()[0] &= 248;
2172-
e.as_mut_slice()[31] &= 127;
2173-
e.as_mut_slice()[31] |= 64;
2171+
e[0] &= 248;
2172+
e[31] &= 127;
2173+
e[31] |= 64;
21742174
let fe = Fe::from_bytes(e.as_ref());
21752175
let e_preserved = fe.to_bytes();
21762176
assert!(e == e_preserved.to_vec());
@@ -2205,9 +2205,9 @@ mod tests {
22052205

22062206
fn next(&mut self) -> Option<Fe> {
22072207
let mut e: Vec<u8> = (0..32).map(|idx| (idx*(1289+self.which*761)) as u8).collect();
2208-
e.as_mut_slice()[0] &= 248;
2209-
e.as_mut_slice()[31] &= 127;
2210-
e.as_mut_slice()[31] |= 64;
2208+
e[0] &= 248;
2209+
e[31] &= 127;
2210+
e[31] |= 64;
22112211
Some(Fe::from_bytes(e.as_ref()))
22122212
}
22132213
}

src/digest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub trait Digest {
7575
use serialize::hex::ToHex;
7676

7777
let mut buf: Vec<u8> = repeat(0).take((self.output_bits()+7)/8).collect();
78-
self.result(buf.as_mut_slice());
78+
self.result(&mut buf);
7979
buf[..].to_hex()
8080
}
8181
}

src/ed25519.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn keypair(seed: &[u8]) -> ([u8; 64], [u8; 32]) {
99
let mut hash_output: [u8; 64] = [0; 64];
1010
let mut hasher = Sha512::new();
1111
hasher.input(seed);
12-
hasher.result(hash_output.as_mut_slice());
12+
hasher.result(&mut hash_output);
1313
hash_output[0] &= 248;
1414
hash_output[31] &= 63;
1515
hash_output[31] |= 64;
@@ -34,7 +34,7 @@ pub fn signature(message: &[u8], secret_key: &[u8]) -> [u8; 64] {
3434
let mut hash_output: [u8; 64] = [0; 64];
3535
let mut hasher = Sha512::new();
3636
hasher.input(seed);
37-
hasher.result(hash_output.as_mut_slice());
37+
hasher.result(&mut hash_output);
3838
hash_output[0] &= 248;
3939
hash_output[31] &= 63;
4040
hash_output[31] |= 64;
@@ -46,7 +46,7 @@ pub fn signature(message: &[u8], secret_key: &[u8]) -> [u8; 64] {
4646
let mut hasher = Sha512::new();
4747
hasher.input(&az[32..64]);
4848
hasher.input(message);
49-
hasher.result(hash_output.as_mut_slice());
49+
hasher.result(&mut hash_output);
5050
sc_reduce(&mut hash_output[0..64]);
5151
hash_output
5252
};
@@ -65,8 +65,8 @@ pub fn signature(message: &[u8], secret_key: &[u8]) -> [u8; 64] {
6565
hasher.input(signature.as_ref());
6666
hasher.input(message);
6767
let mut hram: [u8; 64] = [0; 64];
68-
hasher.result(hram.as_mut_slice());
69-
sc_reduce(hram.as_mut_slice());
68+
hasher.result(&mut hram);
69+
sc_reduce(&mut hram);
7070
sc_muladd(&mut signature[32..64], &hram[0..32], &az[0..32], &nonce[0..32]);
7171
}
7272

@@ -112,8 +112,8 @@ pub fn verify(message: &[u8], public_key: &[u8], signature: &[u8]) -> bool {
112112
hasher.input(public_key);
113113
hasher.input(message);
114114
let mut hash: [u8; 64] = [0; 64];
115-
hasher.result(hash.as_mut_slice());
116-
sc_reduce(hash.as_mut_slice());
115+
hasher.result(&mut hash);
116+
sc_reduce(&mut hash);
117117

118118
let r = GeP2::double_scalarmult_vartime(hash.as_ref(), a, &signature[32..64]);
119119
let rcheck = r.to_bytes();

src/fortuna.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl FortunaGenerator {
102102
let mut hasher = Sha256::new();
103103
hasher.input(&self.key[..]);
104104
hasher.input(s);
105-
hasher.result(self.key.as_mut_slice());
105+
hasher.result(&mut self.key);
106106
hasher = Sha256::new();
107107
hasher.input(&self.key[..]);
108108
hasher.result(&mut self.key[..]);
@@ -134,13 +134,13 @@ impl FortunaGenerator {
134134
self.generate_blocks(n, &mut out[..(n * AES_BLOCK_SIZE)]);
135135
if rem > 0 {
136136
let mut buf = [0; AES_BLOCK_SIZE];
137-
self.generate_blocks(1, buf.as_mut_slice());
137+
self.generate_blocks(1, &mut buf);
138138
copy_memory(&mut out[(n * AES_BLOCK_SIZE)..], &buf[..rem]);
139139
}
140140

141141
// Rekey
142142
let mut new_key = [0; KEY_LEN];
143-
self.generate_blocks(KEY_LEN / AES_BLOCK_SIZE, new_key.as_mut_slice());
143+
self.generate_blocks(KEY_LEN / AES_BLOCK_SIZE, &mut new_key);
144144
self.key = new_key;
145145
}
146146
}
@@ -244,7 +244,7 @@ impl Rng for Fortuna {
244244

245245
fn next_u32(&mut self) -> u32 {
246246
let mut ret = [0; 4];
247-
self.fill_bytes(ret.as_mut_slice());
247+
self.fill_bytes(&mut ret);
248248
read_u32_le(&ret[..])
249249
}
250250
}
@@ -357,11 +357,11 @@ mod tests {
357357
59, 228, 23, 215, 58, 107, 248, 248, 103, 57,
358358
127, 31, 241, 91, 230, 33, 0, 164, 77, 46];
359359
let mut f: Fortuna = SeedableRng::from_seed(&[1, 2, 3, 4][..]);
360-
f.fill_bytes(output.as_mut_slice());
360+
f.fill_bytes(&mut output);
361361
assert_eq!(&expected[..], &output[..]);
362362

363363
let mut scratch = [0; (1 << 20)];
364-
f.generator.generate_random_data(scratch.as_mut_slice());
364+
f.generator.generate_random_data(&mut scratch);
365365

366366
let expected = [122, 164, 26, 67, 102, 65, 30, 217, 219, 113,
367367
14, 86, 214, 146, 185, 17, 107, 135, 183, 7,
@@ -373,7 +373,7 @@ mod tests {
373373
171, 115, 157, 109, 248, 198, 227, 18, 204, 211,
374374
42, 184, 92, 42, 171, 222, 198, 117, 162, 134,
375375
116, 109, 77, 195, 187, 139, 37, 78, 224, 63];
376-
f.fill_bytes(output.as_mut_slice());
376+
f.fill_bytes(&mut output);
377377
assert_eq!(&expected[..], &output[..]);
378378

379379
f.reseed(&[5]);
@@ -389,7 +389,7 @@ mod tests {
389389
101, 10, 29, 33, 133, 87, 189, 36, 229, 56,
390390
17, 100, 138, 49, 79, 239, 210, 189, 141, 46];
391391

392-
f.fill_bytes(output.as_mut_slice());
392+
f.fill_bytes(&mut output);
393393
assert_eq!(&expected[..], &output[..]);
394394
}
395395

@@ -426,7 +426,7 @@ mod tests {
426426
226, 168, 179, 246, 82, 42, 223, 239, 201, 23,
427427
28, 30, 195, 195, 9, 154, 31, 172, 209, 232,
428428
238, 111, 75, 251, 196, 43, 217, 241, 93, 237];
429-
f.fill_bytes(output.as_mut_slice());
429+
f.fill_bytes(&mut output);
430430
assert_eq!(&expected[..], &output[..]);
431431

432432
// Immediately (less than 100ms)
@@ -446,7 +446,7 @@ mod tests {
446446
19, 167, 56, 192, 140, 93, 132, 78, 22, 16,
447447
114, 68, 123, 200, 37, 183, 163, 224, 201, 155,
448448
233, 71, 111, 26, 8, 114, 232, 181, 13, 51];
449-
f.fill_bytes(output.as_mut_slice());
449+
f.fill_bytes(&mut output);
450450
assert_eq!(&expected[..], &output[..]);
451451

452452
// Simulate more than 100 ms passing
@@ -463,7 +463,7 @@ mod tests {
463463
67, 148, 192, 52, 147, 216, 79, 204, 106, 112,
464464
238, 0, 239, 99, 159, 96, 184, 90, 54, 122,
465465
184, 241, 221, 151, 169, 29, 197, 45, 80, 6];
466-
f.fill_bytes(output.as_mut_slice());
466+
f.fill_bytes(&mut output);
467467
assert_eq!(&expected[..], &output[..]);
468468
}
469469
}

0 commit comments

Comments
 (0)