Skip to content

Commit 7362ec1

Browse files
committed
[WIP] Migrate to hybrid-array; MSRV 1.65
Builds on RustCrypto/traits#1319. Migrates the following crates away from using `generic-array` to using `hybrid-array` instead: - `block-buffer` - `block-padding` - `dbl` - `inout`
1 parent eb03093 commit 7362ec1

File tree

19 files changed

+142
-169
lines changed

19 files changed

+142
-169
lines changed

.github/workflows/block-buffer.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
rust:
28-
- 1.56.0 # MSRV
28+
- 1.65.0 # MSRV
2929
- stable
3030
target:
3131
- thumbv7em-none-eabi
@@ -37,29 +37,26 @@ jobs:
3737
with:
3838
toolchain: ${{ matrix.rust }}
3939
targets: ${{ matrix.target }}
40-
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
41-
- run: rm ../Cargo.toml
4240
- run: cargo build --target ${{ matrix.target }}
4341

44-
minimal-versions:
45-
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
46-
with:
47-
working-directory: ${{ github.workflow }}
42+
# TODO(tarcieri): re-enable after next `crypto-common` release
43+
#minimal-versions:
44+
# uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
45+
# with:
46+
# working-directory: ${{ github.workflow }}
4847

4948
test:
5049
runs-on: ubuntu-latest
5150
strategy:
5251
matrix:
5352
rust:
54-
- 1.56.0 # MSRV
53+
- 1.65.0 # MSRV
5554
- stable
5655
steps:
5756
- uses: actions/checkout@v4
5857
- uses: RustCrypto/actions/cargo-cache@master
5958
- uses: dtolnay/rust-toolchain@master
6059
with:
6160
toolchain: ${{ matrix.rust }}
62-
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
63-
- run: rm ../Cargo.toml
6461
- run: cargo test
6562
- run: cargo test --all-features

.github/workflows/block-padding.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
rust:
28-
- 1.56.0 # MSRV
28+
- 1.65.0 # MSRV
2929
- stable
3030
target:
3131
- thumbv7em-none-eabi
@@ -49,7 +49,7 @@ jobs:
4949
strategy:
5050
matrix:
5151
rust:
52-
- 1.56.0 # MSRV
52+
- 1.65.0 # MSRV
5353
- stable
5454
steps:
5555
- uses: actions/checkout@v4

.github/workflows/dbl.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
rust:
28-
- 1.41.0 # MSRV
28+
- 1.65.0 # MSRV
2929
- stable
3030
target:
3131
- thumbv7em-none-eabi
@@ -37,8 +37,6 @@ jobs:
3737
with:
3838
toolchain: ${{ matrix.rust }}
3939
targets: ${{ matrix.target }}
40-
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
41-
- run: rm ../Cargo.toml
4240
- run: cargo build --target ${{ matrix.target }}
4341

4442
minimal-versions:
@@ -51,14 +49,12 @@ jobs:
5149
strategy:
5250
matrix:
5351
rust:
54-
- 1.41.0 # MSRV
52+
- 1.65.0 # MSRV
5553
- stable
5654
steps:
5755
- uses: actions/checkout@v4
5856
- uses: RustCrypto/actions/cargo-cache@master
5957
- uses: dtolnay/rust-toolchain@master
6058
with:
6159
toolchain: ${{ matrix.rust }}
62-
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
63-
- run: rm ../Cargo.toml
6460
- run: cargo test

.github/workflows/inout.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
rust:
28-
- 1.56.0 # MSRV
28+
- 1.65.0 # MSRV
2929
- stable
3030
target:
3131
- thumbv7em-none-eabi
@@ -50,7 +50,7 @@ jobs:
5050
strategy:
5151
matrix:
5252
rust:
53-
- 1.56.0 # MSRV
53+
- 1.65.0 # MSRV
5454
- stable
5555
steps:
5656
- uses: actions/checkout@v4

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ members = [
1919

2020
[profile.dev]
2121
opt-level = 2
22+
23+
[patch.crates-io]
24+
crypto-common = { git = "https://github.com/RustCrypto/traits", branch = "crypto-common/hybrid-array" }
25+
hybrid-array = { path = "hybrid-array" }

block-buffer/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ readme = "README.md"
1313

1414
[dependencies]
1515
crypto-common = "0.2.0-pre"
16-
generic-array = "0.14"
1716

1817
[dev-dependencies]
1918
hex-literal = "0.3.3"

block-buffer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
2929
[docs-image]: https://docs.rs/block-buffer/badge.svg
3030
[docs-link]: https://docs.rs/block-buffer/
3131
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
32-
[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg
32+
[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg
3333
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
3434
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260052-utils
3535
[build-image]: https://github.com/RustCrypto/utils/workflows/block-buffer/badge.svg?branch=master&event=push

block-buffer/src/lib.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@
66
)]
77
#![warn(missing_docs, rust_2018_idioms)]
88

9-
pub use generic_array;
9+
pub use crypto_common::{array, Block};
1010

11-
use core::{fmt, ops::Add, slice};
12-
pub use crypto_common::Block;
13-
use crypto_common::{BlockSizeUser, BlockSizes};
14-
use generic_array::{
11+
use array::{
1512
typenum::{Add1, B1},
16-
ArrayLength, GenericArray,
13+
Array, ArraySize,
1714
};
15+
use core::{fmt, ops::Add, slice};
16+
use crypto_common::{BlockSizeUser, BlockSizes};
1817

1918
mod read;
2019
mod sealed;
2120

2221
pub use read::ReadBuffer;
2322

2423
/// Block with additional one byte
25-
type BlockP1<BlockSize> = GenericArray<u8, Add1<BlockSize>>;
24+
type BlockP1<BlockSize> = Array<u8, Add1<BlockSize>>;
2625

2726
/// Trait for buffer kinds.
2827
pub trait BufferKind: sealed::Sealed {}
@@ -304,7 +303,7 @@ impl<BS: BlockSizes> BlockBuffer<BS, Lazy> {
304303
pub fn serialize(&self) -> BlockP1<BS>
305304
where
306305
BS: Add<B1>,
307-
Add1<BS>: ArrayLength<u8>,
306+
Add1<BS>: ArraySize,
308307
{
309308
let mut res = BlockP1::<BS>::default();
310309
res[0] = self.pos;
@@ -318,7 +317,7 @@ impl<BS: BlockSizes> BlockBuffer<BS, Lazy> {
318317
pub fn deserialize(buffer: &BlockP1<BS>) -> Result<Self, Error>
319318
where
320319
BS: Add<B1>,
321-
Add1<BS>: ArrayLength<u8>,
320+
Add1<BS>: ArraySize,
322321
{
323322
let pos = buffer[0];
324323
if !<Lazy as sealed::Sealed>::invariant(pos as usize, BS::USIZE) {
@@ -327,9 +326,7 @@ impl<BS: BlockSizes> BlockBuffer<BS, Lazy> {
327326
if buffer[1..][pos as usize..].iter().any(|&b| b != 0) {
328327
return Err(Error);
329328
}
330-
Ok(Self {
331-
buffer: GenericArray::clone_from_slice(&buffer[1..]),
332-
pos,
333-
})
329+
let buffer = Array::clone_from_slice(&buffer[1..]);
330+
Ok(Self { buffer, pos })
334331
}
335332
}

block-buffer/src/sealed.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::array::{Array, ArraySize};
12
use core::slice;
2-
use generic_array::{ArrayLength, GenericArray};
33

44
/// Sealed trait for buffer kinds.
55
pub trait Sealed {
@@ -14,7 +14,7 @@ pub trait Sealed {
1414
fn invariant(pos: usize, block_size: usize) -> bool;
1515

1616
/// Split input data into slice of blocks and tail.
17-
fn split_blocks<N: ArrayLength<u8>>(data: &[u8]) -> (&[GenericArray<u8, N>], &[u8]);
17+
fn split_blocks<N: ArraySize>(data: &[u8]) -> (&[Array<u8, N>], &[u8]);
1818
}
1919

2020
impl Sealed for super::Eager {
@@ -35,14 +35,14 @@ impl Sealed for super::Eager {
3535
}
3636

3737
#[inline(always)]
38-
fn split_blocks<N: ArrayLength<u8>>(data: &[u8]) -> (&[GenericArray<u8, N>], &[u8]) {
38+
fn split_blocks<N: ArraySize>(data: &[u8]) -> (&[Array<u8, N>], &[u8]) {
3939
let nb = data.len() / N::USIZE;
4040
let blocks_len = nb * N::USIZE;
4141
let tail_len = data.len() - blocks_len;
4242
// SAFETY: we guarantee that created slices do not point
4343
// outside of `data`
4444
unsafe {
45-
let blocks_ptr = data.as_ptr() as *const GenericArray<u8, N>;
45+
let blocks_ptr = data.as_ptr() as *const Array<u8, N>;
4646
let tail_ptr = data.as_ptr().add(blocks_len);
4747
(
4848
slice::from_raw_parts(blocks_ptr, nb),
@@ -70,7 +70,7 @@ impl Sealed for super::Lazy {
7070
}
7171

7272
#[inline(always)]
73-
fn split_blocks<N: ArrayLength<u8>>(data: &[u8]) -> (&[GenericArray<u8, N>], &[u8]) {
73+
fn split_blocks<N: ArraySize>(data: &[u8]) -> (&[Array<u8, N>], &[u8]) {
7474
if data.is_empty() {
7575
return (&[], &[]);
7676
}
@@ -84,7 +84,7 @@ impl Sealed for super::Lazy {
8484
// SAFETY: we guarantee that created slices do not point
8585
// outside of `data`
8686
unsafe {
87-
let blocks_ptr = data.as_ptr() as *const GenericArray<u8, N>;
87+
let blocks_ptr = data.as_ptr() as *const Array<u8, N>;
8888
let tail_ptr = data.as_ptr().add(blocks_len);
8989
(
9090
slice::from_raw_parts(blocks_ptr, nb),

0 commit comments

Comments
 (0)