Fix clippy errors

Changes include cargo-fix generated, Default impls
This commit is contained in:
François Garillot 2019-02-11 10:33:17 -08:00
parent e69eabb36f
commit a8a3afe8db
No known key found for this signature in database
GPG Key ID: 3E1EA1A9D2044742
3 changed files with 58 additions and 28 deletions

View File

@ -11,10 +11,10 @@ os:
- windows - windows
matrix: matrix:
# rand 0.4 actually needs Rust 1.22, which leads to build failures on Rust 1.14 on Windows. # rand 0.6 actually needs Rust 1.22, which leads to build failures on Rust 1.14 on Windows.
# This is not a problem, because # This is a problem, because
# - we insist on rust 1.14 only for Debian, and # - we insist on rust 1.22 since #92
# - "rand" is only an optional dependency. # - but "rand" is only an optional dependency.
exclude: exclude:
- rust: 1.22.0 - rust: 1.22.0
os: windows os: windows

View File

@ -21,13 +21,13 @@ use std::hash;
use std::os::raw::{c_int, c_uchar, c_uint, c_void}; use std::os::raw::{c_int, c_uchar, c_uint, c_void};
/// Flag for context to enable no precomputation /// Flag for context to enable no precomputation
pub const SECP256K1_START_NONE: c_uint = (1 << 0) | 0; pub const SECP256K1_START_NONE: c_uint = 1;
/// Flag for context to enable verification precomputation /// Flag for context to enable verification precomputation
pub const SECP256K1_START_VERIFY: c_uint = (1 << 0) | (1 << 8); pub const SECP256K1_START_VERIFY: c_uint = 1 | (1 << 8);
/// Flag for context to enable signing precomputation /// Flag for context to enable signing precomputation
pub const SECP256K1_START_SIGN: c_uint = (1 << 0) | (1 << 9); pub const SECP256K1_START_SIGN: c_uint = 1 | (1 << 9);
/// Flag for keys to indicate uncompressed serialization format /// Flag for keys to indicate uncompressed serialization format
pub const SECP256K1_SER_UNCOMPRESSED: c_uint = (1 << 1) | 0; pub const SECP256K1_SER_UNCOMPRESSED: c_uint = (1 << 1);
/// Flag for keys to indicate compressed serialization format /// Flag for keys to indicate compressed serialization format
pub const SECP256K1_SER_COMPRESSED: c_uint = (1 << 1) | (1 << 8); pub const SECP256K1_SER_COMPRESSED: c_uint = (1 << 1) | (1 << 8);
@ -74,6 +74,12 @@ impl PublicKey {
pub unsafe fn blank() -> PublicKey { mem::uninitialized() } pub unsafe fn blank() -> PublicKey { mem::uninitialized() }
} }
impl Default for PublicKey {
fn default() -> Self {
PublicKey::new()
}
}
impl hash::Hash for PublicKey { impl hash::Hash for PublicKey {
fn hash<H: hash::Hasher>(&self, state: &mut H) { fn hash<H: hash::Hasher>(&self, state: &mut H) {
state.write(&self.0) state.write(&self.0)
@ -99,6 +105,12 @@ impl Signature {
pub unsafe fn blank() -> Signature { mem::uninitialized() } pub unsafe fn blank() -> Signature { mem::uninitialized() }
} }
impl Default for Signature {
fn default() -> Self {
Signature::new()
}
}
impl RecoverableSignature { impl RecoverableSignature {
/// Create a new (zeroed) signature usable for the FFI interface /// Create a new (zeroed) signature usable for the FFI interface
pub fn new() -> RecoverableSignature { RecoverableSignature([0; 65]) } pub fn new() -> RecoverableSignature { RecoverableSignature([0; 65]) }
@ -106,6 +118,12 @@ impl RecoverableSignature {
pub unsafe fn blank() -> RecoverableSignature { mem::uninitialized() } pub unsafe fn blank() -> RecoverableSignature { mem::uninitialized() }
} }
impl Default for RecoverableSignature {
fn default() -> Self {
RecoverableSignature::new()
}
}
/// Library-internal representation of an ECDH shared secret /// Library-internal representation of an ECDH shared secret
#[repr(C)] #[repr(C)]
pub struct SharedSecret([c_uchar; 32]); pub struct SharedSecret([c_uchar; 32]);
@ -119,6 +137,12 @@ impl SharedSecret {
pub unsafe fn blank() -> SharedSecret { mem::uninitialized() } pub unsafe fn blank() -> SharedSecret { mem::uninitialized() }
} }
impl Default for SharedSecret {
fn default() -> Self {
SharedSecret::new()
}
}
#[cfg(not(feature = "fuzztarget"))] #[cfg(not(feature = "fuzztarget"))]
extern "C" { extern "C" {
/// Default ECDH hash function /// Default ECDH hash function
@ -369,8 +393,8 @@ mod fuzz_dummy {
} }
// Signatures // Signatures
pub unsafe fn secp256k1_ecdsa_signature_parse_der(cx: *const Context, sig: *mut Signature, pub unsafe fn secp256k1_ecdsa_signature_parse_der(_cx: *const Context, _sig: *mut Signature,
input: *const c_uchar, in_len: usize) _input: *const c_uchar, _in_len: usize)
-> c_int { -> c_int {
unimplemented!(); unimplemented!();
} }
@ -385,8 +409,8 @@ mod fuzz_dummy {
1 1
} }
pub unsafe fn ecdsa_signature_parse_der_lax(cx: *const Context, sig: *mut Signature, pub unsafe fn ecdsa_signature_parse_der_lax(_cx: *const Context, _sig: *mut Signature,
input: *const c_uchar, in_len: usize) _input: *const c_uchar, _in_len: usize)
-> c_int { -> c_int {
unimplemented!(); unimplemented!();
} }
@ -438,26 +462,26 @@ mod fuzz_dummy {
1 1
} }
pub unsafe fn secp256k1_ecdsa_recoverable_signature_parse_compact(cx: *const Context, sig: *mut RecoverableSignature, pub unsafe fn secp256k1_ecdsa_recoverable_signature_parse_compact(_cx: *const Context, _sig: *mut RecoverableSignature,
input64: *const c_uchar, recid: c_int) _input64: *const c_uchar, _recid: c_int)
-> c_int { -> c_int {
unimplemented!(); unimplemented!();
} }
pub unsafe fn secp256k1_ecdsa_recoverable_signature_serialize_compact(cx: *const Context, output64: *const c_uchar, pub unsafe fn secp256k1_ecdsa_recoverable_signature_serialize_compact(_cx: *const Context, _output64: *const c_uchar,
recid: *mut c_int, sig: *const RecoverableSignature) _recid: *mut c_int, _sig: *const RecoverableSignature)
-> c_int { -> c_int {
unimplemented!(); unimplemented!();
} }
pub unsafe fn secp256k1_ecdsa_recoverable_signature_convert(cx: *const Context, sig: *mut Signature, pub unsafe fn secp256k1_ecdsa_recoverable_signature_convert(_cx: *const Context, _sig: *mut Signature,
input: *const RecoverableSignature) _input: *const RecoverableSignature)
-> c_int { -> c_int {
unimplemented!(); unimplemented!();
} }
pub unsafe fn secp256k1_ecdsa_signature_normalize(cx: *const Context, out_sig: *mut Signature, pub unsafe fn secp256k1_ecdsa_signature_normalize(_cx: *const Context, _out_sig: *mut Signature,
in_sig: *const Signature) _in_sig: *const Signature)
-> c_int { -> c_int {
unimplemented!(); unimplemented!();
} }
@ -521,10 +545,10 @@ mod fuzz_dummy {
1 1
} }
pub unsafe fn secp256k1_ecdsa_recover(cx: *const Context, pub unsafe fn secp256k1_ecdsa_recover(_cx: *const Context,
pk: *mut PublicKey, _pk: *mut PublicKey,
sig: *const RecoverableSignature, _sig: *const RecoverableSignature,
msg32: *const c_uchar) _msg32: *const c_uchar)
-> c_int { -> c_int {
unimplemented!(); unimplemented!();
} }
@ -640,8 +664,8 @@ mod fuzz_dummy {
out: *mut SharedSecret, out: *mut SharedSecret,
point: *const PublicKey, point: *const PublicKey,
scalar: *const c_uchar, scalar: *const c_uchar,
hashfp: EcdhHashFn, _hashfp: EcdhHashFn,
data: *mut c_void, _data: *mut c_void,
) -> c_int { ) -> c_int {
assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0); assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
if secp256k1_ec_seckey_verify(cx, scalar) != 1 { return 0; } if secp256k1_ec_seckey_verify(cx, scalar) != 1 { return 0; }

View File

@ -223,7 +223,7 @@ pub fn from_i32(id: i32) -> Result<RecoveryId, Error> {
#[inline] #[inline]
/// Allows library users to convert recovery IDs to i32. /// Allows library users to convert recovery IDs to i32.
pub fn to_i32(&self) -> i32 { pub fn to_i32(self) -> i32 {
self.0 self.0
} }
} }
@ -474,7 +474,7 @@ impl Message {
/// Converts a `MESSAGE_SIZE`-byte slice to a message object /// Converts a `MESSAGE_SIZE`-byte slice to a message object
#[inline] #[inline]
pub fn from_slice(data: &[u8]) -> Result<Message, Error> { pub fn from_slice(data: &[u8]) -> Result<Message, Error> {
if data == &[0; constants::MESSAGE_SIZE] { if data == [0; constants::MESSAGE_SIZE] {
return Err(Error::InvalidMessage); return Err(Error::InvalidMessage);
} }
@ -617,6 +617,12 @@ impl Secp256k1<All> {
} }
} }
impl Default for Secp256k1<All> {
fn default() -> Self {
Self::new()
}
}
impl Secp256k1<SignOnly> { impl Secp256k1<SignOnly> {
/// Creates a new Secp256k1 context that can only be used for signing /// Creates a new Secp256k1 context that can only be used for signing
pub fn signing_only() -> Secp256k1<SignOnly> { pub fn signing_only() -> Secp256k1<SignOnly> {