Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 9887c4e

Browse files
committed
Merge #136: Enable edition 2018
abb7c80 Bump version 0.10.0 -> 0.11.0 (Tobin Harding) b270023 Update to use edition 2018 (Tobin Harding) e762962 Update MSRV in CI and Readme from 1.29 to 1.41.1 (Tobin Harding) 3602c75 Remove trailing whitespace (Tobin Harding) Pull request description: Update the MSRV to Rustn 1.41.1 and enable edition 2018. Should not be merged without rust-bitcoin organization-wide planning on how to go about this upgrade. Discussion: rust-bitcoin/rust-bitcoin#510 (comment) This one is a bit more involved than the same PRs for [rust-bech32](rust-bitcoin/rust-bech32#57) or [rust-bitcoinconcensus](rust-bitcoin/rust-bitcoinconsensus#34). The commit message of patch 3: ``` Update to use edition 2018 Add `edition = "2018"` to the minifest file. In order to get the codebase to build cleanly do: - Remove usage of `use Hash as HashTrait`, instead use `impl crate::Hash for Hash` and `use Hash as _`. - Same for HashEngine (remove EngineTrait). - Add `crate::` to import statements and group same level (only did this for crate imports, the rest can wait for rustfmt :) - Make test imports uniform, elect to _not_ use `super::*` because it seems cleaner, we are always importing the module we are testing and the same set of traits in each `test` module. Can change if requested. ``` Thanks ACKs for top commit: apoelstra: ACK abb7c80 Tree-SHA512: 6e99235075a12a82bc2bb032411eb7d022c650e5288bd1a2891b3d863e093ad9398525c1fba41d5e3fdcb194fcf93b00c6f59ad7681f5404eaeae73f08af2278
2 parents 9b124ca + abb7c80 commit 9887c4e

File tree

18 files changed

+133
-182
lines changed

18 files changed

+133
-182
lines changed

.github/workflows/rust.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
on: [push, pull_request]
23

34
name: Continuous integration
@@ -11,7 +12,7 @@ jobs:
1112
rust:
1213
- nightly
1314
steps:
14-
- name: Checkout Crate
15+
- name: Checkout Crate
1516
uses: actions/checkout@v2
1617
- name: Checkout Toolchain
1718
uses: actions-rs/toolchain@v1
@@ -60,7 +61,7 @@ jobs:
6061
strategy:
6162
matrix:
6263
rust:
63-
- 1.29.0
64+
- 1.41.1
6465
- beta
6566
- stable
6667
steps:
@@ -72,14 +73,11 @@ jobs:
7273
profile: minimal
7374
toolchain: ${{ matrix.rust }}
7475
override: true
75-
- name: Pin cc if rust 1.29
76-
if: matrix.rust == '1.29.0'
77-
run: cargo generate-lockfile && cargo update -p serde_json --precise "1.0.39"
7876
- name: Running cargo
7977
env:
8078
DO_FEATURE_MATRIX: true
81-
DO_SCHEMARS_TESTS: ${{matrix.rust != '1.29.0'}}
82-
DO_ALLOC_TESTS: ${{matrix.rust != '1.29.0'}}
79+
DO_SCHEMARS_TESTS: true
80+
DO_ALLOC_TESTS: true
8381
run: ./contrib/test.sh
8482

8583
Embedded:

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bitcoin_hashes"
3-
version = "0.10.0"
3+
version = "0.11.0"
44
authors = ["Andrew Poelstra <[email protected]>"]
55
license = "CC0-1.0"
66
description = "Hash functions used by rust-bitcoin which support rustc 1.29.0"
@@ -9,6 +9,7 @@ repository = "https://github.com/rust-bitcoin/bitcoin_hashes/"
99
documentation = "https://docs.rs/bitcoin_hashes/"
1010
keywords = [ "crypto", "bitcoin", "hash", "digest" ]
1111
readme = "README.md"
12+
edition = "2018"
1213

1314
[lib]
1415
name = "bitcoin_hashes"

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ since these are needed to display hashes anway.
1111

1212
## Minimum Supported Rust Version (MSRV)
1313

14-
This library should always compile with any combination of features on **Rust 1.29**.
15-
However, due to some dependencies breaking their MSRV in patch releases, you may
16-
need to pin these deps explicitly, e.g. with the following commands
17-
18-
```
19-
cargo generate-lockfile
20-
cargo update -p serde_json --precise "1.0.39"
21-
```
14+
This library should always compile with any combination of features on **Rust 1.41.1**.
2215

2316
## Contributions
2417

src/cmp.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ fn eq_test() {
8383
mod benches {
8484
use test::Bencher;
8585

86-
use sha256;
87-
use sha512;
88-
use Hash;
89-
use cmp::fixed_time_eq;
86+
use crate::{Hash, sha256, sha512};
87+
use crate::cmp::fixed_time_eq;
9088

9189
#[bench]
9290
fn bench_32b_constant_time_cmp_ne(bh: &mut Bencher) {

src/hash160.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ use core::str;
2424
use core::ops::Index;
2525
use core::slice::SliceIndex;
2626

27-
use sha256;
28-
use ripemd160;
29-
use Hash as HashTrait;
30-
use Error;
27+
use crate::{Error, hex, ripemd160, sha256};
3128

3229
/// Output of the Bitcoin HASH160 hash function.
3330
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
@@ -54,13 +51,13 @@ impl<I: SliceIndex<[u8]>> Index<I> for Hash {
5451
}
5552

5653
impl str::FromStr for Hash {
57-
type Err = ::hex::Error;
54+
type Err = hex::Error;
5855
fn from_str(s: &str) -> Result<Self, Self::Err> {
59-
::hex::FromHex::from_hex(s)
56+
hex::FromHex::from_hex(s)
6057
}
6158
}
6259

63-
impl HashTrait for Hash {
60+
impl crate::Hash for Hash {
6461
type Engine = sha256::HashEngine;
6562
type Inner = [u8; 20];
6663

@@ -107,8 +104,8 @@ mod tests {
107104
#[test]
108105
#[cfg(any(feature = "std", feature = "alloc"))]
109106
fn test() {
110-
use {hash160, Hash, HashEngine};
111-
use hex::{FromHex, ToHex};
107+
use crate::{hash160, Hash, HashEngine};
108+
use crate::hex::{FromHex, ToHex};
112109

113110
#[derive(Clone)]
114111
#[cfg(any(feature = "std", feature = "alloc"))]
@@ -162,7 +159,7 @@ mod tests {
162159
#[test]
163160
fn ripemd_serde() {
164161
use serde_test::{Configure, Token, assert_tokens};
165-
use {hash160, Hash};
162+
use crate::{hash160, Hash};
166163

167164
static HASH_BYTES: [u8; 20] = [
168165
0x13, 0x20, 0x72, 0xdf,
@@ -182,9 +179,7 @@ mod tests {
182179
mod benches {
183180
use test::Bencher;
184181

185-
use hash160;
186-
use Hash;
187-
use HashEngine;
182+
use crate::{Hash, HashEngine, hash160};
188183

189184
#[bench]
190185
pub fn hash160_10(bh: &mut Bencher) {

src/hex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
//!
1717
1818
#[cfg(any(feature = "std", feature = "alloc"))]
19-
use alloc::{string::String, vec::Vec};
19+
use crate::alloc::{string::String, vec::Vec};
2020
#[cfg(feature = "alloc")]
21-
use alloc::format;
21+
use crate::alloc::format;
2222

2323
#[cfg(feature = "std")]
2424
use std::io;
2525
#[cfg(all(not(feature = "std"), feature = "core2"))]
2626
use core2::io;
2727

2828
use core::{fmt, str};
29-
use Hash;
29+
use crate::Hash;
3030

3131
/// Hex decoding error.
3232
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]

src/hmac.rs

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,44 @@ use core::{borrow, fmt, ops, str};
2424
#[cfg(feature = "serde")]
2525
use serde::{Serialize, Serializer, Deserialize, Deserializer};
2626

27-
use HashEngine as EngineTrait;
28-
use Hash as HashTrait;
29-
use Error;
27+
use crate::{Error, Hash, HashEngine};
3028

3129
/// A hash computed from a RFC 2104 HMAC. Parameterized by the underlying hash function.
3230
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
3331
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3432
#[cfg_attr(feature = "schemars", schemars(transparent))]
3533
#[repr(transparent)]
36-
pub struct Hmac<T: HashTrait>(T);
34+
pub struct Hmac<T: Hash>(T);
3735

38-
impl<T: HashTrait + str::FromStr> str::FromStr for Hmac<T> {
36+
impl<T: Hash + str::FromStr> str::FromStr for Hmac<T> {
3937
type Err = <T as str::FromStr>::Err;
4038
fn from_str(s: &str) -> Result<Self, Self::Err> {
4139
Ok(Hmac(str::FromStr::from_str(s)?))
4240
}
4341
}
4442

4543
/// Pair of underlying hash midstates which represent the current state of an `HmacEngine`.
46-
pub struct HmacMidState<T: HashTrait> {
44+
pub struct HmacMidState<T: Hash> {
4745
/// Midstate of the inner hash engine
48-
pub inner: <T::Engine as EngineTrait>::MidState,
46+
pub inner: <T::Engine as HashEngine>::MidState,
4947
/// Midstate of the outer hash engine
50-
pub outer: <T::Engine as EngineTrait>::MidState,
48+
pub outer: <T::Engine as HashEngine>::MidState,
5149
}
5250

5351
/// Pair of underyling hash engines, used for the inner and outer hash of HMAC.
5452
#[derive(Clone)]
55-
pub struct HmacEngine<T: HashTrait> {
53+
pub struct HmacEngine<T: Hash> {
5654
iengine: T::Engine,
5755
oengine: T::Engine,
5856
}
5957

60-
impl<T: HashTrait> Default for HmacEngine<T> {
58+
impl<T: Hash> Default for HmacEngine<T> {
6159
fn default() -> Self {
6260
HmacEngine::new(&[])
6361
}
6462
}
6563

66-
impl<T: HashTrait> HmacEngine<T> {
64+
impl<T: Hash> HmacEngine<T> {
6765
/// Constructs a new keyed HMAC from `key`.
6866
///
6967
/// We only support underlying hashes whose block sizes are ≤ 128 bytes.
@@ -77,12 +75,12 @@ impl<T: HashTrait> HmacEngine<T> {
7775
let mut ipad = [0x36u8; 128];
7876
let mut opad = [0x5cu8; 128];
7977
let mut ret = HmacEngine {
80-
iengine: <T as HashTrait>::engine(),
81-
oengine: <T as HashTrait>::engine(),
78+
iengine: <T as Hash>::engine(),
79+
oengine: <T as Hash>::engine(),
8280
};
8381

8482
if key.len() > T::Engine::BLOCK_SIZE {
85-
let hash = <T as HashTrait>::hash(key);
83+
let hash = <T as Hash>::hash(key);
8684
for (b_i, b_h) in ipad.iter_mut().zip(&hash[..]) {
8785
*b_i ^= *b_h;
8886
}
@@ -98,8 +96,8 @@ impl<T: HashTrait> HmacEngine<T> {
9896
}
9997
};
10098

101-
EngineTrait::input(&mut ret.iengine, &ipad[..T::Engine::BLOCK_SIZE]);
102-
EngineTrait::input(&mut ret.oengine, &opad[..T::Engine::BLOCK_SIZE]);
99+
HashEngine::input(&mut ret.iengine, &ipad[..T::Engine::BLOCK_SIZE]);
100+
HashEngine::input(&mut ret.oengine, &opad[..T::Engine::BLOCK_SIZE]);
103101
ret
104102
}
105103

@@ -112,7 +110,7 @@ impl<T: HashTrait> HmacEngine<T> {
112110
}
113111
}
114112

115-
impl<T: HashTrait> EngineTrait for HmacEngine<T> {
113+
impl<T: Hash> HashEngine for HmacEngine<T> {
116114
type MidState = HmacMidState<T>;
117115

118116
fn midstate(&self) -> Self::MidState {
@@ -133,66 +131,66 @@ impl<T: HashTrait> EngineTrait for HmacEngine<T> {
133131
}
134132
}
135133

136-
impl<T: HashTrait> fmt::Debug for Hmac<T> {
134+
impl<T: Hash> fmt::Debug for Hmac<T> {
137135
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
138136
fmt::Debug::fmt(&self.0, f)
139137
}
140138
}
141139

142-
impl<T: HashTrait> fmt::Display for Hmac<T> {
140+
impl<T: Hash> fmt::Display for Hmac<T> {
143141
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
144142
fmt::Display::fmt(&self.0, f)
145143
}
146144
}
147145

148-
impl<T: HashTrait> fmt::LowerHex for Hmac<T> {
146+
impl<T: Hash> fmt::LowerHex for Hmac<T> {
149147
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
150148
fmt::LowerHex::fmt(&self.0, f)
151149
}
152150
}
153151

154-
impl<T: HashTrait> ops::Index<usize> for Hmac<T> {
152+
impl<T: Hash> ops::Index<usize> for Hmac<T> {
155153
type Output = u8;
156154
fn index(&self, index: usize) -> &u8 {
157155
&self.0[index]
158156
}
159157
}
160158

161-
impl<T: HashTrait> ops::Index<ops::Range<usize>> for Hmac<T> {
159+
impl<T: Hash> ops::Index<ops::Range<usize>> for Hmac<T> {
162160
type Output = [u8];
163161
fn index(&self, index: ops::Range<usize>) -> &[u8] {
164162
&self.0[index]
165163
}
166164
}
167165

168-
impl<T: HashTrait> ops::Index<ops::RangeFrom<usize>> for Hmac<T> {
166+
impl<T: Hash> ops::Index<ops::RangeFrom<usize>> for Hmac<T> {
169167
type Output = [u8];
170168
fn index(&self, index: ops::RangeFrom<usize>) -> &[u8] {
171169
&self.0[index]
172170
}
173171
}
174172

175-
impl<T: HashTrait> ops::Index<ops::RangeTo<usize>> for Hmac<T> {
173+
impl<T: Hash> ops::Index<ops::RangeTo<usize>> for Hmac<T> {
176174
type Output = [u8];
177175
fn index(&self, index: ops::RangeTo<usize>) -> &[u8] {
178176
&self.0[index]
179177
}
180178
}
181179

182-
impl<T: HashTrait> ops::Index<ops::RangeFull> for Hmac<T> {
180+
impl<T: Hash> ops::Index<ops::RangeFull> for Hmac<T> {
183181
type Output = [u8];
184182
fn index(&self, index: ops::RangeFull) -> &[u8] {
185183
&self.0[index]
186184
}
187185
}
188186

189-
impl<T: HashTrait> borrow::Borrow<[u8]> for Hmac<T> {
187+
impl<T: Hash> borrow::Borrow<[u8]> for Hmac<T> {
190188
fn borrow(&self) -> &[u8] {
191189
&self[..]
192190
}
193191
}
194192

195-
impl<T: HashTrait> HashTrait for Hmac<T> {
193+
impl<T: Hash> Hash for Hmac<T> {
196194
type Engine = HmacEngine<T>;
197195
type Inner = T::Inner;
198196

@@ -224,15 +222,15 @@ impl<T: HashTrait> HashTrait for Hmac<T> {
224222

225223
#[cfg(feature = "serde")]
226224
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
227-
impl<T: HashTrait + Serialize> Serialize for Hmac<T> {
225+
impl<T: Hash + Serialize> Serialize for Hmac<T> {
228226
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
229227
Serialize::serialize(&self.0, s)
230228
}
231229
}
232230

233231
#[cfg(feature = "serde")]
234232
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
235-
impl<'de, T: HashTrait + Deserialize<'de>> Deserialize<'de> for Hmac<T> {
233+
impl<'de, T: Hash + Deserialize<'de>> Deserialize<'de> for Hmac<T> {
236234
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Hmac<T>, D::Error> {
237235
let inner = Deserialize::deserialize(d)?;
238236
Ok(Hmac(inner))
@@ -244,7 +242,7 @@ mod tests {
244242
#[test]
245243
#[cfg(any(feature = "std", feature = "alloc"))]
246244
fn test() {
247-
use {sha256, HashEngine, HmacEngine, Hash, Hmac};
245+
use crate::{sha256, HashEngine, HmacEngine, Hash, Hmac};
248246

249247
#[derive(Clone)]
250248
struct Test {
@@ -370,7 +368,7 @@ mod tests {
370368
#[test]
371369
fn hmac_sha512_serde() {
372370
use serde_test::{Configure, Token, assert_tokens};
373-
use {sha512, Hash, Hmac};
371+
use crate::{sha512, Hash, Hmac};
374372

375373
static HASH_BYTES: [u8; 64] = [
376374
0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21,
@@ -399,8 +397,7 @@ mod tests {
399397
mod benches {
400398
use test::Bencher;
401399

402-
use sha256;
403-
use {Hmac, Hash, HashEngine};
400+
use crate::{Hmac, Hash, HashEngine, sha256};
404401

405402
#[bench]
406403
pub fn hmac_sha256_10(bh: &mut Bencher) {

0 commit comments

Comments
 (0)