37
37
//! trigger any assertion failures in the upstream library.
38
38
//!
39
39
//! ```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() {
48
40
//! # #[cfg(all(feature="rand", feature="bitcoin_hashes"))] {
49
- //! use rand::rngs::OsRng;
41
+ //! use secp256k1:: rand::rngs::OsRng;
50
42
//! use secp256k1::{Secp256k1, Message};
51
- //! use bitcoin_hashes::sha256;
43
+ //! use secp256k1:: bitcoin_hashes::sha256;
52
44
//!
53
45
//! let secp = Secp256k1::new();
54
46
//! let mut rng = OsRng::new().expect("OsRng");
57
49
//!
58
50
//! let sig = secp.sign(&message, &secret_key);
59
51
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
60
- //! # } }
52
+ //! # }
61
53
//! ```
62
54
//!
63
55
//! The above code requires `rust-secp256k1` to be compiled with the `rand` and `bitcoin_hashes`
64
56
//! feature enabled, to get access to [`generate_keypair`](struct.Secp256k1.html#method.generate_keypair)
65
57
//! Alternately, keys and messages can be parsed from slices, like
66
58
//!
67
59
//! ```rust
68
- //! # fn main() {
69
60
//! use self::secp256k1::{Secp256k1, Message, SecretKey, PublicKey};
70
61
//!
71
62
//! let secp = Secp256k1::new();
77
68
//!
78
69
//! let sig = secp.sign(&message, &secret_key);
79
70
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
80
- //! # }
81
71
//! ```
82
72
//!
83
73
//! Users who only want to verify signatures can use a cheaper context, like so:
84
74
//!
85
75
//! ```rust
86
- //! # fn main() {
87
76
//! use secp256k1::{Secp256k1, Message, Signature, PublicKey};
88
77
//!
89
78
//! let secp = Secp256k1::verification_only();
115
104
//! ]).expect("compact signatures are 64 bytes; DER signatures are 68-72 bytes");
116
105
//!
117
106
//! assert!(secp.verify(&message, &sig, &public_key).is_ok());
118
- //! # }
119
107
//! ```
120
108
//!
121
109
//! Observe that the same code using, say [`signing_only`](struct.Secp256k1.html#method.signing_only)
122
110
//! to generate a context would simply not compile.
123
111
//!
124
112
125
- #![ crate_type = "lib" ]
126
- #![ crate_type = "rlib" ]
127
- #![ crate_type = "dylib" ]
128
- #![ crate_name = "secp256k1" ]
129
-
130
113
// Coding conventions
131
114
#![ deny( non_upper_case_globals) ]
132
115
#![ deny( non_camel_case_types) ]
133
116
#![ deny( non_snake_case) ]
134
117
#![ deny( unused_mut) ]
135
118
#![ warn( missing_docs) ]
136
119
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) ]
142
120
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) ]
149
122
#![ cfg_attr( all( test, feature = "unstable" ) , feature( test) ) ]
150
123
151
124
#[ macro_use]
152
125
pub extern crate secp256k1_sys;
153
126
pub use secp256k1_sys as ffi;
154
127
155
- #[ cfg( feature = "bitcoin_hashes" ) ] extern crate bitcoin_hashes;
128
+ #[ cfg( feature = "bitcoin_hashes" ) ] pub extern crate bitcoin_hashes;
156
129
#[ cfg( all( test, feature = "unstable" ) ) ] extern crate test;
157
130
#[ cfg( any( test, feature = "rand" ) ) ] pub extern crate rand;
158
131
#[ cfg( any( test) ) ] extern crate rand_core;
@@ -575,9 +548,7 @@ impl fmt::Display for Error {
575
548
}
576
549
577
550
#[ 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 { }
581
552
582
553
583
554
/// The secp256k1 engine, used to execute all signature operations
@@ -676,7 +647,7 @@ impl<C: Context> Secp256k1<C> {
676
647
// However, if this DOES fail, the result is potentially weaker side-channel
677
648
// resistance, which is deadly and undetectable, so we take out the entire
678
649
// thread to be on the safe side.
679
- assert ! ( err == 1 ) ;
650
+ assert_eq ! ( err, 1 ) ;
680
651
}
681
652
}
682
653
@@ -723,13 +694,8 @@ impl<C: Verification> Secp256k1<C> {
723
694
/// verify-capable context.
724
695
///
725
696
/// ```rust
726
- /// # extern crate secp256k1;
727
- /// # #[cfg(feature="rand")]
728
- /// # extern crate rand;
729
- /// #
730
- /// # fn main() {
731
697
/// # #[cfg(feature="rand")] {
732
- /// # use rand::OsRng;
698
+ /// # use secp256k1:: rand::rngs ::OsRng;
733
699
/// # use secp256k1::{Secp256k1, Message, Error};
734
700
/// #
735
701
/// # let secp = Secp256k1::new();
@@ -742,7 +708,7 @@ impl<C: Verification> Secp256k1<C> {
742
708
///
743
709
/// let message = Message::from_slice(&[0xcd; 32]).expect("32 bytes");
744
710
/// assert_eq!(secp.verify(&message, &sig, &public_key), Err(Error::IncorrectSignature));
745
- /// # } }
711
+ /// # }
746
712
/// ```
747
713
#[ inline]
748
714
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, ()> {
769
735
for c in hex. bytes ( ) {
770
736
b <<= 4 ;
771
737
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' ,
775
741
_ => return Err ( ( ) ) ,
776
742
}
777
743
if ( idx & 1 ) == 1 {
0 commit comments