Skip to content

Commit 4b5defb

Browse files
committed
chore(deps): bump block-padding from 0.4.0-rc.4 to 0.4.1
1 parent c1047be commit 4b5defb

File tree

2 files changed

+42
-55
lines changed

2 files changed

+42
-55
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cipher/src/block.rs

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use inout::{InOut, InOutBuf, NotEqualError};
1717
#[cfg(feature = "block-padding")]
1818
use inout::{
1919
InOutBufReserved, PadError,
20-
block_padding::{Padding, UnpadError},
20+
block_padding::{self, Padding},
2121
};
2222

2323
mod backends;
@@ -87,7 +87,7 @@ pub trait BlockCipherEncrypt: BlockSizeUser + Sized {
8787
/// Returns [`PadError`] if length of output buffer is not sufficient.
8888
#[cfg(feature = "block-padding")]
8989
#[inline]
90-
fn encrypt_padded_inout<'out, P: Padding<Self::BlockSize>>(
90+
fn encrypt_padded_inout<'out, P: Padding>(
9191
&self,
9292
data: InOutBufReserved<'_, 'out, u8>,
9393
) -> Result<&'out [u8], PadError> {
@@ -104,7 +104,7 @@ pub trait BlockCipherEncrypt: BlockSizeUser + Sized {
104104
/// Returns [`PadError`] if length of output buffer is not sufficient.
105105
#[cfg(feature = "block-padding")]
106106
#[inline]
107-
fn encrypt_padded<'a, P: Padding<Self::BlockSize>>(
107+
fn encrypt_padded<'a, P: Padding>(
108108
&self,
109109
buf: &'a mut [u8],
110110
msg_len: usize,
@@ -118,7 +118,7 @@ pub trait BlockCipherEncrypt: BlockSizeUser + Sized {
118118
/// Returns [`PadError`] if length of output buffer is not sufficient.
119119
#[cfg(feature = "block-padding")]
120120
#[inline]
121-
fn encrypt_padded_b2b<'a, P: Padding<Self::BlockSize>>(
121+
fn encrypt_padded_b2b<'a, P: Padding>(
122122
&self,
123123
msg: &[u8],
124124
out_buf: &'a mut [u8],
@@ -130,7 +130,7 @@ pub trait BlockCipherEncrypt: BlockSizeUser + Sized {
130130
/// Pad input and encrypt into a newly allocated Vec. Returns resulting ciphertext Vec.
131131
#[cfg(all(feature = "block-padding", feature = "alloc"))]
132132
#[inline]
133-
fn encrypt_padded_vec<P: Padding<Self::BlockSize>>(&self, msg: &[u8]) -> Vec<u8> {
133+
fn encrypt_padded_vec<P: Padding>(&self, msg: &[u8]) -> Vec<u8> {
134134
use crypto_common::typenum::Unsigned;
135135
let bs = Self::BlockSize::USIZE;
136136
let mut out = vec![0; bs * (msg.len() / bs + 1)];
@@ -197,67 +197,64 @@ pub trait BlockCipherDecrypt: BlockSizeUser {
197197

198198
/// Decrypt input and unpad it. Returns resulting plaintext slice.
199199
///
200-
/// Returns [`UnpadError`] if padding is malformed or if input length is
200+
/// Returns [`block_padding::Error`] if padding is malformed or if input length is
201201
/// not multiple of `Self::BlockSize`.
202202
#[cfg(feature = "block-padding")]
203203
#[inline]
204-
fn decrypt_padded_inout<'out, P: Padding<Self::BlockSize>>(
204+
fn decrypt_padded_inout<'out, P: Padding>(
205205
&self,
206206
data: InOutBuf<'_, 'out, u8>,
207-
) -> Result<&'out [u8], UnpadError> {
207+
) -> Result<&'out [u8], block_padding::Error> {
208208
let (mut blocks, tail) = data.into_chunks();
209209
if !tail.is_empty() {
210-
return Err(UnpadError);
210+
return Err(block_padding::Error);
211211
}
212212
self.decrypt_blocks_inout(blocks.reborrow());
213-
P::unpad_blocks(blocks.into_out())
213+
P::unpad_blocks::<Self::BlockSize>(blocks.into_out())
214214
}
215215

216216
/// Decrypt input and unpad it in-place. Returns resulting plaintext slice.
217217
///
218-
/// Returns [`UnpadError`] if padding is malformed or if input length is
218+
/// Returns [`block_padding::Error`] if padding is malformed or if input length is
219219
/// not multiple of `Self::BlockSize`.
220220
#[cfg(feature = "block-padding")]
221221
#[inline]
222-
fn decrypt_padded<'a, P: Padding<Self::BlockSize>>(
222+
fn decrypt_padded<'a, P: Padding>(
223223
&self,
224224
buf: &'a mut [u8],
225-
) -> Result<&'a [u8], UnpadError> {
225+
) -> Result<&'a [u8], block_padding::Error> {
226226
self.decrypt_padded_inout::<P>(buf.into())
227227
}
228228

229229
/// Decrypt input and unpad it buffer-to-buffer. Returns resulting
230230
/// plaintext slice.
231231
///
232-
/// Returns [`UnpadError`] if padding is malformed or if input length is
232+
/// Returns [`block_padding::Error`] if padding is malformed or if input length is
233233
/// not multiple of `Self::BlockSize`.
234234
#[cfg(feature = "block-padding")]
235235
#[inline]
236-
fn decrypt_padded_b2b<'a, P: Padding<Self::BlockSize>>(
236+
fn decrypt_padded_b2b<'a, P: Padding>(
237237
&self,
238238
in_buf: &[u8],
239239
out_buf: &'a mut [u8],
240-
) -> Result<&'a [u8], UnpadError> {
240+
) -> Result<&'a [u8], block_padding::Error> {
241241
if out_buf.len() < in_buf.len() {
242-
return Err(UnpadError);
242+
return Err(block_padding::Error);
243243
}
244244
let n = in_buf.len();
245245
// note: `new` always returns `Ok` here
246-
let buf = InOutBuf::new(in_buf, &mut out_buf[..n]).map_err(|_| UnpadError)?;
246+
let buf = InOutBuf::new(in_buf, &mut out_buf[..n]).map_err(|_| block_padding::Error)?;
247247
self.decrypt_padded_inout::<P>(buf)
248248
}
249249

250250
/// Decrypt input and unpad it in a newly allocated Vec. Returns resulting
251251
/// plaintext `Vec`.
252252
///
253-
/// Returns [`UnpadError`] if padding is malformed or if input length is
253+
/// Returns [`block_padding::Error`] if padding is malformed or if input length is
254254
/// not multiple of `Self::BlockSize`.
255255
#[cfg(all(feature = "block-padding", feature = "alloc"))]
256256
#[inline]
257-
fn decrypt_padded_vec<P: Padding<Self::BlockSize>>(
258-
&self,
259-
buf: &[u8],
260-
) -> Result<Vec<u8>, UnpadError> {
257+
fn decrypt_padded_vec<P: Padding>(&self, buf: &[u8]) -> Result<Vec<u8>, block_padding::Error> {
261258
let mut out = vec![0; buf.len()];
262259
let len = self.decrypt_padded_b2b::<P>(buf, &mut out)?.len();
263260
out.truncate(len);
@@ -338,7 +335,7 @@ pub trait BlockModeEncrypt: BlockSizeUser + Sized {
338335
/// Returns [`PadError`] if length of output buffer is not sufficient.
339336
#[cfg(feature = "block-padding")]
340337
#[inline]
341-
fn encrypt_padded_inout<'out, P: Padding<Self::BlockSize>>(
338+
fn encrypt_padded_inout<'out, P: Padding>(
342339
mut self,
343340
data: InOutBufReserved<'_, 'out, u8>,
344341
) -> Result<&'out [u8], PadError> {
@@ -355,11 +352,7 @@ pub trait BlockModeEncrypt: BlockSizeUser + Sized {
355352
/// Returns [`PadError`] if length of output buffer is not sufficient.
356353
#[cfg(feature = "block-padding")]
357354
#[inline]
358-
fn encrypt_padded<P: Padding<Self::BlockSize>>(
359-
self,
360-
buf: &mut [u8],
361-
msg_len: usize,
362-
) -> Result<&[u8], PadError> {
355+
fn encrypt_padded<P: Padding>(self, buf: &mut [u8], msg_len: usize) -> Result<&[u8], PadError> {
363356
let buf = InOutBufReserved::from_mut_slice(buf, msg_len).map_err(|_| PadError)?;
364357
self.encrypt_padded_inout::<P>(buf)
365358
}
@@ -369,7 +362,7 @@ pub trait BlockModeEncrypt: BlockSizeUser + Sized {
369362
/// Returns [`PadError`] if length of output buffer is not sufficient.
370363
#[cfg(feature = "block-padding")]
371364
#[inline]
372-
fn encrypt_padded_b2b<'a, P: Padding<Self::BlockSize>>(
365+
fn encrypt_padded_b2b<'a, P: Padding>(
373366
self,
374367
msg: &[u8],
375368
out_buf: &'a mut [u8],
@@ -381,7 +374,7 @@ pub trait BlockModeEncrypt: BlockSizeUser + Sized {
381374
/// Pad input and encrypt into a newly allocated Vec. Returns resulting ciphertext Vec.
382375
#[cfg(all(feature = "block-padding", feature = "alloc"))]
383376
#[inline]
384-
fn encrypt_padded_vec<P: Padding<Self::BlockSize>>(self, msg: &[u8]) -> Vec<u8> {
377+
fn encrypt_padded_vec<P: Padding>(self, msg: &[u8]) -> Vec<u8> {
385378
use crypto_common::typenum::Unsigned;
386379
let bs = Self::BlockSize::USIZE;
387380
let mut out = vec![0; bs * (msg.len() / bs + 1)];
@@ -452,67 +445,61 @@ pub trait BlockModeDecrypt: BlockSizeUser + Sized {
452445

453446
/// Decrypt input and unpad it. Returns resulting plaintext slice.
454447
///
455-
/// Returns [`UnpadError`] if padding is malformed or if input length is
448+
/// Returns [`block_padding::Error`] if padding is malformed or if input length is
456449
/// not multiple of `Self::BlockSize`.
457450
#[cfg(feature = "block-padding")]
458451
#[inline]
459-
fn decrypt_padded_inout<'out, P: Padding<Self::BlockSize>>(
452+
fn decrypt_padded_inout<'out, P: Padding>(
460453
mut self,
461454
data: InOutBuf<'_, 'out, u8>,
462-
) -> Result<&'out [u8], UnpadError> {
455+
) -> Result<&'out [u8], block_padding::Error> {
463456
let (mut blocks, tail) = data.into_chunks();
464457
if !tail.is_empty() {
465-
return Err(UnpadError);
458+
return Err(block_padding::Error);
466459
}
467460
self.decrypt_blocks_inout(blocks.reborrow());
468-
P::unpad_blocks(blocks.into_out())
461+
P::unpad_blocks::<Self::BlockSize>(blocks.into_out())
469462
}
470463

471464
/// Decrypt input and unpad it in-place. Returns resulting plaintext slice.
472465
///
473-
/// Returns [`UnpadError`] if padding is malformed or if input length is
466+
/// Returns [`block_padding::Error`] if padding is malformed or if input length is
474467
/// not multiple of `Self::BlockSize`.
475468
#[cfg(feature = "block-padding")]
476469
#[inline]
477-
fn decrypt_padded<P: Padding<Self::BlockSize>>(
478-
self,
479-
buf: &mut [u8],
480-
) -> Result<&[u8], UnpadError> {
470+
fn decrypt_padded<P: Padding>(self, buf: &mut [u8]) -> Result<&[u8], block_padding::Error> {
481471
self.decrypt_padded_inout::<P>(buf.into())
482472
}
483473

484474
/// Decrypt input and unpad it buffer-to-buffer. Returns resulting
485475
/// plaintext slice.
486476
///
487-
/// Returns [`UnpadError`] if padding is malformed or if input length is
477+
/// Returns [`block_padding::Error`] if padding is malformed or if input length is
488478
/// not multiple of `Self::BlockSize`.
489479
#[cfg(feature = "block-padding")]
490480
#[inline]
491-
fn decrypt_padded_b2b<'a, P: Padding<Self::BlockSize>>(
481+
fn decrypt_padded_b2b<'a, P: Padding>(
492482
self,
493483
in_buf: &[u8],
494484
out_buf: &'a mut [u8],
495-
) -> Result<&'a [u8], UnpadError> {
485+
) -> Result<&'a [u8], block_padding::Error> {
496486
if out_buf.len() < in_buf.len() {
497-
return Err(UnpadError);
487+
return Err(block_padding::Error);
498488
}
499489
let n = in_buf.len();
500490
// note: `new` always returns `Ok` here
501-
let buf = InOutBuf::new(in_buf, &mut out_buf[..n]).map_err(|_| UnpadError)?;
491+
let buf = InOutBuf::new(in_buf, &mut out_buf[..n]).map_err(|_| block_padding::Error)?;
502492
self.decrypt_padded_inout::<P>(buf)
503493
}
504494

505495
/// Decrypt input and unpad it in a newly allocated Vec. Returns resulting
506496
/// plaintext `Vec`.
507497
///
508-
/// Returns [`UnpadError`] if padding is malformed or if input length is
498+
/// Returns [`block_padding::Error`] if padding is malformed or if input length is
509499
/// not multiple of `Self::BlockSize`.
510500
#[cfg(all(feature = "block-padding", feature = "alloc"))]
511501
#[inline]
512-
fn decrypt_padded_vec<P: Padding<Self::BlockSize>>(
513-
self,
514-
buf: &[u8],
515-
) -> Result<Vec<u8>, UnpadError> {
502+
fn decrypt_padded_vec<P: Padding>(self, buf: &[u8]) -> Result<Vec<u8>, block_padding::Error> {
516503
let mut out = vec![0; buf.len()];
517504
let len = self.decrypt_padded_b2b::<P>(buf, &mut out)?.len();
518505
out.truncate(len);

0 commit comments

Comments
 (0)