diff --git a/block-padding/CHANGELOG.md b/block-padding/CHANGELOG.md index 91bbd955..d624b500 100644 --- a/block-padding/CHANGELOG.md +++ b/block-padding/CHANGELOG.md @@ -8,9 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Migrated from `generic-array` to `hybrid-array` ([#944]) - Edition changed to 2024 and MSRV bumped to 1.85 ([#1149]) +- Merged `RawPadding` and `Padding` traits ([#1217]) + +### Removed +- `Block` type alias ([#1217]) [#944]: https://github.com/RustCrypto/utils/pull/944 [#1149]: https://github.com/RustCrypto/utils/pull/1149 +[#1217]: https://github.com/RustCrypto/utils/pull/1217 ## 0.3.3 (2023-04-02) ### Added diff --git a/block-padding/src/lib.rs b/block-padding/src/lib.rs index 912cf7ff..da556015 100644 --- a/block-padding/src/lib.rs +++ b/block-padding/src/lib.rs @@ -26,8 +26,8 @@ pub enum PadType { NoPadding, } -/// Trait for padding messages divided into blocks of arbitrary size -pub trait RawPadding { +/// Trait for messages padding algorithms. +pub trait Padding { /// Padding type const TYPE: PadType; @@ -43,15 +43,6 @@ pub trait RawPadding { /// /// Returns `Err(UnpadError)` if the block contains malformed padding. fn raw_unpad(block: &[u8]) -> Result<&[u8], UnpadError>; -} - -/// Block size. -pub type Block = Array; - -/// Trait for padding messages divided into blocks -pub trait Padding { - /// Padding type - const TYPE: PadType; /// Pads `block` filled with data up to `pos` (i.e length of a message /// stored in the block is equal to `pos`). @@ -59,17 +50,23 @@ pub trait Padding { /// # Panics /// If `pos` is bigger than `BlockSize`. Most padding algorithms also /// panic if they are equal. - fn pad(block: &mut Block, pos: usize); + fn pad(block: &mut Array, pos: usize) { + Self::raw_pad(block.as_mut_slice(), pos); + } /// Unpad data in the `block`. /// /// Returns `Err(UnpadError)` if the block contains malformed padding. - fn unpad(block: &Block) -> Result<&[u8], UnpadError>; + fn unpad(block: &Array) -> Result<&[u8], UnpadError> { + Self::raw_unpad(block.as_slice()) + } /// Unpad data in the `blocks`. /// /// Returns `Err(UnpadError)` if the block contains malformed padding. - fn unpad_blocks(blocks: &[Block]) -> Result<&[u8], UnpadError> { + fn unpad_blocks( + blocks: &[Array], + ) -> Result<&[u8], UnpadError> { let bs = BlockSize::USIZE; let res_len = match (blocks.last(), Self::TYPE) { (_, PadType::NoPadding) => bs * blocks.len(), @@ -89,23 +86,6 @@ pub trait Padding { } } -impl Padding for T -where - T: RawPadding, -{ - const TYPE: PadType = T::TYPE; - - #[inline] - fn pad(block: &mut Block, pos: usize) { - T::raw_pad(block.as_mut_slice(), pos); - } - - #[inline] - fn unpad(block: &Block) -> Result<&[u8], UnpadError> { - T::raw_unpad(block.as_slice()) - } -} - /// Pad block with zeros. /// /// ``` @@ -127,7 +107,7 @@ where #[derive(Clone, Copy, Debug)] pub struct ZeroPadding; -impl RawPadding for ZeroPadding { +impl Padding for ZeroPadding { const TYPE: PadType = PadType::Ambiguous; #[inline] @@ -189,7 +169,7 @@ impl Pkcs7 { } } -impl RawPadding for Pkcs7 { +impl Padding for Pkcs7 { const TYPE: PadType = PadType::Reversible; #[inline] @@ -231,7 +211,7 @@ impl RawPadding for Pkcs7 { #[derive(Clone, Copy, Debug)] pub struct Iso10126; -impl RawPadding for Iso10126 { +impl Padding for Iso10126 { const TYPE: PadType = PadType::Reversible; #[inline] @@ -266,7 +246,7 @@ impl RawPadding for Iso10126 { #[derive(Clone, Copy, Debug)] pub struct AnsiX923; -impl RawPadding for AnsiX923 { +impl Padding for AnsiX923 { const TYPE: PadType = PadType::Reversible; #[inline] @@ -320,7 +300,7 @@ impl RawPadding for AnsiX923 { #[derive(Clone, Copy, Debug)] pub struct Iso7816; -impl RawPadding for Iso7816 { +impl Padding for Iso7816 { const TYPE: PadType = PadType::Reversible; #[inline] @@ -369,7 +349,7 @@ impl RawPadding for Iso7816 { #[derive(Clone, Copy, Debug)] pub struct NoPadding; -impl RawPadding for NoPadding { +impl Padding for NoPadding { const TYPE: PadType = PadType::NoPadding; #[inline] diff --git a/inout/src/reserved.rs b/inout/src/reserved.rs index 635d323e..701f8b50 100644 --- a/inout/src/reserved.rs +++ b/inout/src/reserved.rs @@ -155,7 +155,7 @@ impl<'inp, 'out> InOutBufReserved<'inp, 'out, u8> { #[inline(always)] pub fn into_padded_blocks(self) -> Result, PadError> where - P: Padding, + P: Padding, BS: ArraySize, { let bs = BS::USIZE;