@@ -276,19 +276,7 @@ pub trait AeadInPlace: AeadCore {
276
276
nonce : & Nonce < Self > ,
277
277
associated_data : & [ u8 ] ,
278
278
buffer : & mut dyn Buffer ,
279
- ) -> Result < ( ) > {
280
- let tag = self . encrypt_in_place_detached ( nonce, associated_data, buffer. as_mut ( ) ) ?;
281
- buffer. extend_from_slice ( tag. as_slice ( ) ) ?;
282
- Ok ( ( ) )
283
- }
284
-
285
- /// Encrypt the data in-place, returning the authentication tag
286
- fn encrypt_in_place_detached (
287
- & self ,
288
- nonce : & Nonce < Self > ,
289
- associated_data : & [ u8 ] ,
290
- buffer : & mut [ u8 ] ,
291
- ) -> Result < Tag < Self > > ;
279
+ ) -> Result < ( ) > ;
292
280
293
281
/// Decrypt the message in-place, returning an error in the event the
294
282
/// provided authentication tag does not match the given ciphertext.
@@ -300,9 +288,17 @@ pub trait AeadInPlace: AeadCore {
300
288
nonce : & Nonce < Self > ,
301
289
associated_data : & [ u8 ] ,
302
290
buffer : & mut dyn Buffer ,
303
- ) -> Result < ( ) > {
304
- impl_decrypt_in_place ! ( self , nonce, associated_data, buffer)
305
- }
291
+ ) -> Result < ( ) > ;
292
+ }
293
+
294
+ pub trait AeadInPlaceDetached : AeadCore {
295
+ /// Encrypt the data in-place, returning the authentication tag.
296
+ fn encrypt_in_place_detached (
297
+ & self ,
298
+ nonce : & Nonce < Self > ,
299
+ associated_data : & [ u8 ] ,
300
+ buffer : & mut [ u8 ] ,
301
+ ) -> Result < Tag < Self > > ;
306
302
307
303
/// Decrypt the message in-place, returning an error in the event the provided
308
304
/// authentication tag does not match the given ciphertext (i.e. ciphertext
@@ -316,6 +312,30 @@ pub trait AeadInPlace: AeadCore {
316
312
) -> Result < ( ) > ;
317
313
}
318
314
315
+ pub trait PostfixTagged { }
316
+
317
+ impl < T : AeadInPlaceDetached + PostfixTagged > AeadInPlace for T {
318
+ fn encrypt_in_place (
319
+ & self ,
320
+ nonce : & Nonce < Self > ,
321
+ associated_data : & [ u8 ] ,
322
+ buffer : & mut dyn Buffer ,
323
+ ) -> Result < ( ) > {
324
+ let tag = self . encrypt_in_place_detached ( nonce, associated_data, buffer. as_mut ( ) ) ?;
325
+ buffer. extend_from_slice ( tag. as_slice ( ) ) ?;
326
+ Ok ( ( ) )
327
+ }
328
+
329
+ fn decrypt_in_place (
330
+ & self ,
331
+ nonce : & Nonce < Self > ,
332
+ associated_data : & [ u8 ] ,
333
+ buffer : & mut dyn Buffer ,
334
+ ) -> Result < ( ) > {
335
+ impl_decrypt_in_place ! ( self , nonce, associated_data, buffer)
336
+ }
337
+ }
338
+
319
339
/// In-place stateful AEAD trait.
320
340
///
321
341
/// This trait is both object safe and has no dependencies on `alloc` or `std`.
0 commit comments