Skip to content

Commit cf22f60

Browse files
authored
Merge pull request #162 from elichai/2019-09-ffi
Fixes and tests for the ffi
2 parents 1e711f1 + 06b2beb commit cf22f60

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/ffi.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ pub type NonceFn = unsafe extern "C" fn(nonce32: *mut c_uchar,
4141
msg32: *const c_uchar,
4242
key32: *const c_uchar,
4343
algo16: *const c_uchar,
44+
data: *mut c_void,
4445
attempt: c_uint,
45-
data: *const c_void);
46+
);
4647

4748
/// Hash function to use to post-process an ECDH point to get
4849
/// a shared secret.
4950
pub type EcdhHashFn = unsafe extern "C" fn(
5051
output: *mut c_uchar,
5152
x: *const c_uchar,
5253
y: *const c_uchar,
53-
data: *const c_void,
54+
data: *mut c_void,
5455
);
5556

5657
/// A Secp256k1 context, containing various precomputed values and such
@@ -186,7 +187,7 @@ extern "C" {
186187
out_len: *mut usize, sig: *const Signature)
187188
-> c_int;
188189

189-
pub fn secp256k1_ecdsa_signature_serialize_compact(cx: *const Context, output64: *const c_uchar,
190+
pub fn secp256k1_ecdsa_signature_serialize_compact(cx: *const Context, output64: *mut c_uchar,
190191
sig: *const Signature)
191192
-> c_int;
192193

src/recovery/ffi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern "C" {
4545
input64: *const c_uchar, recid: c_int)
4646
-> c_int;
4747

48-
pub fn secp256k1_ecdsa_recoverable_signature_serialize_compact(cx: *const Context, output64: *const c_uchar,
48+
pub fn secp256k1_ecdsa_recoverable_signature_serialize_compact(cx: *const Context, output64: *mut c_uchar,
4949
recid: *mut c_int, sig: *const RecoverableSignature)
5050
-> c_int;
5151

@@ -82,7 +82,7 @@ mod fuzz_dummy {
8282
unimplemented!();
8383
}
8484

85-
pub unsafe fn secp256k1_ecdsa_recoverable_signature_serialize_compact(_cx: *const Context, _output64: *const c_uchar,
85+
pub unsafe fn secp256k1_ecdsa_recoverable_signature_serialize_compact(_cx: *const Context, _output64: *mut c_uchar,
8686
_recid: *mut c_int, _sig: *const RecoverableSignature)
8787
-> c_int {
8888
unimplemented!();

src/types.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,19 @@ impl fmt::Debug for c_void {
2323
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2424
f.pad("c_void")
2525
}
26+
}
27+
28+
#[cfg(test)]
29+
mod tests {
30+
use std::os::raw;
31+
use std::any::TypeId;
32+
use types;
33+
34+
#[test]
35+
fn verify_types() {
36+
assert_eq!(TypeId::of::<types::c_int>(), TypeId::of::<raw::c_int>());
37+
assert_eq!(TypeId::of::<types::c_uchar>(), TypeId::of::<raw::c_uchar>());
38+
assert_eq!(TypeId::of::<types::c_uint>(), TypeId::of::<raw::c_uint>());
39+
assert_eq!(TypeId::of::<types::c_char>(), TypeId::of::<raw::c_char>());
40+
}
2641
}

0 commit comments

Comments
 (0)