Skip to content

Commit 74db581

Browse files
authored
crypto-common: move ParBlocks* from cipher crate (#1052)
Moves `ParBlocks`/`ParBlocksSizeUser` from the `cipher` crate so it can be reused in the `universal-hash` crate (see #965, #1051). The `cipher` crate re-exports them in an API-compatible way, so this is not a breaking change.
1 parent ea33e32 commit 74db581

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

cipher/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,11 @@ pub use crypto_common::{
5151
generic_array,
5252
typenum::{self, consts},
5353
AlgorithmName, Block, InnerIvInit, InvalidLength, Iv, IvSizeUser, Key, KeyInit, KeyIvInit,
54-
KeySizeUser,
54+
KeySizeUser, ParBlocks, ParBlocksSizeUser,
5555
};
56-
use generic_array::{ArrayLength, GenericArray};
5756

5857
/// Trait for loading current IV state.
5958
pub trait IvState: IvSizeUser {
6059
/// Returns current IV state.
6160
fn iv_state(&self) -> Iv<Self>;
6261
}
63-
64-
/// Types which process blocks in parallel.
65-
pub trait ParBlocksSizeUser: BlockSizeUser {
66-
/// Number of blocks which can be processed in parallel.
67-
type ParBlocksSize: ArrayLength<Block<Self>>;
68-
}
69-
70-
/// Parallel blocks on which [`ParBlocksSizeUser`] implementors operate.
71-
pub type ParBlocks<T> = GenericArray<Block<T>, <T as ParBlocksSizeUser>::ParBlocksSize>;

crypto-common/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ use rand_core::{CryptoRng, RngCore};
2525

2626
/// Block on which [`BlockSizeUser`] implementors operate.
2727
pub type Block<B> = GenericArray<u8, <B as BlockSizeUser>::BlockSize>;
28+
29+
/// Parallel blocks on which [`ParBlocksSizeUser`] implementors operate.
30+
pub type ParBlocks<T> = GenericArray<Block<T>, <T as ParBlocksSizeUser>::ParBlocksSize>;
31+
2832
/// Output array of [`OutputSizeUser`] implementors.
2933
pub type Output<T> = GenericArray<u8, <T as OutputSizeUser>::OutputSize>;
34+
3035
/// Key used by [`KeySizeUser`] implementors.
3136
pub type Key<B> = GenericArray<u8, <B as KeySizeUser>::KeySize>;
37+
3238
/// Initialization vector (nonce) used by [`IvSizeUser`] implementors.
3339
pub type Iv<B> = GenericArray<u8, <B as IvSizeUser>::IvSize>;
3440

@@ -51,6 +57,12 @@ impl<T: BlockSizeUser> BlockSizeUser for &mut T {
5157
type BlockSize = T::BlockSize;
5258
}
5359

60+
/// Types which can process blocks in parallel.
61+
pub trait ParBlocksSizeUser: BlockSizeUser {
62+
/// Number of blocks which can be processed in parallel.
63+
type ParBlocksSize: ArrayLength<Block<Self>>;
64+
}
65+
5466
/// Types which return data with the given size.
5567
pub trait OutputSizeUser {
5668
/// Size of the output in bytes.

0 commit comments

Comments
 (0)