Fix imports when using recovery with fuzztarget feature

This commit is contained in:
Jonas Nick 2019-05-21 22:16:11 +00:00
parent 2d41612e4a
commit 0e6ff34009
4 changed files with 23 additions and 5 deletions

View File

@ -29,6 +29,7 @@ script:
- cargo build --verbose --no-default-features --features="serde" - cargo build --verbose --no-default-features --features="serde"
- cargo build --verbose --no-default-features --features="rand" - cargo build --verbose --no-default-features --features="rand"
- cargo build --verbose --no-default-features --features="rand serde recovery" - cargo build --verbose --no-default-features --features="rand serde recovery"
- cargo build --verbose --no-default-features --features="fuzztarget recovery"
- cargo build --verbose - cargo build --verbose
- cargo test --verbose - cargo test --verbose
- cargo build --release - cargo build --release

View File

@ -60,6 +60,13 @@ pub type EcdhHashFn = unsafe extern "C" fn(
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[repr(C)] pub struct Context(c_int); #[repr(C)] pub struct Context(c_int);
#[cfg(feature = "fuzztarget")]
impl Context {
pub fn flags(&self) -> u32 {
self.0 as u32
}
}
/// Library-internal representation of a Secp256k1 public key /// Library-internal representation of a Secp256k1 public key
#[repr(C)] #[repr(C)]
pub struct PublicKey([c_uchar; 64]); pub struct PublicKey([c_uchar; 64]);
@ -250,9 +257,11 @@ extern "C" {
#[cfg(feature = "fuzztarget")] #[cfg(feature = "fuzztarget")]
mod fuzz_dummy { mod fuzz_dummy {
use std::os::raw::{c_int, c_uchar, c_uint, c_void}; extern crate std;
use types::*;
use ffi::*; use ffi::*;
use std::ptr; use self::std::ptr;
use self::std::boxed::Box;
extern "C" { extern "C" {
pub static secp256k1_ecdh_hash_function_default: EcdhHashFn; pub static secp256k1_ecdh_hash_function_default: EcdhHashFn;

View File

@ -133,7 +133,7 @@
#![cfg_attr(feature = "dev", feature(plugin))] #![cfg_attr(feature = "dev", feature(plugin))]
#![cfg_attr(feature = "dev", plugin(clippy))] #![cfg_attr(feature = "dev", plugin(clippy))]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)] #![cfg_attr(all(not(test), not(fuzztarget), not(feature = "std")), no_std)]
#![cfg_attr(all(test, feature = "unstable"), feature(test))] #![cfg_attr(all(test, feature = "unstable"), feature(test))]
#[cfg(all(test, feature = "unstable"))] extern crate test; #[cfg(all(test, feature = "unstable"))] extern crate test;
#[cfg(any(test, feature = "rand"))] pub extern crate rand; #[cfg(any(test, feature = "rand"))] pub extern crate rand;

View File

@ -69,6 +69,12 @@ extern "C" {
#[cfg(feature = "fuzztarget")] #[cfg(feature = "fuzztarget")]
mod fuzz_dummy { mod fuzz_dummy {
extern crate std;
use types::*;
use ffi::*;
use self::std::ptr;
use super::RecoverableSignature;
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 {
@ -95,8 +101,8 @@ mod fuzz_dummy {
_noncefn: NonceFn, _noncefn: NonceFn,
_noncedata: *const c_void) _noncedata: *const 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).flags() & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
assert!((*cx).0 as u32 & SECP256K1_START_SIGN == SECP256K1_START_SIGN); assert!((*cx).flags() & SECP256K1_START_SIGN == SECP256K1_START_SIGN);
if secp256k1_ec_seckey_verify(cx, sk) != 1 { return 0; } if secp256k1_ec_seckey_verify(cx, sk) != 1 { return 0; }
if *sk.offset(0) > 0x7f { if *sk.offset(0) > 0x7f {
(*sig).0[0] = 2; (*sig).0[0] = 2;
@ -116,3 +122,5 @@ mod fuzz_dummy {
unimplemented!(); unimplemented!();
} }
} }
#[cfg(feature = "fuzztarget")]
pub use self::fuzz_dummy::*;