@@ -79,8 +79,9 @@ impl KeyObfuscator {
7979		tag. copy_from_slice ( & tag_bytes) ; 
8080
8181		let  ( wrapped_nonce_bytes,  wrapped_nonce_tag_bytes)  = remaining. split_at ( NONCE_LENGTH ) ; 
82+ 
8283		let  mut  wrapped_nonce_tag = [ 0u8 ;  TAG_LENGTH ] ; 
83- 		wrapped_nonce_tag. copy_from_slice ( wrapped_nonce_tag_bytes) ; 
84+ 		wrapped_nonce_tag. copy_from_slice ( & wrapped_nonce_tag_bytes[ .. TAG_LENGTH ] ) ; 
8485
8586		// Unwrap wrapped_nonce to get nonce. 
8687		let  mut  wrapped_nonce = [ 0u8 ;  NONCE_LENGTH ] ; 
@@ -94,10 +95,8 @@ impl KeyObfuscator {
9495		} ) ?; 
9596
9697		// Decrypt ciphertext using nonce. 
97- 		let  cipher = ChaCha20Poly1305 :: new ( 
98- 			Key :: new ( self . obfuscation_key . clone ( ) ) , 
99- 			Nonce :: new ( wrapped_nonce) , 
100- 		) ; 
98+ 		let  cipher =
99+ 			ChaCha20Poly1305 :: new ( Key :: new ( self . obfuscation_key ) ,  Nonce :: new ( wrapped_nonce) ) ; 
101100		let  mut  ciphertext = ciphertext. to_vec ( ) ; 
102101		cipher. decrypt ( & mut  ciphertext,  tag,  None ) . map_err ( |_| { 
103102			let  msg = format ! ( "Failed to decrypt key: {}, Invalid Tag." ,  obfuscated_key) ; 
@@ -119,10 +118,7 @@ impl KeyObfuscator {
119118		& self ,  mut  plaintext :  & mut  [ u8 ] ,  initial_nonce_material :  & [ u8 ] , 
120119	)  -> ( [ u8 ;  NONCE_LENGTH ] ,  [ u8 ;  TAG_LENGTH ] )  { 
121120		let  nonce = self . generate_synthetic_nonce ( initial_nonce_material) ; 
122- 		let  cipher = ChaCha20Poly1305 :: new ( 
123- 			Key :: new ( self . obfuscation_key . clone ( ) ) , 
124- 			Nonce :: new ( nonce. clone ( ) ) , 
125- 		) ; 
121+ 		let  cipher = ChaCha20Poly1305 :: new ( Key :: new ( self . obfuscation_key ) ,  Nonce :: new ( nonce) ) ; 
126122		let  tag = cipher. encrypt ( & mut  plaintext,  None ) ; 
127123		( nonce,  tag) 
128124	} 
@@ -132,10 +128,7 @@ impl KeyObfuscator {
132128		& self ,  mut  ciphertext :  & mut  [ u8 ] ,  initial_nonce_material :  & [ u8 ] ,  tag :  [ u8 ;  TAG_LENGTH ] , 
133129	)  -> Result < ( ) ,  ( ) >  { 
134130		let  nonce = self . generate_synthetic_nonce ( initial_nonce_material) ; 
135- 		let  cipher = ChaCha20Poly1305 :: new ( 
136- 			Key :: new ( self . obfuscation_key . clone ( ) ) , 
137- 			Nonce :: new ( nonce. clone ( ) ) , 
138- 		) ; 
131+ 		let  cipher = ChaCha20Poly1305 :: new ( Key :: new ( self . obfuscation_key ) ,  Nonce :: new ( nonce) ) ; 
139132		cipher. decrypt ( & mut  ciphertext,  tag,  None ) . map_err ( |_| ( ) ) 
140133	} 
141134
0 commit comments