Merge pull request #162 from elichai/2019-09-ffi

Fixes and tests for the ffi
This commit is contained in:
Andrew Poelstra 2019-11-27 20:01:17 +00:00 committed by GitHub
commit cf22f60919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 5 deletions

View File

@ -41,8 +41,9 @@ pub type NonceFn = unsafe extern "C" fn(nonce32: *mut c_uchar,
msg32: *const c_uchar, msg32: *const c_uchar,
key32: *const c_uchar, key32: *const c_uchar,
algo16: *const c_uchar, algo16: *const c_uchar,
data: *mut c_void,
attempt: c_uint, attempt: c_uint,
data: *const c_void); );
/// Hash function to use to post-process an ECDH point to get /// Hash function to use to post-process an ECDH point to get
/// a shared secret. /// a shared secret.
@ -50,7 +51,7 @@ pub type EcdhHashFn = unsafe extern "C" fn(
output: *mut c_uchar, output: *mut c_uchar,
x: *const c_uchar, x: *const c_uchar,
y: *const c_uchar, y: *const c_uchar,
data: *const c_void, data: *mut c_void,
); );
/// A Secp256k1 context, containing various precomputed values and such /// A Secp256k1 context, containing various precomputed values and such
@ -186,7 +187,7 @@ extern "C" {
out_len: *mut usize, sig: *const Signature) out_len: *mut usize, sig: *const Signature)
-> c_int; -> c_int;
pub fn secp256k1_ecdsa_signature_serialize_compact(cx: *const Context, output64: *const c_uchar, pub fn secp256k1_ecdsa_signature_serialize_compact(cx: *const Context, output64: *mut c_uchar,
sig: *const Signature) sig: *const Signature)
-> c_int; -> c_int;

View File

@ -45,7 +45,7 @@ extern "C" {
input64: *const c_uchar, recid: c_int) input64: *const c_uchar, recid: c_int)
-> c_int; -> c_int;
pub fn secp256k1_ecdsa_recoverable_signature_serialize_compact(cx: *const Context, output64: *const c_uchar, pub fn secp256k1_ecdsa_recoverable_signature_serialize_compact(cx: *const Context, output64: *mut c_uchar,
recid: *mut c_int, sig: *const RecoverableSignature) recid: *mut c_int, sig: *const RecoverableSignature)
-> c_int; -> c_int;
@ -82,7 +82,7 @@ mod fuzz_dummy {
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: *mut c_uchar,
_recid: *mut c_int, _sig: *const RecoverableSignature) _recid: *mut c_int, _sig: *const RecoverableSignature)
-> c_int { -> c_int {
unimplemented!(); unimplemented!();

View File

@ -23,4 +23,19 @@ impl fmt::Debug for c_void {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("c_void") f.pad("c_void")
} }
}
#[cfg(test)]
mod tests {
use std::os::raw;
use std::any::TypeId;
use types;
#[test]
fn verify_types() {
assert_eq!(TypeId::of::<types::c_int>(), TypeId::of::<raw::c_int>());
assert_eq!(TypeId::of::<types::c_uchar>(), TypeId::of::<raw::c_uchar>());
assert_eq!(TypeId::of::<types::c_uint>(), TypeId::of::<raw::c_uint>());
assert_eq!(TypeId::of::<types::c_char>(), TypeId::of::<raw::c_char>());
}
} }