Skip to content

Commit 626835f

Browse files
committed
Update secp256k1 to edition 2018 and fix imports
1 parent 67c0922 commit 626835f

File tree

11 files changed

+165
-193
lines changed

11 files changed

+165
-193
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ documentation = "https://docs.rs/secp256k1/"
1010
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."
1111
keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ]
1212
readme = "README.md"
13-
autoexamples = false # Remove when edition 2018 https://github.com/rust-lang/cargo/issues/5330
13+
edition = "2018"
1414

1515
# Should make docs.rs show all functions, even those behind non-default features
1616
[package.metadata.docs.rs]

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.29"
1+
msrv = "1.41.1"

src/context.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use core::marker::PhantomData;
22
use core::mem::ManuallyDrop;
3-
use ffi::{self, CPtr, types::AlignedType};
4-
use ffi::types::{c_uint, c_void};
5-
use Error;
6-
use Secp256k1;
3+
4+
use crate::{Error, Secp256k1};
5+
use crate::ffi::{self, CPtr, types::AlignedType};
6+
use crate::ffi::types::{c_uint, c_void};
77

88
#[cfg(any(feature = "std", feature = "alloc"))]
99
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
@@ -13,12 +13,11 @@ pub use self::alloc_only::*;
1313
#[cfg_attr(docsrs, doc(cfg(all(feature = "global-context", feature = "std"))))]
1414
/// Module implementing a singleton pattern for a global `Secp256k1` context.
1515
pub mod global {
16-
#[cfg(feature = "rand-std")]
17-
use rand;
1816

1917
use std::ops::Deref;
2018
use std::sync::Once;
21-
use {Secp256k1, All};
19+
20+
use crate::{All, Secp256k1};
2221

2322
/// Proxy struct for global `SECP256K1` context.
2423
#[derive(Debug, Copy, Clone)]
@@ -107,10 +106,16 @@ mod private {
107106
#[cfg(any(feature = "std", feature = "alloc"))]
108107
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
109108
mod alloc_only {
110-
#[cfg(feature = "std")]
111-
use std::alloc;
112109
#[cfg(not(feature = "std"))]
113110
use alloc::alloc;
111+
#[cfg(feature = "std")]
112+
use std::alloc;
113+
114+
use core::marker::PhantomData;
115+
116+
use super::private;
117+
use crate::ffi::{self, types::{c_uint, c_void}};
118+
use crate::{Secp256k1, Signing, Verification, Context, AlignedType};
114119

115120
#[cfg(feature = "rand-std")]
116121
use rand;
@@ -119,8 +124,7 @@ mod alloc_only {
119124
impl private::Sealed for All {}
120125
impl private::Sealed for VerifyOnly {}
121126

122-
use super::*;
123-
const ALIGN_TO: usize = ::core::mem::align_of::<AlignedType>();
127+
const ALIGN_TO: usize = core::mem::align_of::<AlignedType>();
124128

125129
/// Represents the set of capabilities needed for signing.
126130
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]

src/ecdh.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
//! Support for shared secret computations.
1616
//!
1717
18-
use core::{ptr, str};
19-
use core::borrow::Borrow;
18+
use core::{borrow::Borrow, ptr, str};
2019

21-
use {Error, from_hex};
22-
use key::{SecretKey, PublicKey};
23-
use ffi::{self, CPtr};
2420
use secp256k1_sys::types::{c_int, c_uchar, c_void};
25-
use constants;
21+
22+
use crate::{constants, Error, ffi::{self, CPtr}, key::{PublicKey, SecretKey}};
2623

2724
// The logic for displaying shared secrets relies on this (see `secret.rs`).
2825
const SHARED_SECRET_SIZE: usize = constants::SECRET_KEY_SIZE;
@@ -97,7 +94,7 @@ impl str::FromStr for SharedSecret {
9794
type Err = Error;
9895
fn from_str(s: &str) -> Result<SharedSecret, Error> {
9996
let mut res = [0u8; SHARED_SECRET_SIZE];
100-
match from_hex(s, &mut res) {
97+
match crate::from_hex(s, &mut res) {
10198
Ok(SHARED_SECRET_SIZE) => Ok(SharedSecret::from_bytes(res)),
10299
_ => Err(Error::InvalidSharedSecret)
103100
}
@@ -177,7 +174,7 @@ impl ::serde::Serialize for SharedSecret {
177174
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
178175
if s.is_human_readable() {
179176
let mut buf = [0u8; SHARED_SECRET_SIZE * 2];
180-
s.serialize_str(::to_hex(&self.0, &mut buf).expect("fixed-size hex serialization"))
177+
s.serialize_str(crate::to_hex(&self.0, &mut buf).expect("fixed-size hex serialization"))
181178
} else {
182179
s.serialize_bytes(&self.as_ref()[..])
183180
}
@@ -204,13 +201,13 @@ impl<'de> ::serde::Deserialize<'de> for SharedSecret {
204201
#[cfg(test)]
205202
#[allow(unused_imports)]
206203
mod tests {
207-
use super::*;
208204
use rand::thread_rng;
209-
use super::super::Secp256k1;
210-
211205
#[cfg(target_arch = "wasm32")]
212206
use wasm_bindgen_test::wasm_bindgen_test as test;
213207

208+
use crate::Secp256k1;
209+
use super::SharedSecret;
210+
214211
#[test]
215212
#[cfg(all(feature="rand-std", any(feature = "alloc", feature = "std")))]
216213
fn ecdh() {
@@ -230,7 +227,7 @@ mod tests {
230227
let x = [5u8; 32];
231228
let y = [7u8; 32];
232229
let mut output = [0u8; 64];
233-
let res = unsafe { super::c_callback(output.as_mut_ptr(), x.as_ptr(), y.as_ptr(), ptr::null_mut()) };
230+
let res = unsafe { super::c_callback(output.as_mut_ptr(), x.as_ptr(), y.as_ptr(), core::ptr::null_mut()) };
234231
assert_eq!(res, 1);
235232
let mut new_x = [0u8; 32];
236233
let mut new_y = [0u8; 32];
@@ -244,7 +241,8 @@ mod tests {
244241
#[cfg(not(fuzzing))]
245242
#[cfg(all(feature="rand-std", feature = "std", feature = "bitcoin_hashes"))]
246243
fn bitcoin_hashes_and_sys_generate_same_secret() {
247-
use hashes::{sha256, Hash, HashEngine};
244+
use bitcoin_hashes::{sha256, Hash, HashEngine};
245+
use crate::ecdh::shared_secret_point;
248246

249247
let s = Secp256k1::signing_only();
250248
let (sk1, _) = s.generate_keypair(&mut thread_rng());
@@ -292,11 +290,13 @@ mod tests {
292290

293291
#[cfg(all(test, feature = "unstable"))]
294292
mod benches {
295-
use rand::thread_rng;
296293
use test::{Bencher, black_box};
297294

295+
use rand::thread_rng;
296+
297+
use crate::Secp256k1;
298+
298299
use super::SharedSecret;
299-
use super::super::Secp256k1;
300300

301301
#[bench]
302302
pub fn bench_ecdh(bh: &mut Bencher) {

src/ecdsa/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use core::{fmt, str, ops, ptr, mem};
44

5-
use {Signing, Verification, Message, PublicKey, Secp256k1, SecretKey, from_hex, Error, ffi};
6-
use ffi::CPtr;
5+
use crate::{Signing, Verification, Message, PublicKey, Secp256k1, SecretKey, from_hex, Error, ffi};
6+
use crate::ffi::CPtr;
77

88
#[cfg(feature = "recovery")]
99
mod recovery;
@@ -13,7 +13,7 @@ mod recovery;
1313
pub use self::recovery::{RecoveryId, RecoverableSignature};
1414

1515
#[cfg(feature = "global-context")]
16-
use SECP256K1;
16+
use crate::SECP256K1;
1717

1818
/// An ECDSA signature
1919
#[derive(Copy, Clone, PartialEq, Eq)]
@@ -304,8 +304,8 @@ impl From<ffi::Signature> for Signature {
304304

305305
#[cfg(feature = "serde")]
306306
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
307-
impl ::serde::Serialize for Signature {
308-
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
307+
impl serde::Serialize for Signature {
308+
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
309309
if s.is_human_readable() {
310310
s.collect_str(self)
311311
} else {
@@ -316,14 +316,14 @@ impl ::serde::Serialize for Signature {
316316

317317
#[cfg(feature = "serde")]
318318
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
319-
impl<'de> ::serde::Deserialize<'de> for Signature {
320-
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
319+
impl<'de> serde::Deserialize<'de> for Signature {
320+
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
321321
if d.is_human_readable() {
322-
d.deserialize_str(::serde_util::FromStrVisitor::new(
322+
d.deserialize_str(crate::serde_util::FromStrVisitor::new(
323323
"a hex string representing a DER encoded Signature"
324324
))
325325
} else {
326-
d.deserialize_bytes(::serde_util::BytesVisitor::new(
326+
d.deserialize_bytes(crate::serde_util::BytesVisitor::new(
327327
"raw byte stream, that represents a DER encoded Signature",
328328
Signature::from_der
329329
))

src/ecdsa/recovery.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
//!
1919
2020
use core::ptr;
21-
use key;
21+
use crate::{key, Secp256k1, Message, Error, Verification, Signing, ecdsa::Signature};
2222
use super::ffi as super_ffi;
2323
use self::super_ffi::CPtr;
24-
use ffi::recovery as ffi;
25-
use super::*;
26-
use {Verification, Secp256k1, Signing, Message};
24+
use crate::ffi::recovery as ffi;
2725

2826
/// A tag used for recovering the public key from a compact signature.
2927
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -127,7 +125,7 @@ impl RecoverableSignature {
127125
#[cfg(feature = "global-context")]
128126
#[cfg_attr(docsrs, doc(cfg(feature = "global-context")))]
129127
pub fn recover(&self, msg: &Message) -> Result<key::PublicKey, Error> {
130-
SECP256K1.recover_ecdsa(msg, self)
128+
crate::SECP256K1.recover_ecdsa(msg, self)
131129
}
132130
}
133131

@@ -235,9 +233,10 @@ impl<C: Verification> Secp256k1<C> {
235233
#[cfg(test)]
236234
#[allow(unused_imports)]
237235
mod tests {
238-
use super::*;
239236
use rand::{RngCore, thread_rng};
240-
use key::SecretKey;
237+
238+
use crate::{Error, SecretKey, Secp256k1, Message};
239+
use super::{RecoveryId, RecoverableSignature};
241240

242241
#[cfg(target_arch = "wasm32")]
243242
use wasm_bindgen_test::wasm_bindgen_test as test;

0 commit comments

Comments
 (0)