7878//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the
7979//! [`aead`] crate as [`aead::bytes::BytesMut`]).
8080
81- pub use aead:: { self , AeadCore , AeadInPlaceDetached , Error , Key , KeyInit , KeySizeUser } ;
81+ pub use aead:: { self , AeadCore , AeadInOut , Error , Key , KeyInit , KeySizeUser } ;
8282
8383#[ cfg( feature = "aes" ) ]
8484pub use aes;
8585
86- use aead:: PostfixTagged ;
86+ use aead:: { PostfixTagged , inout :: InOutBuf } ;
8787use cipher:: {
8888 BlockCipherEncrypt , BlockSizeUser , InnerIvInit , StreamCipherCore ,
8989 array:: Array ,
@@ -165,28 +165,28 @@ where
165165
166166impl < Aes > PostfixTagged for AesGcmSiv < Aes > { }
167167
168- impl < Aes > AeadInPlaceDetached for AesGcmSiv < Aes >
168+ impl < Aes > AeadInOut for AesGcmSiv < Aes >
169169where
170170 Aes : BlockSizeUser < BlockSize = U16 > + BlockCipherEncrypt + KeyInit ,
171171{
172- fn encrypt_in_place_detached (
172+ fn encrypt_inout_detached (
173173 & self ,
174174 nonce : & Nonce ,
175175 associated_data : & [ u8 ] ,
176- buffer : & mut [ u8 ] ,
176+ buffer : InOutBuf < ' _ , ' _ , u8 > ,
177177 ) -> Result < Tag , Error > {
178178 Cipher :: < Aes > :: new ( & self . key_generating_key , nonce)
179- . encrypt_in_place_detached ( associated_data, buffer)
179+ . encrypt_inout_detached ( associated_data, buffer)
180180 }
181181
182- fn decrypt_in_place_detached (
182+ fn decrypt_inout_detached (
183183 & self ,
184184 nonce : & Nonce ,
185185 associated_data : & [ u8 ] ,
186- buffer : & mut [ u8 ] ,
186+ buffer : InOutBuf < ' _ , ' _ , u8 > ,
187187 tag : & Tag ,
188188 ) -> Result < ( ) , Error > {
189- Cipher :: < Aes > :: new ( & self . key_generating_key , nonce) . decrypt_in_place_detached (
189+ Cipher :: < Aes > :: new ( & self . key_generating_key , nonce) . decrypt_inout_detached (
190190 associated_data,
191191 buffer,
192192 tag,
@@ -268,30 +268,30 @@ where
268268 }
269269
270270 /// Encrypt the given message in-place, returning the authentication tag.
271- pub ( crate ) fn encrypt_in_place_detached (
271+ pub ( crate ) fn encrypt_inout_detached (
272272 mut self ,
273273 associated_data : & [ u8 ] ,
274- buffer : & mut [ u8 ] ,
274+ buffer : InOutBuf < ' _ , ' _ , u8 > ,
275275 ) -> Result < Tag , Error > {
276276 if buffer. len ( ) as u64 > P_MAX || associated_data. len ( ) as u64 > A_MAX {
277277 return Err ( Error ) ;
278278 }
279279
280280 self . polyval . update_padded ( associated_data) ;
281- self . polyval . update_padded ( buffer) ;
281+ self . polyval . update_padded ( buffer. get_in ( ) ) ;
282282
283283 let tag = self . finish_tag ( associated_data. len ( ) , buffer. len ( ) ) ;
284- init_ctr ( & self . enc_cipher , & tag) . apply_keystream_partial ( buffer. into ( ) ) ;
284+ init_ctr ( & self . enc_cipher , & tag) . apply_keystream_partial ( buffer) ;
285285
286286 Ok ( tag)
287287 }
288288
289289 /// Decrypt the given message, first authenticating ciphertext integrity
290290 /// and returning an error if it's been tampered with.
291- pub ( crate ) fn decrypt_in_place_detached (
291+ pub ( crate ) fn decrypt_inout_detached (
292292 mut self ,
293293 associated_data : & [ u8 ] ,
294- buffer : & mut [ u8 ] ,
294+ mut buffer : InOutBuf < ' _ , ' _ , u8 > ,
295295 tag : & Tag ,
296296 ) -> Result < ( ) , Error > {
297297 if buffer. len ( ) as u64 > C_MAX || associated_data. len ( ) as u64 > A_MAX {
@@ -301,8 +301,8 @@ where
301301 self . polyval . update_padded ( associated_data) ;
302302
303303 // TODO(tarcieri): interleave decryption and authentication
304- init_ctr ( & self . enc_cipher , tag) . apply_keystream_partial ( buffer. into ( ) ) ;
305- self . polyval . update_padded ( buffer) ;
304+ init_ctr ( & self . enc_cipher , tag) . apply_keystream_partial ( buffer. reborrow ( ) ) ;
305+ self . polyval . update_padded ( buffer. get_out ( ) ) ;
306306
307307 let expected_tag = self . finish_tag ( associated_data. len ( ) , buffer. len ( ) ) ;
308308
@@ -312,7 +312,7 @@ where
312312 } else {
313313 // On MAC verify failure, re-encrypt the plaintext buffer to
314314 // prevent accidental exposure.
315- init_ctr ( & self . enc_cipher , tag) . apply_keystream_partial ( buffer. into ( ) ) ;
315+ init_ctr ( & self . enc_cipher , tag) . apply_keystream_partial ( buffer) ;
316316 Err ( Error )
317317 }
318318 }
0 commit comments