Skip to content

Commit b755f1a

Browse files
authored
Migrate to hybrid-array; MSRV 1.65 (#944)
Migrates the following crates away from using `generic-array` to using `hybrid-array` instead: - `block-buffer` - `block-padding` - `dbl` - `inout`
1 parent b1a613b commit b755f1a

File tree

19 files changed

+151
-169
lines changed

19 files changed

+151
-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: 17 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ members = [
1919

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

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
zeroize = { version = "1.4", optional = true, default-features = false }
1817

1918
[dev-dependencies]

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: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
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};
17+
1818
#[cfg(feature = "zeroize")]
1919
use zeroize::Zeroize;
2020

@@ -24,7 +24,7 @@ mod sealed;
2424
pub use read::ReadBuffer;
2525

2626
/// Block with additional one byte
27-
type BlockP1<BlockSize> = GenericArray<u8, Add1<BlockSize>>;
27+
type BlockP1<BlockSize> = Array<u8, Add1<BlockSize>>;
2828

2929
/// Trait for buffer kinds.
3030
pub trait BufferKind: sealed::Sealed {}
@@ -306,7 +306,7 @@ impl<BS: BlockSizes> BlockBuffer<BS, Lazy> {
306306
pub fn serialize(&self) -> BlockP1<BS>
307307
where
308308
BS: Add<B1>,
309-
Add1<BS>: ArrayLength<u8>,
309+
Add1<BS>: ArraySize,
310310
{
311311
let mut res = BlockP1::<BS>::default();
312312
res[0] = self.pos;
@@ -320,7 +320,7 @@ impl<BS: BlockSizes> BlockBuffer<BS, Lazy> {
320320
pub fn deserialize(buffer: &BlockP1<BS>) -> Result<Self, Error>
321321
where
322322
BS: Add<B1>,
323-
Add1<BS>: ArrayLength<u8>,
323+
Add1<BS>: ArraySize,
324324
{
325325
let pos = buffer[0];
326326
if !<Lazy as sealed::Sealed>::invariant(pos as usize, BS::USIZE) {
@@ -329,10 +329,8 @@ impl<BS: BlockSizes> BlockBuffer<BS, Lazy> {
329329
if buffer[1..][pos as usize..].iter().any(|&b| b != 0) {
330330
return Err(Error);
331331
}
332-
Ok(Self {
333-
buffer: GenericArray::clone_from_slice(&buffer[1..]),
334-
pos,
335-
})
332+
let buffer = Array::clone_from_slice(&buffer[1..]);
333+
Ok(Self { buffer, pos })
336334
}
337335
}
338336

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 {
@@ -17,7 +17,7 @@ pub trait Sealed {
1717
fn invariant(pos: usize, block_size: usize) -> bool;
1818

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

2323
impl Sealed for super::Eager {
@@ -38,14 +38,14 @@ impl Sealed for super::Eager {
3838
}
3939

4040
#[inline(always)]
41-
fn split_blocks<N: ArrayLength<u8>>(data: &[u8]) -> (&[GenericArray<u8, N>], &[u8]) {
41+
fn split_blocks<N: ArraySize>(data: &[u8]) -> (&[Array<u8, N>], &[u8]) {
4242
let nb = data.len() / N::USIZE;
4343
let blocks_len = nb * N::USIZE;
4444
let tail_len = data.len() - blocks_len;
4545
// SAFETY: we guarantee that created slices do not point
4646
// outside of `data`
4747
unsafe {
48-
let blocks_ptr = data.as_ptr() as *const GenericArray<u8, N>;
48+
let blocks_ptr = data.as_ptr() as *const Array<u8, N>;
4949
let tail_ptr = data.as_ptr().add(blocks_len);
5050
(
5151
slice::from_raw_parts(blocks_ptr, nb),
@@ -73,7 +73,7 @@ impl Sealed for super::Lazy {
7373
}
7474

7575
#[inline(always)]
76-
fn split_blocks<N: ArrayLength<u8>>(data: &[u8]) -> (&[GenericArray<u8, N>], &[u8]) {
76+
fn split_blocks<N: ArraySize>(data: &[u8]) -> (&[Array<u8, N>], &[u8]) {
7777
if data.is_empty() {
7878
return (&[], &[]);
7979
}
@@ -87,7 +87,7 @@ impl Sealed for super::Lazy {
8787
// SAFETY: we guarantee that created slices do not point
8888
// outside of `data`
8989
unsafe {
90-
let blocks_ptr = data.as_ptr() as *const GenericArray<u8, N>;
90+
let blocks_ptr = data.as_ptr() as *const Array<u8, N>;
9191
let tail_ptr = data.as_ptr().add(blocks_len);
9292
(
9393
slice::from_raw_parts(blocks_ptr, nb),

0 commit comments

Comments
 (0)