From a69680850502971d50c0f69ff088ef673c2b4dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 20 Nov 2024 16:26:37 +0300 Subject: [PATCH] Remove `DynAead` --- aead/src/dyn_aead.rs | 201 ------------------------------------------- aead/src/lib.rs | 4 - 2 files changed, 205 deletions(-) delete mode 100644 aead/src/dyn_aead.rs diff --git a/aead/src/dyn_aead.rs b/aead/src/dyn_aead.rs deleted file mode 100644 index 79a2da20..00000000 --- a/aead/src/dyn_aead.rs +++ /dev/null @@ -1,201 +0,0 @@ -use inout::{InOutBuf, InOutBufReserved}; - -use crate::{Aead, Buffer, Error, Result}; - -#[cfg(feature = "alloc")] -use alloc::vec::Vec; - -mod sealed { - pub trait Sealed {} -} - -/// Object-safe variant of the [`Aead`] trait. -/// -/// This trait is implemented automaticlly for all types which implement the [`Aead`] trait. -pub trait DynAead: sealed::Sealed { - fn postfix_encrypt_inout<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - buffer: InOutBufReserved<'_, 'out, u8>, - ) -> Result<&'out mut [u8]>; - - fn postfix_decrypt_inout<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - buffer: InOutBuf<'_, 'out, u8>, - ) -> Result<&'out mut [u8]>; - - fn postfix_encrypt_inplace<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - buffer: &'out mut [u8], - plaintext_len: usize, - ) -> Result<&'out mut [u8]>; - - fn postfix_decrypt_inplace<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - buffer: &'out mut [u8], - ) -> Result<&'out mut [u8]>; - - fn postfix_encrypt_to_buf<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - plaintext: &[u8], - buffer: &'out mut [u8], - ) -> Result<&'out mut [u8]>; - - fn postfix_decrypt_to_buf<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - ciphertext: &[u8], - buffer: &'out mut [u8], - ) -> Result<&'out mut [u8]>; - - fn encrypt_to_buffer2( - &self, - nonce: &[u8], - associated_data: &[u8], - plaintext: &[u8], - buffer: &mut dyn Buffer, - ) -> Result<()>; - - fn decrypt_to_buffer2( - &self, - nonce: &[u8], - associated_data: &[u8], - ciphertext: &[u8], - buffer: &mut dyn Buffer, - ) -> Result<()>; - - #[cfg(feature = "alloc")] - fn encrypt_to_vec( - &self, - nonce: &[u8], - associated_data: &[u8], - plaintext: &[u8], - ) -> Result>; - - #[cfg(feature = "alloc")] - fn decrypt_to_vec( - &self, - nonce: &[u8], - associated_data: &[u8], - ciphertext: &[u8], - ) -> Result>; -} - -impl sealed::Sealed for T {} - -impl DynAead for T { - fn postfix_encrypt_inout<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - buffer: InOutBufReserved<'_, 'out, u8>, - ) -> Result<&'out mut [u8]> { - let nonce = nonce.try_into().map_err(|_| Error)?; - Aead::postfix_encrypt_inout(self, nonce, associated_data, buffer) - } - - fn postfix_decrypt_inout<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - buffer: InOutBuf<'_, 'out, u8>, - ) -> Result<&'out mut [u8]> { - let nonce = nonce.try_into().map_err(|_| Error)?; - Aead::postfix_decrypt_inout(self, nonce, associated_data, buffer) - } - - fn postfix_encrypt_inplace<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - buffer: &'out mut [u8], - plaintext_len: usize, - ) -> Result<&'out mut [u8]> { - let nonce = nonce.try_into().map_err(|_| Error)?; - Aead::postfix_encrypt_inplace(self, nonce, associated_data, buffer, plaintext_len) - } - - fn postfix_decrypt_inplace<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - buffer: &'out mut [u8], - ) -> Result<&'out mut [u8]> { - let nonce = nonce.try_into().map_err(|_| Error)?; - Aead::postfix_decrypt_inplace(self, nonce, associated_data, buffer) - } - - fn postfix_encrypt_to_buf<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - plaintext: &[u8], - buffer: &'out mut [u8], - ) -> Result<&'out mut [u8]> { - let nonce = nonce.try_into().map_err(|_| Error)?; - Aead::postfix_encrypt_to_buf(self, nonce, associated_data, plaintext, buffer) - } - - fn postfix_decrypt_to_buf<'out>( - &self, - nonce: &[u8], - associated_data: &[u8], - ciphertext: &[u8], - buffer: &'out mut [u8], - ) -> Result<&'out mut [u8]> { - let nonce = nonce.try_into().map_err(|_| Error)?; - Aead::postfix_decrypt_to_buf(self, nonce, associated_data, ciphertext, buffer) - } - - fn encrypt_to_buffer2( - &self, - nonce: &[u8], - aad: &[u8], - msg: &[u8], - buffer: &mut dyn Buffer, - ) -> Result<()> { - let nonce = nonce.try_into().map_err(|_| Error)?; - let payload = crate::Payload { aad, msg }; - Aead::encrypt_to_buffer(self, nonce, payload, buffer) - } - - fn decrypt_to_buffer2( - &self, - nonce: &[u8], - aad: &[u8], - msg: &[u8], - buffer: &mut dyn Buffer, - ) -> Result<()> { - let nonce = nonce.try_into().map_err(|_| Error)?; - let payload = crate::Payload { aad, msg }; - Aead::decrypt_to_buffer(self, nonce, payload, buffer) - } - - #[cfg(feature = "alloc")] - fn encrypt_to_vec(&self, nonce: &[u8], aad: &[u8], msg: &[u8]) -> Result> { - let nonce = nonce.try_into().map_err(|_| Error)?; - let payload = crate::Payload { aad, msg }; - Aead::encrypt_to_vec(self, nonce, payload) - } - - #[cfg(feature = "alloc")] - fn decrypt_to_vec(&self, nonce: &[u8], aad: &[u8], msg: &[u8]) -> Result> { - let nonce = nonce.try_into().map_err(|_| Error)?; - let payload = crate::Payload { aad, msg }; - Aead::decrypt_to_vec(self, nonce, payload) - } -} - -// Ensure that `DynAead` is an object-safe trait -#[allow(dead_code)] -fn foo(_: &dyn DynAead) {} diff --git a/aead/src/lib.rs b/aead/src/lib.rs index 2556b99a..117358bb 100644 --- a/aead/src/lib.rs +++ b/aead/src/lib.rs @@ -25,10 +25,6 @@ use arrayvec::ArrayVec; #[cfg(feature = "dev")] pub mod dev; -mod dyn_aead; - -pub use dyn_aead::DynAead; - pub mod stream; pub use crypto_common::{