Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the code to edition 2018, and update dependencies #331

Merged
merged 8 commits into from Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/rust.yml
Expand Up @@ -36,7 +36,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly, 1.29.0]
rust: [stable, beta, nightly, 1.41.1]
steps:
- name: Checkout Crate
uses: actions/checkout@v2
Expand All @@ -46,9 +46,6 @@ jobs:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Pin cc if rust 1.29
if: matrix.rust == '1.29.0'
run: cargo generate-lockfile --verbose && cargo update -p cc --precise "1.0.41" --verbose
- name: Running cargo
env:
DO_FEATURE_MATRIX: true
Expand All @@ -59,7 +56,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly] # No 1.29 because WASM requires Rust 1.30
rust: [stable, beta, nightly] # wasm-pack doesn't support rust 1.41.1
steps:
- name: Checkout Crate
uses: actions/checkout@v2
Expand Down
16 changes: 8 additions & 8 deletions Cargo.toml
Expand Up @@ -10,7 +10,7 @@ documentation = "https://docs.rs/secp256k1/"
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."
keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ]
readme = "README.md"
autoexamples = false # Remove when edition 2018 https://github.com/rust-lang/cargo/issues/5330
edition = "2018"

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

[dev-dependencies]
rand = "0.6"
rand_core = "0.4"
rand = "0.8"
rand_core = "0.6"
serde_test = "1.0"
bitcoin_hashes = "0.10"

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


[[example]]
Expand Down
16 changes: 1 addition & 15 deletions README.md
Expand Up @@ -20,21 +20,7 @@ Contributions to this library are welcome. A few guidelines:
* Any breaking changes must have an accompanied entry in CHANGELOG.md
* No new dependencies, please.
* No crypto should be implemented in Rust, with the possible exception of hash functions. Cryptographic contributions should be directed upstream to libsecp256k1.
* This library should always compile with any combination of features on **Rust 1.29**.

## A note on Rust 1.29 support

The build dependency `cc` might require a more recent version of the Rust compiler.
To ensure compilation with Rust 1.29.0, pin its version in your `Cargo.lock`
with `cargo update -p cc --precise 1.0.41`. If you're using `secp256k1` in a library,
to make sure it compiles in CI, you'll need to generate a lockfile first.
Example for Travis CI:
```yml
before_script:
- if [ "$TRAVIS_RUST_VERSION" == "1.29.0" ]; then
cargo generate-lockfile --verbose && cargo update -p cc --precise "1.0.41" --verbose;
fi
```
* This library should always compile with any combination of features on **Rust 1.41.1**.

## Fuzzing

Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
@@ -1 +1 @@
msrv = "1.29"
msrv = "1.41.1"
4 changes: 2 additions & 2 deletions examples/generate_keys.rs
@@ -1,11 +1,11 @@
extern crate secp256k1;

use secp256k1::rand::rngs::OsRng;
use secp256k1::rand::thread_rng;
use secp256k1::{PublicKey, Secp256k1, SecretKey};

fn main() {
let secp = Secp256k1::new();
let mut rng = OsRng::new().unwrap();
let mut rng = thread_rng();
// First option:
let (seckey, pubkey) = secp.generate_keypair(&mut rng);

Expand Down
4 changes: 3 additions & 1 deletion secp256k1-sys/Cargo.toml
Expand Up @@ -13,6 +13,7 @@ keywords = [ "secp256k1", "libsecp256k1", "ffi" ]
readme = "README.md"
build = "build.rs"
links = "rustsecp256k1_v0_5_0"
edition = "2018"

# Should make docs.rs show all functions, even those behind non-default features
[package.metadata.docs.rs]
Expand All @@ -29,5 +30,6 @@ libc = "0.2"
default = ["std"]
recovery = []
lowmemory = []
std = []
std = ["alloc"]
alloc = []

29 changes: 14 additions & 15 deletions secp256k1-sys/src/lib.rs
Expand Up @@ -17,21 +17,20 @@
//! not be needed for most users.

// Coding conventions
#![deny(non_upper_case_globals)]
#![deny(non_camel_case_types)]
#![deny(non_snake_case)]
#![deny(unused_mut)]
#![deny(non_upper_case_globals, non_camel_case_types, non_snake_case, unused_mut)]

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

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

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(fuzzing)]
const THIS_UNUSED_CONSTANT_IS_YOUR_WARNING_THAT_ALL_THE_CRYPTO_IN_THIS_LIB_IS_DISABLED_FOR_FUZZING: usize = 0;

#[macro_use]
mod macros;
pub mod types;

Expand Down Expand Up @@ -544,11 +543,11 @@ extern "C" {
///
/// The newly created secp256k1 raw context.
#[no_mangle]
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *mut Context {
use core::mem;
use std::alloc;
use crate::alloc::alloc;
elichai marked this conversation as resolved.
Show resolved Hide resolved
assert!(ALIGN_TO >= mem::align_of::<usize>());
assert!(ALIGN_TO >= mem::align_of::<&usize>());
assert!(ALIGN_TO >= mem::size_of::<usize>());
Expand All @@ -564,8 +563,8 @@ pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *
secp256k1_context_preallocated_create(ptr, flags)
}

#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
rustsecp256k1_v0_5_0_context_create(flags)
}
Expand All @@ -577,19 +576,19 @@ pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
/// The pointer shouldn't be used after passing to this function, consider it as passing it to `free()`.
///
#[no_mangle]
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_destroy(ctx: *mut Context) {
use std::alloc;
use crate::alloc::alloc;
secp256k1_context_preallocated_destroy(ctx);
let ptr = (ctx as *mut u8).sub(ALIGN_TO);
let bytes = (ptr as *mut usize).read();
let layout = alloc::Layout::from_size_align(bytes, ALIGN_TO).unwrap();
alloc::dealloc(ptr, layout);
}

#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
rustsecp256k1_v0_5_0_context_destroy(ctx)
}
Expand Down
30 changes: 15 additions & 15 deletions secp256k1-sys/src/macros.rs
Expand Up @@ -69,14 +69,14 @@ macro_rules! impl_array_newtype {

impl PartialOrd for $thing {
#[inline]
fn partial_cmp(&self, other: &$thing) -> Option<::core::cmp::Ordering> {
fn partial_cmp(&self, other: &$thing) -> Option<core::cmp::Ordering> {
self[..].partial_cmp(&other[..])
}
}

impl Ord for $thing {
#[inline]
fn cmp(&self, other: &$thing) -> ::core::cmp::Ordering {
fn cmp(&self, other: &$thing) -> core::cmp::Ordering {
self[..].cmp(&other[..])
}
}
Expand All @@ -89,7 +89,7 @@ macro_rules! impl_array_newtype {
}
}

impl ::core::ops::Index<usize> for $thing {
impl core::ops::Index<usize> for $thing {
type Output = $ty;

#[inline]
Expand All @@ -99,41 +99,41 @@ macro_rules! impl_array_newtype {
}
}

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

#[inline]
fn index(&self, index: ::core::ops::Range<usize>) -> &[$ty] {
fn index(&self, index: core::ops::Range<usize>) -> &[$ty] {
let &$thing(ref dat) = self;
&dat[index]
}
}

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

#[inline]
fn index(&self, index: ::core::ops::RangeTo<usize>) -> &[$ty] {
fn index(&self, index: core::ops::RangeTo<usize>) -> &[$ty] {
let &$thing(ref dat) = self;
&dat[index]
}
}

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

#[inline]
fn index(&self, index: ::core::ops::RangeFrom<usize>) -> &[$ty] {
fn index(&self, index: core::ops::RangeFrom<usize>) -> &[$ty] {
let &$thing(ref dat) = self;
&dat[index]
}
}

impl ::core::ops::Index<::core::ops::RangeFull> for $thing {
impl core::ops::Index<core::ops::RangeFull> for $thing {
type Output = [$ty];

#[inline]
fn index(&self, _: ::core::ops::RangeFull) -> &[$ty] {
fn index(&self, _: core::ops::RangeFull) -> &[$ty] {
let &$thing(ref dat) = self;
&dat[..]
}
Expand All @@ -142,15 +142,15 @@ macro_rules! impl_array_newtype {
type Target = $ty;
fn as_c_ptr(&self) -> *const Self::Target {
if self.is_empty() {
::core::ptr::null()
core::ptr::null()
} else {
self.as_ptr()
}
}

fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
if self.is_empty() {
::core::ptr::null::<Self::Target>() as *mut _
core::ptr::null::<Self::Target>() as *mut _
} else {
self.as_mut_ptr()
}
Expand All @@ -162,8 +162,8 @@ macro_rules! impl_array_newtype {
#[macro_export]
macro_rules! impl_raw_debug {
($thing:ident) => {
impl ::core::fmt::Debug for $thing {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
impl core::fmt::Debug for $thing {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
for i in self[..].iter().cloned() {
write!(f, "{:02x}", i)?;
}
Expand Down
19 changes: 8 additions & 11 deletions secp256k1-sys/src/recovery.rs
Expand Up @@ -15,9 +15,9 @@

//! # FFI of the recovery module

use ::types::*;
use ::core::fmt;
use {Context, Signature, NonceFn, PublicKey, CPtr};
use crate::{Context, Signature, NonceFn, PublicKey, CPtr, impl_array_newtype};
use crate::types::*;
use core::fmt;

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

#[cfg(fuzzing)]
mod fuzz_dummy {
use super::*;
use std::slice;
use core::slice;

use secp256k1_ec_pubkey_create;
use secp256k1_ec_pubkey_parse;
use secp256k1_ec_pubkey_serialize;
use SECP256K1_SER_COMPRESSED;
use crate::{secp256k1_ec_pubkey_create, secp256k1_ec_pubkey_parse, secp256k1_ec_pubkey_serialize, SECP256K1_SER_COMPRESSED};
use super::*;

/// Sets sig to msg32||full pk
pub unsafe fn secp256k1_ecdsa_sign_recoverable(
Expand Down Expand Up @@ -170,6 +167,6 @@ mod fuzz_dummy {
1
}
}
#[cfg(fuzzing)]
pub use self::fuzz_dummy::*;

#[cfg(fuzzing)]
pub use self::fuzz_dummy::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Newline at EOF got dropped here.