Skip to content

Commit 4f7f138

Browse files
committed
Merge #331: Update the code to edition 2018, and update dependencies
5d2f1ce Fix WASM build (Elichai Turkel) 39aaac6 Use new trait TryFrom and do small refactoring (Elichai Turkel) 7d3a149 Move more things from the std feature to the alloc feature (Elichai Turkel) bc8c713 Replace c_void with core::ffi::c_void (Elichai Turkel) 26a52bc Update secp256k1-sys to edition 2018 and fix imports (Elichai Turkel) ebe46a4 Update rand to 0.8 and replace CounterRng with mock::StepRng (Elichai Turkel) 626835f Update secp256k1 to edition 2018 and fix imports (Elichai Turkel) 67c0922 Update MSRV in CI and Readme from 1.29 to 1.41 (Elichai Turkel) Pull request description: As proposed in rust-bitcoin/rust-bitcoin#510 (comment) this PR raises the MSRV to 1.41.1 it also changes the code to be Edition 2018. The PR contains a few things: * Moving to edition 2018 and fixing the imports * Sorting and combining imports to make them more concise * Replacing our c_void with `core::ffi::c_void` * Bumping the `rand` version to latest and modifying our `RngCore` implementations accordingly * Doing some small refactoring and using the new `TryInto` trait where it makes the code nicer If people prefer I can split this PR into multiple and/or drop some commits ACKs for top commit: tcharding: ACK 5d2f1ce apoelstra: ACK 5d2f1ce Tree-SHA512: 5bf84e7ebb6286d59f8cada0bb712c46336f0dd6c35b67e6f4ba323b5484ad925b99b73e778ae4608f123938e7ee8705a0aec576cd9c065072c4ecf1248e3470
2 parents 33f76e4 + 5d2f1ce commit 4f7f138

File tree

19 files changed

+258
-416
lines changed

19 files changed

+258
-416
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
runs-on: ubuntu-latest
3737
strategy:
3838
matrix:
39-
rust: [stable, beta, nightly, 1.29.0]
39+
rust: [stable, beta, nightly, 1.41.1]
4040
steps:
4141
- name: Checkout Crate
4242
uses: actions/checkout@v2
@@ -46,9 +46,6 @@ jobs:
4646
profile: minimal
4747
toolchain: ${{ matrix.rust }}
4848
override: true
49-
- name: Pin cc if rust 1.29
50-
if: matrix.rust == '1.29.0'
51-
run: cargo generate-lockfile --verbose && cargo update -p cc --precise "1.0.41" --verbose
5249
- name: Running cargo
5350
env:
5451
DO_FEATURE_MATRIX: true
@@ -59,7 +56,7 @@ jobs:
5956
runs-on: ubuntu-latest
6057
strategy:
6158
matrix:
62-
rust: [stable, beta, nightly] # No 1.29 because WASM requires Rust 1.30
59+
rust: [stable, beta, nightly] # wasm-pack doesn't support rust 1.41.1
6360
steps:
6461
- name: Checkout Crate
6562
uses: actions/checkout@v2

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ documentation = "https://docs.rs/secp256k1/"
1010
description = "Rust wrapper library for Pieter Wuille's `libsecp256k1`. Implements ECDSA and BIP 340 signatures for the SECG elliptic curve group secp256k1 and related utilities."
1111
keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ]
1212
readme = "README.md"
13-
autoexamples = false # Remove when edition 2018 https://github.com/rust-lang/cargo/issues/5330
13+
edition = "2018"
1414

1515
# Should make docs.rs show all functions, even those behind non-default features
1616
[package.metadata.docs.rs]
@@ -20,10 +20,10 @@ rustdoc-args = ["--cfg", "docsrs"]
2020
[features]
2121
unstable = ["recovery", "rand-std"]
2222
default = ["std"]
23-
std = ["secp256k1-sys/std"]
23+
std = ["alloc", "secp256k1-sys/std"]
2424
# allow use of Secp256k1::new and related API that requires an allocator
25-
alloc = []
26-
bitcoin-hashes-std = ["bitcoin_hashes/std"]
25+
alloc = ["secp256k1-sys/alloc"]
26+
bitcoin-hashes-std = ["bitcoin_hashes/std"]
2727
rand-std = ["rand/std"]
2828
recovery = ["secp256k1-sys/recovery"]
2929
lowmemory = ["secp256k1-sys/lowmemory"]
@@ -43,17 +43,17 @@ serde = { version = "1.0", default-features = false, optional = true }
4343
# You likely only want to enable these if you explicitly do not want to use "std", otherwise enable
4444
# the respective -std feature e.g., bitcoin-hashes-std
4545
bitcoin_hashes = { version = "0.10", default-features = false, optional = true }
46-
rand = { version = "0.6", default-features = false, optional = true }
46+
rand = { version = "0.8", default-features = false, optional = true }
4747

4848
[dev-dependencies]
49-
rand = "0.6"
50-
rand_core = "0.4"
49+
rand = "0.8"
50+
rand_core = "0.6"
5151
serde_test = "1.0"
5252
bitcoin_hashes = "0.10"
5353

5454
[target.wasm32-unknown-unknown.dev-dependencies]
5555
wasm-bindgen-test = "0.3"
56-
rand = { version = "0.6", features = ["wasm-bindgen"] }
56+
getrandom = { version = "0.2", features = ["js"] }
5757

5858

5959
[[example]]

README.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,7 @@ Contributions to this library are welcome. A few guidelines:
2020
* Any breaking changes must have an accompanied entry in CHANGELOG.md
2121
* No new dependencies, please.
2222
* No crypto should be implemented in Rust, with the possible exception of hash functions. Cryptographic contributions should be directed upstream to libsecp256k1.
23-
* This library should always compile with any combination of features on **Rust 1.29**.
24-
25-
## A note on Rust 1.29 support
26-
27-
The build dependency `cc` might require a more recent version of the Rust compiler.
28-
To ensure compilation with Rust 1.29.0, pin its version in your `Cargo.lock`
29-
with `cargo update -p cc --precise 1.0.41`. If you're using `secp256k1` in a library,
30-
to make sure it compiles in CI, you'll need to generate a lockfile first.
31-
Example for Travis CI:
32-
```yml
33-
before_script:
34-
- if [ "$TRAVIS_RUST_VERSION" == "1.29.0" ]; then
35-
cargo generate-lockfile --verbose && cargo update -p cc --precise "1.0.41" --verbose;
36-
fi
37-
```
23+
* This library should always compile with any combination of features on **Rust 1.41.1**.
3824

3925
## Fuzzing
4026

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.29"
1+
msrv = "1.41.1"

examples/generate_keys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
extern crate secp256k1;
22

3-
use secp256k1::rand::rngs::OsRng;
3+
use secp256k1::rand::thread_rng;
44
use secp256k1::{PublicKey, Secp256k1, SecretKey};
55

66
fn main() {
77
let secp = Secp256k1::new();
8-
let mut rng = OsRng::new().unwrap();
8+
let mut rng = thread_rng();
99
// First option:
1010
let (seckey, pubkey) = secp.generate_keypair(&mut rng);
1111

secp256k1-sys/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords = [ "secp256k1", "libsecp256k1", "ffi" ]
1313
readme = "README.md"
1414
build = "build.rs"
1515
links = "rustsecp256k1_v0_5_0"
16+
edition = "2018"
1617

1718
# Should make docs.rs show all functions, even those behind non-default features
1819
[package.metadata.docs.rs]
@@ -29,5 +30,6 @@ libc = "0.2"
2930
default = ["std"]
3031
recovery = []
3132
lowmemory = []
32-
std = []
33+
std = ["alloc"]
34+
alloc = []
3335

secp256k1-sys/src/lib.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717
//! not be needed for most users.
1818
1919
// Coding conventions
20-
#![deny(non_upper_case_globals)]
21-
#![deny(non_camel_case_types)]
22-
#![deny(non_snake_case)]
23-
#![deny(unused_mut)]
20+
#![deny(non_upper_case_globals, non_camel_case_types, non_snake_case, unused_mut)]
2421

2522
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
2623
#![cfg_attr(docsrs, feature(doc_cfg))]
2724

2825
#[cfg(any(test, feature = "std"))]
2926
extern crate core;
3027

28+
#[cfg(feature = "alloc")]
29+
extern crate alloc;
30+
3131
#[cfg(fuzzing)]
3232
const THIS_UNUSED_CONSTANT_IS_YOUR_WARNING_THAT_ALL_THE_CRYPTO_IN_THIS_LIB_IS_DISABLED_FOR_FUZZING: usize = 0;
3333

34-
#[macro_use]
3534
mod macros;
3635
pub mod types;
3736

@@ -585,11 +584,11 @@ extern "C" {
585584
///
586585
/// The newly created secp256k1 raw context.
587586
#[no_mangle]
588-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
589-
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
587+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
588+
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
590589
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *mut Context {
591590
use core::mem;
592-
use std::alloc;
591+
use crate::alloc::alloc;
593592
assert!(ALIGN_TO >= mem::align_of::<usize>());
594593
assert!(ALIGN_TO >= mem::align_of::<&usize>());
595594
assert!(ALIGN_TO >= mem::size_of::<usize>());
@@ -605,8 +604,8 @@ pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *
605604
secp256k1_context_preallocated_create(ptr, flags)
606605
}
607606

608-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
609-
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
607+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
608+
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
610609
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
611610
rustsecp256k1_v0_5_0_context_create(flags)
612611
}
@@ -618,19 +617,19 @@ pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
618617
/// The pointer shouldn't be used after passing to this function, consider it as passing it to `free()`.
619618
///
620619
#[no_mangle]
621-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
622-
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
620+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
621+
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
623622
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_destroy(ctx: *mut Context) {
624-
use std::alloc;
623+
use crate::alloc::alloc;
625624
secp256k1_context_preallocated_destroy(ctx);
626625
let ptr = (ctx as *mut u8).sub(ALIGN_TO);
627626
let bytes = (ptr as *mut usize).read();
628627
let layout = alloc::Layout::from_size_align(bytes, ALIGN_TO).unwrap();
629628
alloc::dealloc(ptr, layout);
630629
}
631630

632-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
633-
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
631+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
632+
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
634633
pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
635634
rustsecp256k1_v0_5_0_context_destroy(ctx)
636635
}

secp256k1-sys/src/macros.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ macro_rules! impl_array_newtype {
6969

7070
impl PartialOrd for $thing {
7171
#[inline]
72-
fn partial_cmp(&self, other: &$thing) -> Option<::core::cmp::Ordering> {
72+
fn partial_cmp(&self, other: &$thing) -> Option<core::cmp::Ordering> {
7373
self[..].partial_cmp(&other[..])
7474
}
7575
}
7676

7777
impl Ord for $thing {
7878
#[inline]
79-
fn cmp(&self, other: &$thing) -> ::core::cmp::Ordering {
79+
fn cmp(&self, other: &$thing) -> core::cmp::Ordering {
8080
self[..].cmp(&other[..])
8181
}
8282
}
@@ -89,7 +89,7 @@ macro_rules! impl_array_newtype {
8989
}
9090
}
9191

92-
impl ::core::ops::Index<usize> for $thing {
92+
impl core::ops::Index<usize> for $thing {
9393
type Output = $ty;
9494

9595
#[inline]
@@ -99,41 +99,41 @@ macro_rules! impl_array_newtype {
9999
}
100100
}
101101

102-
impl ::core::ops::Index<::core::ops::Range<usize>> for $thing {
102+
impl core::ops::Index<core::ops::Range<usize>> for $thing {
103103
type Output = [$ty];
104104

105105
#[inline]
106-
fn index(&self, index: ::core::ops::Range<usize>) -> &[$ty] {
106+
fn index(&self, index: core::ops::Range<usize>) -> &[$ty] {
107107
let &$thing(ref dat) = self;
108108
&dat[index]
109109
}
110110
}
111111

112-
impl ::core::ops::Index<::core::ops::RangeTo<usize>> for $thing {
112+
impl core::ops::Index<core::ops::RangeTo<usize>> for $thing {
113113
type Output = [$ty];
114114

115115
#[inline]
116-
fn index(&self, index: ::core::ops::RangeTo<usize>) -> &[$ty] {
116+
fn index(&self, index: core::ops::RangeTo<usize>) -> &[$ty] {
117117
let &$thing(ref dat) = self;
118118
&dat[index]
119119
}
120120
}
121121

122-
impl ::core::ops::Index<::core::ops::RangeFrom<usize>> for $thing {
122+
impl core::ops::Index<core::ops::RangeFrom<usize>> for $thing {
123123
type Output = [$ty];
124124

125125
#[inline]
126-
fn index(&self, index: ::core::ops::RangeFrom<usize>) -> &[$ty] {
126+
fn index(&self, index: core::ops::RangeFrom<usize>) -> &[$ty] {
127127
let &$thing(ref dat) = self;
128128
&dat[index]
129129
}
130130
}
131131

132-
impl ::core::ops::Index<::core::ops::RangeFull> for $thing {
132+
impl core::ops::Index<core::ops::RangeFull> for $thing {
133133
type Output = [$ty];
134134

135135
#[inline]
136-
fn index(&self, _: ::core::ops::RangeFull) -> &[$ty] {
136+
fn index(&self, _: core::ops::RangeFull) -> &[$ty] {
137137
let &$thing(ref dat) = self;
138138
&dat[..]
139139
}
@@ -142,15 +142,15 @@ macro_rules! impl_array_newtype {
142142
type Target = $ty;
143143
fn as_c_ptr(&self) -> *const Self::Target {
144144
if self.is_empty() {
145-
::core::ptr::null()
145+
core::ptr::null()
146146
} else {
147147
self.as_ptr()
148148
}
149149
}
150150

151151
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
152152
if self.is_empty() {
153-
::core::ptr::null::<Self::Target>() as *mut _
153+
core::ptr::null::<Self::Target>() as *mut _
154154
} else {
155155
self.as_mut_ptr()
156156
}
@@ -162,8 +162,8 @@ macro_rules! impl_array_newtype {
162162
#[macro_export]
163163
macro_rules! impl_raw_debug {
164164
($thing:ident) => {
165-
impl ::core::fmt::Debug for $thing {
166-
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
165+
impl core::fmt::Debug for $thing {
166+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
167167
for i in self[..].iter().cloned() {
168168
write!(f, "{:02x}", i)?;
169169
}

secp256k1-sys/src/recovery.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
//! # FFI of the recovery module
1717
18-
use ::types::*;
19-
use ::core::fmt;
20-
use {Context, Signature, NonceFn, PublicKey, CPtr};
18+
use crate::{Context, Signature, NonceFn, PublicKey, CPtr, impl_array_newtype};
19+
use crate::types::*;
20+
use core::fmt;
2121

2222
/// Library-internal representation of a Secp256k1 signature + recovery ID
2323
#[repr(C)]
@@ -98,13 +98,10 @@ extern "C" {
9898

9999
#[cfg(fuzzing)]
100100
mod fuzz_dummy {
101-
use super::*;
102-
use std::slice;
101+
use core::slice;
103102

104-
use secp256k1_ec_pubkey_create;
105-
use secp256k1_ec_pubkey_parse;
106-
use secp256k1_ec_pubkey_serialize;
107-
use SECP256K1_SER_COMPRESSED;
103+
use crate::{secp256k1_ec_pubkey_create, secp256k1_ec_pubkey_parse, secp256k1_ec_pubkey_serialize, SECP256K1_SER_COMPRESSED};
104+
use super::*;
108105

109106
/// Sets sig to msg32||full pk
110107
pub unsafe fn secp256k1_ecdsa_sign_recoverable(
@@ -170,6 +167,6 @@ mod fuzz_dummy {
170167
1
171168
}
172169
}
173-
#[cfg(fuzzing)]
174-
pub use self::fuzz_dummy::*;
175170

171+
#[cfg(fuzzing)]
172+
pub use self::fuzz_dummy::*;

0 commit comments

Comments
 (0)