Skip to content

Commit 40c3134

Browse files
committed
ffi: make function types nullable
1 parent 91eea11 commit 40c3134

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

secp256k1-sys/src/lib.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,37 @@ pub const SECP256K1_SER_COMPRESSED: c_uint = (1 << 1) | (1 << 8);
5858
/// around the FFI functions to use it. And it's an unsafe type.
5959
/// Nonces are generated deterministically by RFC6979 by
6060
/// default; there should be no need to ever change this.
61-
pub type NonceFn = unsafe extern "C" fn(nonce32: *mut c_uchar,
62-
msg32: *const c_uchar,
63-
key32: *const c_uchar,
64-
algo16: *const c_uchar,
65-
data: *mut c_void,
66-
attempt: c_uint,
67-
) -> c_int;
61+
pub type NonceFn = Option<unsafe extern "C" fn(
62+
nonce32: *mut c_uchar,
63+
msg32: *const c_uchar,
64+
key32: *const c_uchar,
65+
algo16: *const c_uchar,
66+
data: *mut c_void,
67+
attempt: c_uint,
68+
) -> c_int>;
6869

6970
/// Hash function to use to post-process an ECDH point to get
7071
/// a shared secret.
71-
pub type EcdhHashFn = unsafe extern "C" fn(
72+
pub type EcdhHashFn = Option<unsafe extern "C" fn(
7273
output: *mut c_uchar,
7374
x: *const c_uchar,
7475
y: *const c_uchar,
7576
data: *mut c_void,
76-
) -> c_int;
77+
) -> c_int>;
7778

7879
/// Same as secp256k1_nonce function with the exception of accepting an
7980
/// additional pubkey argument and not requiring an attempt argument. The pubkey
8081
/// argument can protect signature schemes with key-prefixed challenge hash
8182
/// inputs against reusing the nonce when signing with the wrong precomputed
8283
/// pubkey.
83-
pub type SchnorrNonceFn = unsafe extern "C" fn(
84+
pub type SchnorrNonceFn = Option<unsafe extern "C" fn(
8485
nonce32: *mut c_uchar,
8586
msg32: *const c_uchar,
8687
key32: *const c_uchar,
8788
xonly_pk32: *const c_uchar,
8889
algo16: *const c_uchar,
8990
data: *mut c_void,
90-
) -> c_int;
91+
) -> c_int>;
9192

9293
/// A Secp256k1 context, containing various precomputed values and such
9394
/// needed to do elliptic curve computations. If you create one of these

src/ecdh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl SharedSecret {
151151
xy.as_mut_ptr(),
152152
point.as_ptr(),
153153
scalar.as_ptr(),
154-
c_callback,
154+
Some(c_callback),
155155
ptr::null_mut(),
156156
)
157157
};

0 commit comments

Comments
 (0)