Skip to content

Commit b09b87b

Browse files
committed
sha2: 2018 edition and digest crate upgrade
Upgrades to Rust 2018 edition and the (now 2018 edition) `digest` v0.9.0-pre crate.
1 parent b4e9edd commit b09b87b

File tree

12 files changed

+47
-54
lines changed

12 files changed

+47
-54
lines changed

sha2/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ including SHA-224, SHA-256, SHA-384, and SHA-512.
88
authors = ["RustCrypto Developers"]
99
license = "MIT OR Apache-2.0"
1010
readme = "README.md"
11+
edition = "2018"
1112
documentation = "https://docs.rs/sha2"
1213
repository = "https://github.com/RustCrypto/hashes"
1314
keywords = ["crypto", "sha2", "hash", "digest"]
1415
categories = ["cryptography", "no-std"]
1516

1617
[dependencies]
17-
digest = "0.8"
18-
block-buffer = "0.7"
18+
digest = { version = "0.9.0-pre", git = "https://github.com/RustCrypto/traits" }
19+
block-buffer = { version = "0.7", git = "https://github.com/RustCrypto/utils" }
1920
fake-simd = "0.1"
2021
opaque-debug = "0.2"
2122
sha2-asm = { version = "0.5", optional = true }
2223
libc = { version = "0.2.68", optional = true }
2324

2425
[dev-dependencies]
25-
digest = { version = "0.8", features = ["dev"] }
26+
digest = { version = "0.9.0-pre", features = ["dev"], git = "https://github.com/RustCrypto/traits" }
2627
hex-literal = "0.1"
2728

2829
[features]

sha2/benches/sha256.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![no_std]
22
#![feature(test)]
3-
#[macro_use]
4-
extern crate digest;
5-
extern crate sha2;
63

4+
use digest::bench;
75
bench!(sha2::Sha256);

sha2/benches/sha512.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![no_std]
22
#![feature(test)]
3-
#[macro_use]
4-
extern crate digest;
5-
extern crate sha2;
63

4+
use digest::bench;
75
bench!(sha2::Sha512);

sha2/examples/sha256sum.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate sha2;
2-
31
use sha2::{Digest, Sha256};
42
use std::env;
53
use std::fs;
@@ -25,7 +23,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2523
Ok(n) => n,
2624
Err(_) => return,
2725
};
28-
sh.input(&buffer[..n]);
26+
sh.update(&buffer[..n]);
2927
if n == 0 || n < BUFFER_SIZE {
3028
break;
3129
}

sha2/examples/sha512sum.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate sha2;
2-
31
use sha2::{Digest, Sha512};
42
use std::env;
53
use std::fs;
@@ -25,7 +23,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2523
Ok(n) => n,
2624
Err(_) => return,
2725
};
28-
sh.input(&buffer[..n]);
26+
sh.update(&buffer[..n]);
2927
if n == 0 || n < BUFFER_SIZE {
3028
break;
3129
}

sha2/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![allow(dead_code)]
22
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
33

4-
use simd::u32x4;
5-
use simd::u64x2;
4+
use crate::simd::u32x4;
5+
use crate::simd::u64x2;
66

77
pub const STATE_LEN: usize = 8;
88
pub const BLOCK_LEN: usize = 16;

sha2/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
//! let mut hasher = Sha256::new();
3030
//!
3131
//! // write input message
32-
//! hasher.input(b"hello world");
32+
//! hasher.update(b"hello world");
3333
//!
3434
//! // read hash digest and consume hasher
3535
//! let result = hasher.result();
@@ -40,7 +40,7 @@
4040
//!
4141
//! // same for Sha512
4242
//! let mut hasher = Sha512::new();
43-
//! hasher.input(b"hello world");
43+
//! hasher.update(b"hello world");
4444
//! let result = hasher.result();
4545
//!
4646
//! assert_eq!(result[..], hex!("
@@ -57,6 +57,7 @@
5757
5858
#![no_std]
5959
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
60+
#![warn(missing_docs, rust_2018_idioms)]
6061

6162
// Give relevant error messages if the user tries to enable AArch64 asm on unsupported platforms.
6263
#[cfg(all(
@@ -82,7 +83,6 @@ compile_error!("Enable the \"asm\" feature instead of \"asm-aarch64\" when build
8283
))]
8384
compile_error!("Enable the \"asm-aarch64\" feature on AArch64 if you want to use asm detected at runtime, or build with the crypto extensions support, for instance with RUSTFLAGS='-C target-cpu=native' on a compatible CPU.");
8485

85-
extern crate block_buffer;
8686
extern crate fake_simd as simd;
8787
#[macro_use]
8888
extern crate opaque_debug;
@@ -105,10 +105,10 @@ mod sha512;
105105
#[cfg(any(not(feature = "asm"), target_arch = "aarch64", feature = "compress"))]
106106
mod sha512_utils;
107107

108+
pub use crate::sha256::{Sha224, Sha256};
109+
pub use crate::sha512::{Sha384, Sha512, Sha512Trunc224, Sha512Trunc256};
108110
pub use digest::Digest;
109-
pub use sha256::{Sha224, Sha256};
110111
#[cfg(feature = "compress")]
111112
pub use sha256_utils::compress256;
112-
pub use sha512::{Sha384, Sha512, Sha512Trunc224, Sha512Trunc256};
113113
#[cfg(feature = "compress")]
114114
pub use sha512_utils::compress512;

sha2/src/sha256.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use block_buffer::byteorder::{ByteOrder, BE};
22
use block_buffer::BlockBuffer;
33
use digest::generic_array::typenum::{U28, U32, U64};
44
use digest::generic_array::GenericArray;
5-
use digest::{BlockInput, FixedOutput, Input, Reset};
5+
use digest::{BlockInput, FixedOutput, Update, Reset};
66

7-
use consts::{H224, H256, STATE_LEN};
7+
use crate::consts::{H224, H256, STATE_LEN};
88

99
#[cfg(not(feature = "asm"))]
10-
use sha256_utils::compress256;
10+
use crate::sha256_utils::compress256;
1111
#[cfg(feature = "asm")]
1212
use sha2_asm::compress256;
1313

@@ -64,7 +64,7 @@ impl Engine256 {
6464
}
6565
}
6666

67-
fn input(&mut self, input: &[u8]) {
67+
fn update(&mut self, input: &[u8]) {
6868
// Assumes that input.len() can be converted to u64 without overflow
6969
self.len += (input.len() as u64) << 3;
7070
let self_state = &mut self.state;
@@ -104,9 +104,9 @@ impl BlockInput for Sha256 {
104104
type BlockSize = BlockSize;
105105
}
106106

107-
impl Input for Sha256 {
108-
fn input<B: AsRef<[u8]>>(&mut self, input: B) {
109-
self.engine.input(input.as_ref());
107+
impl Update for Sha256 {
108+
fn update(&mut self, input: impl AsRef<[u8]>) {
109+
self.engine.update(input.as_ref());
110110
}
111111
}
112112

@@ -146,9 +146,9 @@ impl BlockInput for Sha224 {
146146
type BlockSize = BlockSize;
147147
}
148148

149-
impl Input for Sha224 {
150-
fn input<B: AsRef<[u8]>>(&mut self, input: B) {
151-
self.engine.input(input.as_ref());
149+
impl Update for Sha224 {
150+
fn update(&mut self, input: impl AsRef<[u8]>) {
151+
self.engine.update(input.as_ref());
152152
}
153153
}
154154

sha2/src/sha256_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![cfg_attr(feature = "cargo-clippy", allow(clippy::many_single_char_names))]
22

3+
use crate::consts::{BLOCK_LEN, K32X4};
4+
use crate::simd::u32x4;
35
use block_buffer::byteorder::{ByteOrder, BE};
4-
use consts::{BLOCK_LEN, K32X4};
5-
use simd::u32x4;
66

77
/// Not an intrinsic, but works like an unaligned load.
88
#[inline]

sha2/src/sha512.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use block_buffer::byteorder::{ByteOrder, BE};
22
use block_buffer::BlockBuffer;
33
use digest::generic_array::typenum::{U128, U28, U32, U48, U64};
44
use digest::generic_array::GenericArray;
5-
use digest::{BlockInput, FixedOutput, Input, Reset};
5+
use digest::{BlockInput, FixedOutput, Update, Reset};
66

7-
use consts::{H384, H512, H512_TRUNC_224, H512_TRUNC_256, STATE_LEN};
7+
use crate::consts::{H384, H512, H512_TRUNC_224, H512_TRUNC_256, STATE_LEN};
88

9+
#[cfg(any(not(feature = "asm"), target_arch = "aarch64"))]
10+
use crate::sha512_utils::compress512;
911
#[cfg(all(feature = "asm", not(target_arch = "aarch64")))]
1012
use sha2_asm::compress512;
11-
#[cfg(any(not(feature = "asm"), target_arch = "aarch64"))]
12-
use sha512_utils::compress512;
1313

1414
type BlockSize = U128;
1515
type Block = GenericArray<u8, BlockSize>;
@@ -50,7 +50,7 @@ impl Engine512 {
5050
}
5151
}
5252

53-
fn input(&mut self, input: &[u8]) {
53+
fn update(&mut self, input: &[u8]) {
5454
let (res, over) = self.len.1.overflowing_add((input.len() as u64) << 3);
5555
self.len.1 = res;
5656
if over {
@@ -92,9 +92,9 @@ impl BlockInput for Sha512 {
9292
type BlockSize = BlockSize;
9393
}
9494

95-
impl Input for Sha512 {
96-
fn input<B: AsRef<[u8]>>(&mut self, input: B) {
97-
self.engine.input(input.as_ref());
95+
impl Update for Sha512 {
96+
fn update(&mut self, input: impl AsRef<[u8]>) {
97+
self.engine.update(input.as_ref());
9898
}
9999
}
100100

@@ -135,9 +135,9 @@ impl BlockInput for Sha384 {
135135
type BlockSize = BlockSize;
136136
}
137137

138-
impl Input for Sha384 {
139-
fn input<B: AsRef<[u8]>>(&mut self, input: B) {
140-
self.engine.input(input.as_ref());
138+
impl Update for Sha384 {
139+
fn update(&mut self, input: impl AsRef<[u8]>) {
140+
self.engine.update(input.as_ref());
141141
}
142142
}
143143

@@ -178,9 +178,9 @@ impl BlockInput for Sha512Trunc256 {
178178
type BlockSize = BlockSize;
179179
}
180180

181-
impl Input for Sha512Trunc256 {
182-
fn input<B: AsRef<[u8]>>(&mut self, input: B) {
183-
self.engine.input(input.as_ref());
181+
impl Update for Sha512Trunc256 {
182+
fn update(&mut self, input: impl AsRef<[u8]>) {
183+
self.engine.update(input.as_ref());
184184
}
185185
}
186186

@@ -221,9 +221,9 @@ impl BlockInput for Sha512Trunc224 {
221221
type BlockSize = BlockSize;
222222
}
223223

224-
impl Input for Sha512Trunc224 {
225-
fn input<B: AsRef<[u8]>>(&mut self, input: B) {
226-
self.engine.input(input.as_ref());
224+
impl Update for Sha512Trunc224 {
225+
fn update(&mut self, input: impl AsRef<[u8]>) {
226+
self.engine.update(input.as_ref());
227227
}
228228
}
229229

sha2/src/sha512_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![cfg_attr(feature = "cargo-clippy", allow(clippy::many_single_char_names))]
22

3+
use crate::consts::{BLOCK_LEN, K64X2};
4+
use crate::simd::u64x2;
35
use block_buffer::byteorder::{ByteOrder, BE};
4-
use consts::{BLOCK_LEN, K64X2};
5-
use simd::u64x2;
66

77
/// Not an intrinsic, but works like an unaligned load.
88
#[inline]

sha2/tests/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![no_std]
22
#[macro_use]
33
extern crate digest;
4-
extern crate sha2;
4+
use sha2;
55

66
use digest::dev::{digest_test, one_million_a};
77

0 commit comments

Comments
 (0)