@@ -297,18 +297,12 @@ impl IHandshakeState for ResponderAwaitingActThreeState {
297
297
let chaining_key = self . chaining_key ;
298
298
299
299
// 1. Read exactly 66 bytes from the network buffer
300
- let mut act_three_bytes = [ 0u8 ; ACT_THREE_LENGTH ] ;
301
- act_three_bytes. copy_from_slice ( & read_buffer[ ..ACT_THREE_LENGTH ] ) ;
302
- read_buffer. drain ( ..ACT_THREE_LENGTH ) ;
300
+ let act_three_bytes: Vec < u8 > = read_buffer. drain ( ..ACT_THREE_LENGTH ) . collect ( ) ;
303
301
304
302
// 2. Parse the read message (m) into v, c, and t
305
303
let version = act_three_bytes[ 0 ] ;
306
-
307
- let mut tagged_encrypted_pubkey = [ 0u8 ; 49 ] ;
308
- tagged_encrypted_pubkey. copy_from_slice ( & act_three_bytes[ 1 ..50 ] ) ;
309
-
310
- let mut chacha_tag = [ 0u8 ; 16 ] ;
311
- chacha_tag. copy_from_slice ( & act_three_bytes[ 50 ..66 ] ) ;
304
+ let tagged_encrypted_pubkey = & act_three_bytes[ 1 ..50 ] ;
305
+ let chacha_tag = & act_three_bytes[ 50 ..66 ] ;
312
306
313
307
// 3. If v is an unrecognized handshake version, then the responder MUST abort the connection attempt.
314
308
if version != 0 {
@@ -318,9 +312,7 @@ impl IHandshakeState for ResponderAwaitingActThreeState {
318
312
319
313
// 4. rs = decryptWithAD(temp_k2, 1, h, c)
320
314
let remote_pubkey_vec = chacha:: decrypt ( & temporary_key, 1 , & hash, & tagged_encrypted_pubkey) ?;
321
- let mut initiator_pubkey_bytes = [ 0u8 ; 33 ] ;
322
- initiator_pubkey_bytes. copy_from_slice ( remote_pubkey_vec. as_slice ( ) ) ;
323
- let initiator_pubkey = if let Ok ( public_key) = PublicKey :: from_slice ( & initiator_pubkey_bytes) {
315
+ let initiator_pubkey = if let Ok ( public_key) = PublicKey :: from_slice ( remote_pubkey_vec. as_slice ( ) ) {
324
316
public_key
325
317
} else {
326
318
return Err ( "invalid remote public key" . to_string ( ) ) ;
@@ -419,24 +411,19 @@ fn process_act_message(read_buffer: &mut Vec<u8>, local_private_key: &SecretKey,
419
411
return Err ( "need at least 50 bytes" . to_string ( ) ) ;
420
412
}
421
413
422
- let mut act_bytes = [ 0u8 ; ACT_ONE_TWO_LENGTH ] ;
423
- act_bytes. copy_from_slice ( & read_buffer[ ..ACT_ONE_TWO_LENGTH ] ) ;
424
- read_buffer. drain ( ..ACT_ONE_TWO_LENGTH ) ;
414
+ let act_bytes: Vec < u8 > = read_buffer. drain ( ..ACT_ONE_TWO_LENGTH ) . collect ( ) ;
425
415
426
416
// 2.Parse the read message (m) into v, re, and c
427
417
let version = act_bytes[ 0 ] ;
418
+ let ephemeral_public_key_bytes = & act_bytes[ 1 ..34 ] ;
419
+ let chacha_tag = & act_bytes[ 34 ..50 ] ;
428
420
429
- let mut ephemeral_public_key_bytes = [ 0u8 ; 33 ] ;
430
- ephemeral_public_key_bytes. copy_from_slice ( & act_bytes[ 1 ..34 ] ) ;
431
421
let ephemeral_public_key = if let Ok ( public_key) = PublicKey :: from_slice ( & ephemeral_public_key_bytes) {
432
422
public_key
433
423
} else {
434
424
return Err ( "invalid remote ephemeral public key" . to_string ( ) ) ;
435
425
} ;
436
426
437
- let mut chacha_tag = [ 0u8 ; 16 ] ;
438
- chacha_tag. copy_from_slice ( & act_bytes[ 34 ..50 ] ) ;
439
-
440
427
// 3. If v is an unrecognized handshake version, then the responder MUST abort the connection attempt
441
428
if version != 0 {
442
429
// this should not crash the process, hence no panic
0 commit comments