Skip to content

Commit cac73b0

Browse files
authored
aead: deprecated AeadInPlace trait (#1882)
`AeadInPlace` was removed in #1798, however in migrating some older code I thought it would be really helpful to have backwards compatibility and deprecations in place to help people migrate to the new names, especially as the "in place" -> "inout" migrations aren't entirely intuitive.
1 parent 52a989f commit cac73b0

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

aead/src/lib.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,98 @@ pub trait AeadInOut: AeadCore {
329329
}
330330
}
331331

332+
/// Legacy in-place stateless AEAD trait.
333+
///
334+
/// NOTE: deprecated! Please migrate to [`AeadInOut`].
335+
#[deprecated(since = "0.6.0", note = "use `AeadInOut` instead")]
336+
pub trait AeadInPlace: AeadCore {
337+
/// Encrypt the given buffer containing a plaintext message in-place.
338+
#[deprecated(since = "0.6.0", note = "use `AeadInOut::encrypt_in_place` instead")]
339+
fn encrypt_in_place(
340+
&self,
341+
nonce: &Nonce<Self>,
342+
associated_data: &[u8],
343+
buffer: &mut dyn Buffer,
344+
) -> Result<()>;
345+
346+
/// Encrypt the data in-place, returning the authentication tag
347+
#[deprecated(
348+
since = "0.6.0",
349+
note = "use `AeadInOut::encrypt_inout_detached` instead"
350+
)]
351+
fn encrypt_in_place_detached(
352+
&self,
353+
nonce: &Nonce<Self>,
354+
associated_data: &[u8],
355+
buffer: &mut [u8],
356+
) -> Result<Tag<Self>>;
357+
358+
/// Decrypt the message in-place, returning an error in the event the
359+
/// provided authentication tag does not match the given ciphertext.
360+
#[deprecated(since = "0.6.0", note = "use `AeadInOut::decrypt_in_place` instead")]
361+
fn decrypt_in_place(
362+
&self,
363+
nonce: &Nonce<Self>,
364+
associated_data: &[u8],
365+
buffer: &mut dyn Buffer,
366+
) -> Result<()>;
367+
368+
/// Decrypt the message in-place, returning an error in the event the provided
369+
/// authentication tag does not match the given ciphertext (i.e. ciphertext
370+
/// is modified/unauthentic)
371+
#[deprecated(
372+
since = "0.6.0",
373+
note = "use `AeadInOut::decrypt_inout_detached` instead"
374+
)]
375+
fn decrypt_in_place_detached(
376+
&self,
377+
nonce: &Nonce<Self>,
378+
associated_data: &[u8],
379+
buffer: &mut [u8],
380+
tag: &Tag<Self>,
381+
) -> Result<()>;
382+
}
383+
384+
#[allow(deprecated)]
385+
impl<T: AeadInOut> AeadInPlace for T {
386+
fn encrypt_in_place(
387+
&self,
388+
nonce: &Nonce<Self>,
389+
associated_data: &[u8],
390+
buffer: &mut dyn Buffer,
391+
) -> Result<()> {
392+
<Self as AeadInOut>::encrypt_in_place(self, nonce, associated_data, buffer)
393+
}
394+
395+
fn encrypt_in_place_detached(
396+
&self,
397+
nonce: &Nonce<Self>,
398+
associated_data: &[u8],
399+
buffer: &mut [u8],
400+
) -> Result<Tag<Self>> {
401+
self.encrypt_inout_detached(nonce, associated_data, buffer.into())
402+
}
403+
404+
fn decrypt_in_place(
405+
&self,
406+
nonce: &Nonce<Self>,
407+
associated_data: &[u8],
408+
buffer: &mut dyn Buffer,
409+
) -> Result<()> {
410+
<Self as AeadInOut>::decrypt_in_place(self, nonce, associated_data, buffer)
411+
}
412+
413+
fn decrypt_in_place_detached(
414+
&self,
415+
nonce: &Nonce<Self>,
416+
associated_data: &[u8],
417+
buffer: &mut [u8],
418+
tag: &Tag<Self>,
419+
) -> Result<()> {
420+
self.decrypt_inout_detached(nonce, associated_data, buffer.into(), tag)
421+
}
422+
}
423+
332424
/// AEAD payloads (message + AAD).
333425
///
334426
/// Combination of a message (plaintext or ciphertext) and

0 commit comments

Comments
 (0)