Skip to content

Commit f375f6d

Browse files
authored
Merge pull request #232 from rust-bitcoin/2020-08-modernize
Small modernization after MSRV bump
2 parents 72c8545 + fbcfc5f commit f375f6d

File tree

8 files changed

+26
-90
lines changed

8 files changed

+26
-90
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ script:
6262
- if [ ${TRAVIS_RUST_VERSION} == "stable" -a "$TRAVIS_OS_NAME" = "linux" ]; then
6363
clang --version &&
6464
CARGO_TARGET_DIR=wasm cargo install --verbose --force wasm-pack &&
65-
sed -i 's/\[lib\]/[lib]\ncrate-type = ["cdylib", "rlib"]/' Cargo.toml &&
65+
printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml &&
6666
CC=clang-9 wasm-pack build &&
6767
CC=clang-9 wasm-pack test --node;
6868
fi

Cargo.toml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[package]
2-
32
name = "secp256k1"
43
version = "0.19.0"
54
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
@@ -17,10 +16,6 @@ autoexamples = false # Remove when edition 2018 https://github.com/rust-lang/car
1716
[package.metadata.docs.rs]
1817
features = [ "rand", "rand-std", "serde", "recovery", "endomorphism" ]
1918

20-
[lib]
21-
name = "secp256k1"
22-
path = "src/lib.rs"
23-
2419
[features]
2520
unstable = ["recovery", "rand-std"]
2621
default = ["std"]
@@ -40,6 +35,10 @@ fuzztarget = ["secp256k1-sys/fuzztarget"]
4035

4136
[dependencies]
4237
secp256k1-sys = { version = "0.3.0", default-features = false, path = "./secp256k1-sys" }
38+
bitcoin_hashes = { version = "0.9", optional = true }
39+
rand = { version = "0.6", default-features = false, optional = true }
40+
serde = { version = "1.0", default-features = false, optional = true }
41+
4342

4443
[dev-dependencies]
4544
rand = "0.6"
@@ -51,19 +50,6 @@ bitcoin_hashes = "0.9"
5150
wasm-bindgen-test = "0.3"
5251
rand = { version = "0.6", features = ["wasm-bindgen"] }
5352

54-
[dependencies.bitcoin_hashes]
55-
version = "0.9"
56-
optional = true
57-
58-
[dependencies.rand]
59-
version = "0.6"
60-
optional = true
61-
default-features = false
62-
63-
[dependencies.serde]
64-
version = "1.0"
65-
optional = true
66-
default-features = false
6753

6854
[[example]]
6955
name = "sign_verify_recovery"

secp256k1-sys/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ features = [ "recovery", "endomorphism", "lowmemory" ]
2121
[build-dependencies]
2222
cc = "1.0.28"
2323

24-
[lib]
25-
name = "secp256k1_sys"
26-
path = "src/lib.rs"
27-
2824
[features]
2925
default = ["std"]
3026
recovery = []

secp256k1-sys/src/lib.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@
1616
//! Direct bindings to the underlying C library functions. These should
1717
//! not be needed for most users.
1818
19-
#![crate_type = "lib"]
20-
#![crate_type = "rlib"]
21-
#![crate_type = "dylib"]
22-
#![crate_name = "secp256k1_sys"]
23-
24-
#![cfg_attr(all(not(test), not(fuzztarget), not(feature = "std")), no_std)]
25-
#![cfg_attr(feature = "dev", allow(unstable_features))]
26-
#![cfg_attr(feature = "dev", feature(plugin))]
27-
#![cfg_attr(feature = "dev", plugin(clippy))]
19+
// Coding conventions
20+
#![deny(non_upper_case_globals)]
21+
#![deny(non_camel_case_types)]
22+
#![deny(non_snake_case)]
23+
#![deny(unused_mut)]
2824

25+
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
2926
#[cfg(any(test, feature = "std"))]
3027
extern crate core;
3128

@@ -97,9 +94,6 @@ impl_raw_debug!(PublicKey);
9794
impl PublicKey {
9895
/// Create a new (zeroed) public key usable for the FFI interface
9996
pub fn new() -> PublicKey { PublicKey([0; 64]) }
100-
/// Create a new (uninitialized) public key usable for the FFI interface
101-
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
102-
pub unsafe fn blank() -> PublicKey { PublicKey::new() }
10397
}
10498

10599
impl Default for PublicKey {
@@ -123,9 +117,6 @@ impl_raw_debug!(Signature);
123117
impl Signature {
124118
/// Create a new (zeroed) signature usable for the FFI interface
125119
pub fn new() -> Signature { Signature([0; 64]) }
126-
/// Create a new (uninitialized) signature usable for the FFI interface
127-
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
128-
pub unsafe fn blank() -> Signature { Signature::new() }
129120
}
130121

131122
impl Default for Signature {
@@ -467,7 +458,7 @@ mod fuzz_dummy {
467458
use self::std::{ptr, mem};
468459
use self::std::boxed::Box;
469460
use types::*;
470-
use ::{Signature, Context, NonceFn, EcdhHashFn, PublicKey,
461+
use {Signature, Context, NonceFn, EcdhHashFn, PublicKey,
471462
SECP256K1_START_NONE, SECP256K1_START_VERIFY, SECP256K1_START_SIGN,
472463
SECP256K1_SER_COMPRESSED, SECP256K1_SER_UNCOMPRESSED};
473464

secp256k1-sys/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ macro_rules! impl_array_newtype {
130130
&dat[..]
131131
}
132132
}
133-
impl ::CPtr for $thing {
133+
impl $crate::CPtr for $thing {
134134
type Target = $ty;
135135
fn as_c_ptr(&self) -> *const Self::Target {
136136
if self.is_empty() {

secp256k1-sys/src/recovery.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ impl_raw_debug!(RecoverableSignature);
2828
impl RecoverableSignature {
2929
/// Create a new (zeroed) signature usable for the FFI interface
3030
pub fn new() -> RecoverableSignature { RecoverableSignature([0; 65]) }
31-
/// Create a new (uninitialized) signature usable for the FFI interface
32-
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
33-
pub unsafe fn blank() -> RecoverableSignature { RecoverableSignature::new() }
3431
}
3532

3633
impl Default for RecoverableSignature {

src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use self::std_only::*;
1414
pub mod global {
1515
use std::ops::Deref;
1616
use std::sync::Once;
17-
use ::{Secp256k1, All};
17+
use {Secp256k1, All};
1818

1919
/// Proxy struct for global `SECP256K1` context
2020
pub struct GlobalContext {

src/lib.rs

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,10 @@
3737
//! trigger any assertion failures in the upstream library.
3838
//!
3939
//! ```rust
40-
//! extern crate secp256k1;
41-
//! # #[cfg(feature="bitcoin_hashes")]
42-
//! extern crate bitcoin_hashes;
43-
//! # #[cfg(feature="rand")]
44-
//! extern crate rand;
45-
//!
46-
//! #
47-
//! # fn main() {
4840
//! # #[cfg(all(feature="rand", feature="bitcoin_hashes"))] {
49-
//! use rand::rngs::OsRng;
41+
//! use secp256k1::rand::rngs::OsRng;
5042
//! use secp256k1::{Secp256k1, Message};
51-
//! use bitcoin_hashes::sha256;
43+
//! use secp256k1::bitcoin_hashes::sha256;
5244
//!
5345
//! let secp = Secp256k1::new();
5446
//! let mut rng = OsRng::new().expect("OsRng");
@@ -57,15 +49,14 @@
5749
//!
5850
//! let sig = secp.sign(&message, &secret_key);
5951
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
60-
//! # } }
52+
//! # }
6153
//! ```
6254
//!
6355
//! The above code requires `rust-secp256k1` to be compiled with the `rand` and `bitcoin_hashes`
6456
//! feature enabled, to get access to [`generate_keypair`](struct.Secp256k1.html#method.generate_keypair)
6557
//! Alternately, keys and messages can be parsed from slices, like
6658
//!
6759
//! ```rust
68-
//! # fn main() {
6960
//! use self::secp256k1::{Secp256k1, Message, SecretKey, PublicKey};
7061
//!
7162
//! let secp = Secp256k1::new();
@@ -77,13 +68,11 @@
7768
//!
7869
//! let sig = secp.sign(&message, &secret_key);
7970
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
80-
//! # }
8171
//! ```
8272
//!
8373
//! Users who only want to verify signatures can use a cheaper context, like so:
8474
//!
8575
//! ```rust
86-
//! # fn main() {
8776
//! use secp256k1::{Secp256k1, Message, Signature, PublicKey};
8877
//!
8978
//! let secp = Secp256k1::verification_only();
@@ -115,44 +104,28 @@
115104
//! ]).expect("compact signatures are 64 bytes; DER signatures are 68-72 bytes");
116105
//!
117106
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
118-
//! # }
119107
//! ```
120108
//!
121109
//! Observe that the same code using, say [`signing_only`](struct.Secp256k1.html#method.signing_only)
122110
//! to generate a context would simply not compile.
123111
//!
124112
125-
#![crate_type = "lib"]
126-
#![crate_type = "rlib"]
127-
#![crate_type = "dylib"]
128-
#![crate_name = "secp256k1"]
129-
130113
// Coding conventions
131114
#![deny(non_upper_case_globals)]
132115
#![deny(non_camel_case_types)]
133116
#![deny(non_snake_case)]
134117
#![deny(unused_mut)]
135118
#![warn(missing_docs)]
136119

137-
// In general, rust is absolutely horrid at supporting users doing things like,
138-
// for example, compiling Rust code for real environments. Disable useless lints
139-
// that don't do anything but annoy us and cant actually ever be resolved.
140-
#![allow(bare_trait_objects)]
141-
#![allow(ellipsis_inclusive_range_patterns)]
142120

143-
#![cfg_attr(feature = "dev", allow(unstable_features))]
144-
#![cfg_attr(feature = "dev", feature(plugin))]
145-
#![cfg_attr(feature = "dev", plugin(clippy))]
146-
147-
148-
#![cfg_attr(all(not(test), not(fuzztarget), not(feature = "std")), no_std)]
121+
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
149122
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
150123

151124
#[macro_use]
152125
pub extern crate secp256k1_sys;
153126
pub use secp256k1_sys as ffi;
154127

155-
#[cfg(feature = "bitcoin_hashes")] extern crate bitcoin_hashes;
128+
#[cfg(feature = "bitcoin_hashes")] pub extern crate bitcoin_hashes;
156129
#[cfg(all(test, feature = "unstable"))] extern crate test;
157130
#[cfg(any(test, feature = "rand"))] pub extern crate rand;
158131
#[cfg(any(test))] extern crate rand_core;
@@ -575,9 +548,7 @@ impl fmt::Display for Error {
575548
}
576549

577550
#[cfg(feature = "std")]
578-
impl std::error::Error for Error {
579-
fn description(&self) -> &str { self.as_str() }
580-
}
551+
impl std::error::Error for Error {}
581552

582553

583554
/// The secp256k1 engine, used to execute all signature operations
@@ -676,7 +647,7 @@ impl<C: Context> Secp256k1<C> {
676647
// However, if this DOES fail, the result is potentially weaker side-channel
677648
// resistance, which is deadly and undetectable, so we take out the entire
678649
// thread to be on the safe side.
679-
assert!(err == 1);
650+
assert_eq!(err, 1);
680651
}
681652
}
682653

@@ -723,13 +694,8 @@ impl<C: Verification> Secp256k1<C> {
723694
/// verify-capable context.
724695
///
725696
/// ```rust
726-
/// # extern crate secp256k1;
727-
/// # #[cfg(feature="rand")]
728-
/// # extern crate rand;
729-
/// #
730-
/// # fn main() {
731697
/// # #[cfg(feature="rand")] {
732-
/// # use rand::OsRng;
698+
/// # use secp256k1::rand::rngs::OsRng;
733699
/// # use secp256k1::{Secp256k1, Message, Error};
734700
/// #
735701
/// # let secp = Secp256k1::new();
@@ -742,7 +708,7 @@ impl<C: Verification> Secp256k1<C> {
742708
///
743709
/// let message = Message::from_slice(&[0xcd; 32]).expect("32 bytes");
744710
/// assert_eq!(secp.verify(&message, &sig, &public_key), Err(Error::IncorrectSignature));
745-
/// # } }
711+
/// # }
746712
/// ```
747713
#[inline]
748714
pub fn verify(&self, msg: &Message, sig: &Signature, pk: &key::PublicKey) -> Result<(), Error> {
@@ -769,9 +735,9 @@ fn from_hex(hex: &str, target: &mut [u8]) -> Result<usize, ()> {
769735
for c in hex.bytes() {
770736
b <<= 4;
771737
match c {
772-
b'A'...b'F' => b |= c - b'A' + 10,
773-
b'a'...b'f' => b |= c - b'a' + 10,
774-
b'0'...b'9' => b |= c - b'0',
738+
b'A'..=b'F' => b |= c - b'A' + 10,
739+
b'a'..=b'f' => b |= c - b'a' + 10,
740+
b'0'..=b'9' => b |= c - b'0',
775741
_ => return Err(()),
776742
}
777743
if (idx & 1) == 1 {

0 commit comments

Comments
 (0)