Merge pull request #232 from rust-bitcoin/2020-08-modernize
Small modernization after MSRV bump
This commit is contained in:
commit
f375f6dfef
|
@ -62,7 +62,7 @@ script:
|
|||
- if [ ${TRAVIS_RUST_VERSION} == "stable" -a "$TRAVIS_OS_NAME" = "linux" ]; then
|
||||
clang --version &&
|
||||
CARGO_TARGET_DIR=wasm cargo install --verbose --force wasm-pack &&
|
||||
sed -i 's/\[lib\]/[lib]\ncrate-type = ["cdylib", "rlib"]/' Cargo.toml &&
|
||||
printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml &&
|
||||
CC=clang-9 wasm-pack build &&
|
||||
CC=clang-9 wasm-pack test --node;
|
||||
fi
|
||||
|
|
22
Cargo.toml
22
Cargo.toml
|
@ -1,5 +1,4 @@
|
|||
[package]
|
||||
|
||||
name = "secp256k1"
|
||||
version = "0.19.0"
|
||||
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
|
||||
|
@ -17,10 +16,6 @@ autoexamples = false # Remove when edition 2018 https://github.com/rust-lang/car
|
|||
[package.metadata.docs.rs]
|
||||
features = [ "rand", "rand-std", "serde", "recovery", "endomorphism" ]
|
||||
|
||||
[lib]
|
||||
name = "secp256k1"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[features]
|
||||
unstable = ["recovery", "rand-std"]
|
||||
default = ["std"]
|
||||
|
@ -40,6 +35,10 @@ fuzztarget = ["secp256k1-sys/fuzztarget"]
|
|||
|
||||
[dependencies]
|
||||
secp256k1-sys = { version = "0.3.0", default-features = false, path = "./secp256k1-sys" }
|
||||
bitcoin_hashes = { version = "0.9", optional = true }
|
||||
rand = { version = "0.6", default-features = false, optional = true }
|
||||
serde = { version = "1.0", default-features = false, optional = true }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.6"
|
||||
|
@ -51,19 +50,6 @@ bitcoin_hashes = "0.9"
|
|||
wasm-bindgen-test = "0.3"
|
||||
rand = { version = "0.6", features = ["wasm-bindgen"] }
|
||||
|
||||
[dependencies.bitcoin_hashes]
|
||||
version = "0.9"
|
||||
optional = true
|
||||
|
||||
[dependencies.rand]
|
||||
version = "0.6"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[[example]]
|
||||
name = "sign_verify_recovery"
|
||||
|
|
|
@ -21,10 +21,6 @@ features = [ "recovery", "endomorphism", "lowmemory" ]
|
|||
[build-dependencies]
|
||||
cc = "1.0.28"
|
||||
|
||||
[lib]
|
||||
name = "secp256k1_sys"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
recovery = []
|
||||
|
|
|
@ -16,16 +16,13 @@
|
|||
//! Direct bindings to the underlying C library functions. These should
|
||||
//! not be needed for most users.
|
||||
|
||||
#![crate_type = "lib"]
|
||||
#![crate_type = "rlib"]
|
||||
#![crate_type = "dylib"]
|
||||
#![crate_name = "secp256k1_sys"]
|
||||
|
||||
#![cfg_attr(all(not(test), not(fuzztarget), not(feature = "std")), no_std)]
|
||||
#![cfg_attr(feature = "dev", allow(unstable_features))]
|
||||
#![cfg_attr(feature = "dev", feature(plugin))]
|
||||
#![cfg_attr(feature = "dev", plugin(clippy))]
|
||||
// Coding conventions
|
||||
#![deny(non_upper_case_globals)]
|
||||
#![deny(non_camel_case_types)]
|
||||
#![deny(non_snake_case)]
|
||||
#![deny(unused_mut)]
|
||||
|
||||
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
|
||||
#[cfg(any(test, feature = "std"))]
|
||||
extern crate core;
|
||||
|
||||
|
@ -97,9 +94,6 @@ impl_raw_debug!(PublicKey);
|
|||
impl PublicKey {
|
||||
/// Create a new (zeroed) public key usable for the FFI interface
|
||||
pub fn new() -> PublicKey { PublicKey([0; 64]) }
|
||||
/// Create a new (uninitialized) public key usable for the FFI interface
|
||||
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
|
||||
pub unsafe fn blank() -> PublicKey { PublicKey::new() }
|
||||
}
|
||||
|
||||
impl Default for PublicKey {
|
||||
|
@ -123,9 +117,6 @@ impl_raw_debug!(Signature);
|
|||
impl Signature {
|
||||
/// Create a new (zeroed) signature usable for the FFI interface
|
||||
pub fn new() -> Signature { Signature([0; 64]) }
|
||||
/// Create a new (uninitialized) signature usable for the FFI interface
|
||||
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
|
||||
pub unsafe fn blank() -> Signature { Signature::new() }
|
||||
}
|
||||
|
||||
impl Default for Signature {
|
||||
|
@ -467,7 +458,7 @@ mod fuzz_dummy {
|
|||
use self::std::{ptr, mem};
|
||||
use self::std::boxed::Box;
|
||||
use types::*;
|
||||
use ::{Signature, Context, NonceFn, EcdhHashFn, PublicKey,
|
||||
use {Signature, Context, NonceFn, EcdhHashFn, PublicKey,
|
||||
SECP256K1_START_NONE, SECP256K1_START_VERIFY, SECP256K1_START_SIGN,
|
||||
SECP256K1_SER_COMPRESSED, SECP256K1_SER_UNCOMPRESSED};
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ macro_rules! impl_array_newtype {
|
|||
&dat[..]
|
||||
}
|
||||
}
|
||||
impl ::CPtr for $thing {
|
||||
impl $crate::CPtr for $thing {
|
||||
type Target = $ty;
|
||||
fn as_c_ptr(&self) -> *const Self::Target {
|
||||
if self.is_empty() {
|
||||
|
|
|
@ -28,9 +28,6 @@ impl_raw_debug!(RecoverableSignature);
|
|||
impl RecoverableSignature {
|
||||
/// Create a new (zeroed) signature usable for the FFI interface
|
||||
pub fn new() -> RecoverableSignature { RecoverableSignature([0; 65]) }
|
||||
/// Create a new (uninitialized) signature usable for the FFI interface
|
||||
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
|
||||
pub unsafe fn blank() -> RecoverableSignature { RecoverableSignature::new() }
|
||||
}
|
||||
|
||||
impl Default for RecoverableSignature {
|
||||
|
|
|
@ -14,7 +14,7 @@ pub use self::std_only::*;
|
|||
pub mod global {
|
||||
use std::ops::Deref;
|
||||
use std::sync::Once;
|
||||
use ::{Secp256k1, All};
|
||||
use {Secp256k1, All};
|
||||
|
||||
/// Proxy struct for global `SECP256K1` context
|
||||
pub struct GlobalContext {
|
||||
|
|
58
src/lib.rs
58
src/lib.rs
|
@ -37,18 +37,10 @@
|
|||
//! trigger any assertion failures in the upstream library.
|
||||
//!
|
||||
//! ```rust
|
||||
//! extern crate secp256k1;
|
||||
//! # #[cfg(feature="bitcoin_hashes")]
|
||||
//! extern crate bitcoin_hashes;
|
||||
//! # #[cfg(feature="rand")]
|
||||
//! extern crate rand;
|
||||
//!
|
||||
//! #
|
||||
//! # fn main() {
|
||||
//! # #[cfg(all(feature="rand", feature="bitcoin_hashes"))] {
|
||||
//! use rand::rngs::OsRng;
|
||||
//! use secp256k1::rand::rngs::OsRng;
|
||||
//! use secp256k1::{Secp256k1, Message};
|
||||
//! use bitcoin_hashes::sha256;
|
||||
//! use secp256k1::bitcoin_hashes::sha256;
|
||||
//!
|
||||
//! let secp = Secp256k1::new();
|
||||
//! let mut rng = OsRng::new().expect("OsRng");
|
||||
|
@ -57,7 +49,7 @@
|
|||
//!
|
||||
//! let sig = secp.sign(&message, &secret_key);
|
||||
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
|
||||
//! # } }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! The above code requires `rust-secp256k1` to be compiled with the `rand` and `bitcoin_hashes`
|
||||
|
@ -65,7 +57,6 @@
|
|||
//! Alternately, keys and messages can be parsed from slices, like
|
||||
//!
|
||||
//! ```rust
|
||||
//! # fn main() {
|
||||
//! use self::secp256k1::{Secp256k1, Message, SecretKey, PublicKey};
|
||||
//!
|
||||
//! let secp = Secp256k1::new();
|
||||
|
@ -77,13 +68,11 @@
|
|||
//!
|
||||
//! let sig = secp.sign(&message, &secret_key);
|
||||
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! Users who only want to verify signatures can use a cheaper context, like so:
|
||||
//!
|
||||
//! ```rust
|
||||
//! # fn main() {
|
||||
//! use secp256k1::{Secp256k1, Message, Signature, PublicKey};
|
||||
//!
|
||||
//! let secp = Secp256k1::verification_only();
|
||||
|
@ -115,18 +104,12 @@
|
|||
//! ]).expect("compact signatures are 64 bytes; DER signatures are 68-72 bytes");
|
||||
//!
|
||||
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! Observe that the same code using, say [`signing_only`](struct.Secp256k1.html#method.signing_only)
|
||||
//! to generate a context would simply not compile.
|
||||
//!
|
||||
|
||||
#![crate_type = "lib"]
|
||||
#![crate_type = "rlib"]
|
||||
#![crate_type = "dylib"]
|
||||
#![crate_name = "secp256k1"]
|
||||
|
||||
// Coding conventions
|
||||
#![deny(non_upper_case_globals)]
|
||||
#![deny(non_camel_case_types)]
|
||||
|
@ -134,25 +117,15 @@
|
|||
#![deny(unused_mut)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
// In general, rust is absolutely horrid at supporting users doing things like,
|
||||
// for example, compiling Rust code for real environments. Disable useless lints
|
||||
// that don't do anything but annoy us and cant actually ever be resolved.
|
||||
#![allow(bare_trait_objects)]
|
||||
#![allow(ellipsis_inclusive_range_patterns)]
|
||||
|
||||
#![cfg_attr(feature = "dev", allow(unstable_features))]
|
||||
#![cfg_attr(feature = "dev", feature(plugin))]
|
||||
#![cfg_attr(feature = "dev", plugin(clippy))]
|
||||
|
||||
|
||||
#![cfg_attr(all(not(test), not(fuzztarget), not(feature = "std")), no_std)]
|
||||
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
|
||||
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
||||
|
||||
#[macro_use]
|
||||
pub extern crate secp256k1_sys;
|
||||
pub use secp256k1_sys as ffi;
|
||||
|
||||
#[cfg(feature = "bitcoin_hashes")] extern crate bitcoin_hashes;
|
||||
#[cfg(feature = "bitcoin_hashes")] pub extern crate bitcoin_hashes;
|
||||
#[cfg(all(test, feature = "unstable"))] extern crate test;
|
||||
#[cfg(any(test, feature = "rand"))] pub extern crate rand;
|
||||
#[cfg(any(test))] extern crate rand_core;
|
||||
|
@ -575,9 +548,7 @@ impl fmt::Display for Error {
|
|||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for Error {
|
||||
fn description(&self) -> &str { self.as_str() }
|
||||
}
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
|
||||
/// The secp256k1 engine, used to execute all signature operations
|
||||
|
@ -676,7 +647,7 @@ impl<C: Context> Secp256k1<C> {
|
|||
// However, if this DOES fail, the result is potentially weaker side-channel
|
||||
// resistance, which is deadly and undetectable, so we take out the entire
|
||||
// thread to be on the safe side.
|
||||
assert!(err == 1);
|
||||
assert_eq!(err, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -723,13 +694,8 @@ impl<C: Verification> Secp256k1<C> {
|
|||
/// verify-capable context.
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate secp256k1;
|
||||
/// # #[cfg(feature="rand")]
|
||||
/// # extern crate rand;
|
||||
/// #
|
||||
/// # fn main() {
|
||||
/// # #[cfg(feature="rand")] {
|
||||
/// # use rand::OsRng;
|
||||
/// # use secp256k1::rand::rngs::OsRng;
|
||||
/// # use secp256k1::{Secp256k1, Message, Error};
|
||||
/// #
|
||||
/// # let secp = Secp256k1::new();
|
||||
|
@ -742,7 +708,7 @@ impl<C: Verification> Secp256k1<C> {
|
|||
///
|
||||
/// let message = Message::from_slice(&[0xcd; 32]).expect("32 bytes");
|
||||
/// assert_eq!(secp.verify(&message, &sig, &public_key), Err(Error::IncorrectSignature));
|
||||
/// # } }
|
||||
/// # }
|
||||
/// ```
|
||||
#[inline]
|
||||
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, ()> {
|
|||
for c in hex.bytes() {
|
||||
b <<= 4;
|
||||
match c {
|
||||
b'A'...b'F' => b |= c - b'A' + 10,
|
||||
b'a'...b'f' => b |= c - b'a' + 10,
|
||||
b'0'...b'9' => b |= c - b'0',
|
||||
b'A'..=b'F' => b |= c - b'A' + 10,
|
||||
b'a'..=b'f' => b |= c - b'a' + 10,
|
||||
b'0'..=b'9' => b |= c - b'0',
|
||||
_ => return Err(()),
|
||||
}
|
||||
if (idx & 1) == 1 {
|
||||
|
|
Loading…
Reference in New Issue