diff --git a/secp256k1-sys/src/lib.rs b/secp256k1-sys/src/lib.rs index c186ec1..e1f72bb 100644 --- a/secp256k1-sys/src/lib.rs +++ b/secp256k1-sys/src/lib.rs @@ -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; @@ -467,7 +464,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}; diff --git a/secp256k1-sys/src/macros.rs b/secp256k1-sys/src/macros.rs index afb0e2f..4a30c27 100644 --- a/secp256k1-sys/src/macros.rs +++ b/secp256k1-sys/src/macros.rs @@ -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() { diff --git a/src/context.rs b/src/context.rs index 0e55d59..5fb7d18 100644 --- a/src/context.rs +++ b/src/context.rs @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index 4d887a0..10a4ed3 100644 --- a/src/lib.rs +++ b/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 Secp256k1 { // 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 Secp256k1 { /// 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 Secp256k1 { /// /// 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 { 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 {