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 } ;
2420use 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`).
2825const 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) ]
206203mod 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" ) ) ]
294292mod 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 ) {
0 commit comments