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");
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();
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();
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]
152125pub extern crate secp256k1_sys;
153126pub 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