diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-01-08 18:28:43 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-01-09 12:47:41 +0100 |
commit | 2cad45090267d6936d1f107720058b7a761f8f00 (patch) | |
tree | 72f169b2861ec5ebf5423d23890f93dbfe65b1dd /ffi/src | |
parent | 3f89bf4477018c5bd75b78253c1fed68baa4e424 (diff) |
ffi: Introduce macro for passing references from C.
Diffstat (limited to 'ffi/src')
-rw-r--r-- | ffi/src/core.rs | 54 | ||||
-rw-r--r-- | ffi/src/error.rs | 4 | ||||
-rw-r--r-- | ffi/src/lib.rs | 16 | ||||
-rw-r--r-- | ffi/src/net.rs | 18 | ||||
-rw-r--r-- | ffi/src/openpgp/armor.rs | 14 | ||||
-rw-r--r-- | ffi/src/openpgp/fingerprint.rs | 12 | ||||
-rw-r--r-- | ffi/src/openpgp/keyid.rs | 8 | ||||
-rw-r--r-- | ffi/src/openpgp/mod.rs | 174 | ||||
-rw-r--r-- | ffi/src/openpgp/packet_pile.rs | 16 | ||||
-rw-r--r-- | ffi/src/openpgp/tpk.rs | 80 | ||||
-rw-r--r-- | ffi/src/store.rs | 98 |
11 files changed, 255 insertions, 239 deletions
diff --git a/ffi/src/core.rs b/ffi/src/core.rs index e31513a5..564f3ae8 100644 --- a/ffi/src/core.rs +++ b/ffi/src/core.rs @@ -64,7 +64,7 @@ impl Context { #[no_mangle] pub extern "system" fn sq_context_last_error(ctx: Option<&mut Context>) -> *mut failure::Error { - let ctx = ctx.expect("Context is NULL"); + let ctx = ffi_param_ref!(ctx); maybe_box_raw!(ctx.e.take()) } @@ -148,29 +148,29 @@ pub extern "system" fn sq_context_home(ctx: Option<&Context>) -> *const c_char { /// Returns the directory containing backend servers. #[no_mangle] pub extern "system" fn sq_context_lib(ctx: Option<&Context>) -> *const c_char { - assert!(ctx.is_some()); - ctx.unwrap().c.lib().to_string_lossy().as_bytes().as_ptr() as *const c_char + let ctx = ffi_param_ref!(ctx); + ctx.c.lib().to_string_lossy().as_bytes().as_ptr() as *const c_char } /// Returns the network policy. #[no_mangle] pub extern "system" fn sq_context_network_policy(ctx: Option<&Context>) -> c_int { - assert!(ctx.is_some()); - u8::from(ctx.unwrap().c.network_policy()) as c_int + let ctx = ffi_param_ref!(ctx); + u8::from(ctx.c.network_policy()) as c_int } /// Returns the IPC policy. #[no_mangle] pub extern "system" fn sq_context_ipc_policy(ctx: Option<&Context>) -> c_int { - assert!(ctx.is_some()); - u8::from(ctx.unwrap().c.ipc_policy()) as c_int + let ctx = ffi_param_ref!(ctx); + u8::from(ctx.c.ipc_policy()) as c_int } /// Returns whether or not this is an ephemeral context. #[no_mangle] pub extern "system" fn sq_context_ephemeral(ctx: Option<&Context>) -> uint8_t { - assert!(ctx.is_some()); - if ctx.unwrap().c.ephemeral() { 1 } else { 0 } + let ctx = ffi_param_ref!(ctx); + if ctx.c.ephemeral() { 1 } else { 0 } } @@ -203,53 +203,53 @@ pub extern "system" fn sq_config_build(cfg: Option<&mut Config>, #[no_mangle] pub extern "system" fn sq_config_home(cfg: Option<&mut Config>, home: *const c_char) { - assert!(cfg.is_some()); + let cfg = ffi_param_ref!(cfg); assert!(! home.is_null()); let home = unsafe { CStr::from_ptr(home).to_string_lossy() }; - cfg.unwrap().set_home(home.as_ref()) + cfg.set_home(home.as_ref()) } /// Set the directory containing backend servers. #[no_mangle] pub extern "system" fn sq_config_lib(cfg: Option<&mut Config>, lib: *const c_char) { - assert!(cfg.is_some()); + let cfg = ffi_param_ref!(cfg); assert!(! lib.is_null()); let lib = unsafe { CStr::from_ptr(lib).to_string_lossy() }; - cfg.unwrap().set_lib(&lib.as_ref()) + cfg.set_lib(&lib.as_ref()) } /// Sets the network policy. #[no_mangle] pub extern "system" fn sq_config_network_policy(cfg: Option<&mut Config>, policy: c_int) { - assert!(cfg.is_some()); + let cfg = ffi_param_ref!(cfg); if policy < 0 || policy > 3 { panic!("Bad network policy: {}", policy); } - cfg.unwrap().set_network_policy((policy as u8).into()); + cfg.set_network_policy((policy as u8).into()); } /// Sets the IPC policy. #[no_mangle] pub extern "system" fn sq_config_ipc_policy(cfg: Option<&mut Config>, policy: c_int) { - assert!(cfg.is_some()); + let cfg = ffi_param_ref!(cfg); if policy < 0 || policy > 2 { panic!("Bad ipc policy: {}", policy); } - cfg.unwrap().set_ipc_policy((policy as u8).into()); + cfg.set_ipc_policy((policy as u8).into()); } /// Makes this context ephemeral. #[no_mangle] pub extern "system" fn sq_config_ephemeral(cfg: Option<&mut Config>) { - assert!(cfg.is_some()); - cfg.unwrap().set_ephemeral(); + let cfg = ffi_param_ref!(cfg); + cfg.set_ephemeral(); } /* Reader and writer. */ @@ -259,7 +259,7 @@ pub extern "system" fn sq_config_ephemeral(cfg: Option<&mut Config>) { pub extern "system" fn sq_reader_from_file(ctx: Option<&mut Context>, filename: *const c_char) -> *mut Box<Read> { - let ctx = ctx.expect("Context is NULL"); + let ctx = ffi_param_ref!(ctx); assert!(! filename.is_null()); let filename = unsafe { CStr::from_ptr(filename).to_string_lossy().into_owned() @@ -301,8 +301,8 @@ pub extern "system" fn sq_reader_read(ctx: Option<&mut Context>, reader: Option<&mut Box<Read>>, buf: *mut uint8_t, len: size_t) -> ssize_t { - let ctx = ctx.expect("Context is NULL"); - let reader = reader.expect("Reader is NULL"); + let ctx = ffi_param_ref!(ctx); + let reader = ffi_param_ref!(reader); assert!(!buf.is_null()); let buf = unsafe { slice::from_raw_parts_mut(buf, len as usize) @@ -319,7 +319,7 @@ pub extern "system" fn sq_reader_read(ctx: Option<&mut Context>, pub extern "system" fn sq_writer_from_file(ctx: Option<&mut Context>, filename: *const c_char) -> *mut Box<Write> { - let ctx = ctx.expect("Context is NULL"); + let ctx = ffi_param_ref!(ctx); assert!(! filename.is_null()); let filename = unsafe { CStr::from_ptr(filename).to_string_lossy().into_owned() @@ -361,8 +361,8 @@ pub extern "system" fn sq_writer_from_bytes(buf: *mut uint8_t, pub extern "system" fn sq_writer_alloc(buf: Option<&'static mut *mut c_void>, len: Option<&'static mut size_t>) -> *mut Box<Write> { - let buf = buf.expect("BUF is NULL"); - let len = len.expect("LEN is NULL"); + let buf = ffi_param_ref!(buf); + let len = ffi_param_ref!(len); box_raw!(Box::new(WriterAlloc { buf: buf, @@ -415,8 +415,8 @@ pub extern "system" fn sq_writer_write(ctx: Option<&mut Context>, writer: Option<&mut Box<Write>>, buf: *const uint8_t, len: size_t) -> ssize_t { - let ctx = ctx.expect("Context is NULL"); - let writer = writer.expect("Writer is NULL"); + let ctx = ffi_param_ref!(ctx); + let writer = ffi_param_ref!(writer); assert!(!buf.is_null()); let buf = unsafe { slice::from_raw_parts(buf, len as usize) diff --git a/ffi/src/error.rs b/ffi/src/error.rs index 05a1998a..e54139d1 100644 --- a/ffi/src/error.rs +++ b/ffi/src/error.rs @@ -20,7 +20,7 @@ pub extern "system" fn sq_error_free(error: *mut failure::Error) { #[no_mangle] pub extern "system" fn sq_error_string(error: Option<&failure::Error>) -> *mut c_char { - let error = error.expect("Error is NULL"); + let error = ffi_param_ref!(error); CString::new(format!("{}", error)) .map(|s| s.into_raw()) .unwrap_or(CString::new("Failed to convert error into string") @@ -31,7 +31,7 @@ pub extern "system" fn sq_error_string(error: Option<&failure::Error>) #[no_mangle] pub extern "system" fn sq_error_status(error: Option<&failure::Error>) -> Status { - let error = error.expect("Error is NULL"); + let error = ffi_param_ref!(error); error.into() } diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index c9410816..3dd0a252 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -141,6 +141,22 @@ macro_rules! ffi_free { }}; } +/* Parameter handling. */ + +/// Transfers a reference from C to Rust. +/// +/// # Panics +/// +/// Panics if called with NULL. +macro_rules! ffi_param_ref { + ($name:ident) => {{ + if $name.is_none() { + panic!("Parameter {} is NULL", stringify!($name)); + } + $name.unwrap() + }}; +} + /// Like try! for ffi glue. /// /// Evaluates the given expression. On success, evaluate to diff --git a/ffi/src/net.rs b/ffi/src/net.rs index bd98bca1..25e1313a 100644 --- a/ffi/src/net.rs +++ b/ffi/src/net.rs @@ -51,7 +51,7 @@ use super::core::Context; #[no_mangle] pub extern "system" fn sq_keyserver_new(ctx: Option<&mut Context>, uri: *const c_char) -> *mut KeyServer { - let ctx = ctx.expect("Context is NULL"); + let ctx = ffi_param_ref!(ctx); let uri = unsafe { if uri.is_null() { None } else { Some(CStr::from_ptr(uri)) } }; @@ -71,7 +71,7 @@ pub extern "system" fn sq_keyserver_with_cert(ctx: Option<&mut Context>, uri: *const c_char, cert: *const uint8_t, len: size_t) -> *mut KeyServer { - let ctx = ctx.expect("Context is NULL"); + let ctx = ffi_param_ref!(ctx); let uri = unsafe { if uri.is_null() { None } else { Some(CStr::from_ptr(uri)) } }; @@ -101,7 +101,7 @@ pub extern "system" fn sq_keyserver_with_cert(ctx: Option<&mut Context>, #[no_mangle] pub extern "system" fn sq_keyserver_sks_pool(ctx: Option<&mut Context>) -> *mut KeyServer { - let ctx = ctx.expect("Context is NULL"); + let ctx = ffi_param_ref!(ctx); fry_box!(ctx, KeyServer::sks_pool(&ctx.c)) } @@ -118,9 +118,9 @@ pub extern "system" fn sq_keyserver_free(ks: *mut KeyServer) { pub extern "system" fn sq_keyserver_get(ctx: Option<&mut Context>, ks: Option<&mut KeyServer>, id: Option<&KeyID>) -> *mut TPK { - let ctx = ctx.expect("Context is NULL"); - let ks = ks.expect("KeyServer is NULL"); - let id = id.expect("KeyID is NULL"); + let ctx = ffi_param_ref!(ctx); + let ks = ffi_param_ref!(ks); + let id = ffi_param_ref!(id); fry_box!(ctx, ks.get(&id)) } @@ -133,9 +133,9 @@ pub extern "system" fn sq_keyserver_send(ctx: Option<&mut Context>, ks: Option<&mut KeyServer>, tpk: Option<&TPK>) -> Status { - let ctx = ctx.expect("Context is NULL"); - let ks = ks.expect("KeyServer is NULL"); - let tpk = tpk.expect("TPK is NULL"); + let ctx = ffi_param_ref!(ctx); + let ks = ffi_param_ref!(ks); + let tpk = ffi_param_ref!(tpk); fry_status!(ctx, ks.send(tpk)) } diff --git a/ffi/src/openpgp/armor.rs b/ffi/src/openpgp/armor.rs index 698018f6..9e6b3611 100644 --- a/ffi/src/openpgp/armor.rs +++ b/ffi/src/openpgp/armor.rs @@ -133,7 +133,7 @@ fn kind_to_int(kind: Option<armor::Kind>) -> c_int { pub extern "system" fn sq_armor_reader_new(inner: Option<&'static mut Box<Read>>, kind: c_int) -> *mut Box<Read> { - let inner = inner.expect("Inner is NULL"); + let inner = ffi_param_ref!(inner); let kind = int_to_kind(kind); box_raw!(Box::new(armor::Reader::new(inner, kind))) @@ -145,7 +145,7 @@ pub extern "system" fn sq_armor_reader_from_file(ctx: Option<&mut Context>, filename: *const c_char, kind: c_int) -> *mut Box<Read> { - let ctx = ctx.expect("Context is NULL"); + let ctx = ffi_param_ref!(ctx); assert!(! filename.is_null()); let filename = unsafe { CStr::from_ptr(filename).to_string_lossy().into_owned() @@ -220,9 +220,9 @@ pub extern "system" fn sq_armor_reader_headers(ctx: Option<&mut Context>, reader: *mut Box<Read>, len: Option<&mut size_t>) -> *mut ArmorHeader { - let ctx = ctx.expect("Context is NULL"); + let ctx = ffi_param_ref!(ctx); assert!(! reader.is_null()); - let len = len.expect("LEN is NULL"); + let len = ffi_param_ref!(len); // We need to downcast `reader`. To do that, we need to do a // little dance. We will momentarily take ownership of `reader`, @@ -358,13 +358,13 @@ pub extern "system" fn sq_armor_writer_new header_len: size_t) -> *mut Box<Write> { - let ctx = ctx.expect("Context is NULL"); - let inner = inner.expect("Inner is NULL"); + let ctx = ffi_param_ref!(ctx); + let inner = ffi_param_ref!(inner); let kind = int_to_kind(kind).expect("KIND must not be SQ_ARMOR_KIND_ANY"); let mut header_ = Vec::new(); if header_len > 0 { - let header = header.expect("HEADER is NULL"); + let header = ffi_param_ref!(header); let header = unsafe { slice::from_raw_parts(header, header_len) }; diff --git a/ffi/src/openpgp/fingerprint.rs b/ffi/src/openpgp/fingerprint.rs index 3c2a38ad..5713b961 100644 --- a/ffi/src/openpgp/fingerprint.rs +++ b/ffi/src/openpgp/fingerprint.rs @@ -48,7 +48,7 @@ pub extern "system" fn sq_fingerprint_free(fp: *mut Fingerprint) { #[no_mangle] pub extern "system" fn sq_fingerprint_clone(fp: Option<&Fingerprint>) -> *mut Fingerprint { - let fp = fp.expect("Fingerprint is NULL"); + let fp = ffi_param_ref!(fp); box_raw!(fp.clone()) } @@ -56,7 +56,7 @@ pub extern "system" fn sq_fingerprint_clone(fp: Option<&Fingerprint>) #[no_mangle] pub extern "system" fn sq_fingerprint_hash(fp: Option<&Fingerprint>) -> uint64_t { - let fp = fp.expect("Fingerprint is NULL"); + let fp = ffi_param_ref!(fp); let mut hasher = build_hasher(); fp.hash(&mut hasher); hasher.finish() @@ -69,7 +69,7 @@ pub extern "system" fn sq_fingerprint_hash(fp: Option<&Fingerprint>) #[no_mangle] pub extern "system" fn sq_fingerprint_as_bytes(fp: Option<&Fingerprint>, fp_len: Option<&mut size_t>) -> *const uint8_t { - let fp = fp.expect("Fingerprint is NULL"); + let fp = ffi_param_ref!(fp); if let Some(p) = fp_len { *p = fp.as_slice().len(); } @@ -80,7 +80,7 @@ pub extern "system" fn sq_fingerprint_as_bytes(fp: Option<&Fingerprint>, fp_len: #[no_mangle] pub extern "system" fn sq_fingerprint_to_string(fp: Option<&Fingerprint>) -> *mut c_char { - let fp = fp.expect("Fingerprint is NULL"); + let fp = ffi_param_ref!(fp); CString::new(fp.to_string()) .unwrap() // Errors only on internal nul bytes. .into_raw() @@ -90,7 +90,7 @@ pub extern "system" fn sq_fingerprint_to_string(fp: Option<&Fingerprint>) #[no_mangle] pub extern "system" fn sq_fingerprint_to_hex(fp: Option<&Fingerprint>) -> *mut c_char { - let fp = fp.expect("Fingerprint is NULL"); + let fp = ffi_param_ref!(fp); CString::new(fp.to_hex()) .unwrap() // Errors only on internal nul bytes. .into_raw() @@ -100,7 +100,7 @@ pub extern "system" fn sq_fingerprint_to_hex(fp: Option<&Fingerprint>) #[no_mangle] pub extern "system" fn sq_fingerprint_to_keyid(fp: Option<&Fingerprint>) -> *mut KeyID { - let fp = fp.expect("Fingerprint is NULL"); + let fp = ffi_param_ref!(fp); Box::into_raw(Box::new(fp.to_keyid())) } diff --git a/ffi/src/openpgp/keyid.rs b/ffi/src/openpgp/keyid.rs index bc4a2ace..8b64d2f8 100644 --- a/ffi/src/openpgp/keyid.rs +++ b/ffi/src/openpgp/keyid.rs @@ -59,7 +59,7 @@ pub extern "system" fn sq_keyid_free(keyid: *mut KeyID) { #[no_mangle] pub extern "system" fn sq_keyid_clone(id: Option<&KeyID>) -> *mut KeyID { - let id = id.expect("KeyID is NULL"); + let id = ffi_param_ref!(id); box_raw!(id.clone()) } @@ -67,7 +67,7 @@ pub extern "system" fn sq_keyid_clone(id: Option<&KeyID>) #[no_mangle] pub extern "system" fn sq_keyid_hash(id: Option<&KeyID>) -> uint64_t { - let id = id.expect("KeyID is NULL"); + let id = ffi_param_ref!(id); let mut hasher = build_hasher(); id.hash(&mut hasher); hasher.finish() @@ -77,7 +77,7 @@ pub extern "system" fn sq_keyid_hash(id: Option<&KeyID>) #[no_mangle] pub extern "system" fn sq_keyid_to_string(id: Option<&KeyID>) -> *mut c_char { - let id = id.expect("KeyID is NULL"); + let id = ffi_param_ref!(id); CString::new(id.to_string()) .unwrap() // Errors only on internal nul bytes. .into_raw() @@ -87,7 +87,7 @@ pub extern "system" fn sq_keyid_to_string(id: Option<&KeyID>) #[no_mangle] pub extern "system" fn sq_keyid_to_hex(id: Option<&KeyID>) -> *mut c_char { - let id = id.expect("KeyID is NULL"); + let id = ffi_param_ref!(id); CString::new(id.to_hex()) .unwrap() // Errors only on internal nul bytes. .into_raw() diff --git a/ffi/src/openpgp/mod.rs b/ffi/src/openpgp/mod.rs index 9dc9548c..cef143af 100644 --- a/ffi/src/openpgp/mod.rs +++ b/ffi/src/openpgp/mod.rs @@ -135,10 +135,10 @@ pub extern "system" fn sq_tsk_new(ctx: Option<&mut Context>, revocation_out: Option<&mut *mut Signature>) -> Status { - let ctx = ctx.expect("CONTEXT is NULL"); + let ctx = ffi_param_ref!(ctx); assert!(!primary_uid.is_null()); - let tsk_out = tsk_out.expect("TSK is NULL"); - let revocation_out = revocation_out.expect("REVOCATION is NULL"); + let tsk_out = ffi_param_ref!(tsk_out); + let revocation_out = ffi_param_ref!(revocation_out); let primary_uid = unsafe { CStr::from_ptr(primary_uid) }; @@ -162,7 +162,7 @@ pub extern "system" fn sq_tsk_free(tsk: *mut TSK) { #[no_mangle] pub extern "system" fn sq_tsk_tpk(tsk: Option<&TSK>) -> &TPK { - let tsk = tsk.expect("TSK is NULL"); + let tsk = ffi_param_ref!(tsk); tsk.tpk() } @@ -183,9 +183,9 @@ pub extern "system" fn sq_tsk_serialize(ctx: Option<&mut Context>, tsk: Option<&TSK>, writer: Option<&mut Box<Write>>) -> Status { - let ctx = ctx.expect("Context is NULL"); - let tsk = tsk.expect("TSK is NULL"); - let writer = writer.expect("Writer is NULL"); + let ctx = ffi_param_ref!(ctx); + let tsk = ffi_param_ref!(tsk); + let writer = ffi_param_ref!(writer); fry_status!(ctx, tsk.serialize(writer)) } @@ -205,7 +205,7 @@ pub extern "system" fn sq_packet_free(p: *mut Packet) { #[no_mangle] pub extern "system" fn sq_packet_tag(p: Option<&Packet>) -> uint8_t { - let p = p.expect("Packet is NULL"); + let p = ffi_param_ref!(p); let tag: u8 = p.tag().into(); tag as uint8_t } @@ -220,7 +220,7 @@ pub extern "system" fn sq_packet_tag(p: Option<&Packet>) #[no_mangle] pub extern "system" fn sq_packet_kind(p: Option<&Packet>) -> uint8_t { - let p = p.expect("Packet is NULL"); + let p = ffi_param_ref!(p); if let Some(kind) = p.kind() { kind.into() } else { @@ -253,7 +253,7 @@ pub extern "system" fn sq_signature_to_packet(s: *mut Signature) #[no_mangle] pub extern "system" fn sq_signature_issuer(sig: Option<&packet::Signature>) -> *mut KeyID { - let sig = sig.expect("Signature is NULL"); + let sig = ffi_param_ref!(sig); maybe_box_raw!(sig.issuer()) } @@ -267,7 +267,7 @@ pub extern "system" fn sq_signature_issuer_fingerprint( sig: Option<&packet::Signature>) -> *mut Fingerprint { - let sig = sig.expect("Signature is NULL"); + let sig = ffi_param_ref!(sig); maybe_box_raw!(sig.issuer_fingerprint()) } @@ -278,7 +278,7 @@ pub extern "system" fn sq_signature_issuer_fingerprint( pub extern "system" fn sq_signature_can_certify(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.key_flags().can_certify() } @@ -288,7 +288,7 @@ pub extern "system" fn sq_signature_can_certify(sig: Option<&packet::Signature>) pub extern "system" fn sq_signature_can_sign(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.key_flags().can_sign() } @@ -298,7 +298,7 @@ pub extern "system" fn sq_signature_can_sign(sig: Option<&packet::Signature>) pub extern "system" fn sq_signature_can_encrypt_for_transport(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.key_flags().can_encrypt_for_transport() } @@ -308,7 +308,7 @@ pub extern "system" fn sq_signature_can_encrypt_for_transport(sig: Option<&packe pub extern "system" fn sq_signature_can_encrypt_at_rest(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.key_flags().can_encrypt_at_rest() } @@ -318,7 +318,7 @@ pub extern "system" fn sq_signature_can_encrypt_at_rest(sig: Option<&packet::Sig pub extern "system" fn sq_signature_can_authenticate(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.key_flags().can_authenticate() } @@ -328,7 +328,7 @@ pub extern "system" fn sq_signature_can_authenticate(sig: Option<&packet::Signat pub extern "system" fn sq_signature_is_split_key(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.key_flags().is_split_key() } @@ -338,7 +338,7 @@ pub extern "system" fn sq_signature_is_split_key(sig: Option<&packet::Signature> pub extern "system" fn sq_signature_is_group_key(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.key_flags().is_group_key() } @@ -351,7 +351,7 @@ pub extern "system" fn sq_signature_is_group_key(sig: Option<&packet::Signature> pub extern "system" fn sq_signature_alive(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.signature_alive() } @@ -364,7 +364,7 @@ pub extern "system" fn sq_signature_alive_at(sig: Option<&packet::Signature>, when: time_t) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.signature_alive_at(time::at(time::Timespec::new(when as i64, 0))) } @@ -373,7 +373,7 @@ pub extern "system" fn sq_signature_alive_at(sig: Option<&packet::Signature>, pub extern "system" fn sq_signature_expired(sig: Option<&packet::Signature>) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.signature_expired() } @@ -383,7 +383,7 @@ pub extern "system" fn sq_signature_expired_at(sig: Option<&packet::Signature>, when: time_t) -> bool { - let sig = sig.expect("Sig is NULL"); + let sig = ffi_param_ref!(sig); sig.signature_expired_at(time::at(time::Timespec::new(when as i64, 0))) } @@ -392,7 +392,7 @@ pub extern "system" fn sq_signature_expired_at(sig: Option<&packet::Signature>, #[no_mangle] pub extern "system" fn sq_p_key_clone(key: Option<&packet::Key>) -> *mut packet::Key { - let key = key.expect("Key is NULL"); + let key = ffi_param_ref!(key); box_raw!(key.clone()) } @@ -401,7 +401,7 @@ pub extern "system" fn sq_p_key_clone(key: Option<&packet::Key>) #[no_mangle] pub extern "system" fn sq_p_key_fingerprint(key: Option<&packet::Key>) -> *mut Fingerprint { - let key = key.expect("Key is NULL"); + let key = ffi_param_ref!(key); box_raw!(key.fingerprint()) } @@ -410,7 +410,7 @@ pub extern "system" fn sq_p_key_fingerprint(key: Option<&packet::Key>) #[no_mangle] pub extern "system" fn sq_p_key_keyid(key: Option<&packet::Key>) -> *mut KeyID { - let key = key.expect("Key is NULL"); + let key = ffi_param_ref!(key); box_raw!(key.keyid()) } @@ -425,8 +425,8 @@ pub extern "system" fn sq_p_key_expired(key: Option<&packet::Key>, sig: Option<&packet::Signature>) -> bool { - let key = key.expect("Key is NULL"); - let sig = sig.expect("SIG is NULL"); + let key = ffi_param_ref!(key); + let sig = ffi_param_ref!(sig); sig.key_expired(key) } @@ -438,8 +438,8 @@ pub extern "system" fn sq_p_key_expired_at(key: Option<&packet::Key>, when: time_t) -> bool { - let key = key.expect("Key is NULL"); - let sig = sig.expect("SIG is NULL"); + let key = ffi_param_ref!(key); + let sig = ffi_param_ref!(sig); sig.key_expired_at(key, time::at(time::Timespec::new(when as i64, 0))) } @@ -458,8 +458,8 @@ pub extern "system" fn sq_p_key_alive(key: Option<&packet::Key>, sig: Option<&packet::Signature>) -> bool { - let key = key.expect("Key is NULL"); - let sig = sig.expect("SIG is NULL"); + let key = |