diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-01-09 16:07:50 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-01-09 16:48:40 +0100 |
commit | fd95fa4f42afa73d09a3d32e88acd083fef756d5 (patch) | |
tree | 7fdc3a0d8400e9abfdbed4f44267aecbab895bcd /ffi | |
parent | 2a0e31feb5359887fc7574e9957bea0905950d63 (diff) |
ffi: Use *const T for non-optional arguments.
- Previously, Option<&T> was used, primarily because it was more
ergonomic in Rust. However, this gave the impression that the
argument was optional.
- Likewise for mutable references.
- This patch addresses all pointers to Rust values.
- See #149.
Diffstat (limited to 'ffi')
-rw-r--r-- | ffi/src/core.rs | 40 | ||||
-rw-r--r-- | ffi/src/error.rs | 4 | ||||
-rw-r--r-- | ffi/src/lib.rs | 25 | ||||
-rw-r--r-- | ffi/src/net.rs | 19 | ||||
-rw-r--r-- | ffi/src/openpgp/armor.rs | 14 | ||||
-rw-r--r-- | ffi/src/openpgp/fingerprint.rs | 17 | ||||
-rw-r--r-- | ffi/src/openpgp/keyid.rs | 12 | ||||
-rw-r--r-- | ffi/src/openpgp/mod.rs | 182 | ||||
-rw-r--r-- | ffi/src/openpgp/packet_pile.rs | 16 | ||||
-rw-r--r-- | ffi/src/openpgp/tpk.rs | 92 | ||||
-rw-r--r-- | ffi/src/store.rs | 98 |
11 files changed, 263 insertions, 256 deletions
diff --git a/ffi/src/core.rs b/ffi/src/core.rs index 53bf5217..bb65d09c 100644 --- a/ffi/src/core.rs +++ b/ffi/src/core.rs @@ -62,7 +62,7 @@ impl Context { /// /// Returns and removes the last error from the context. #[no_mangle] -pub extern "system" fn sq_context_last_error(ctx: Option<&mut Context>) +pub extern "system" fn sq_context_last_error(ctx: *mut Context) -> *mut failure::Error { let ctx = ffi_param_ref_mut!(ctx); maybe_box_raw!(ctx.e.take()) @@ -133,42 +133,42 @@ pub extern "system" fn sq_context_configure(domain: *const c_char) /// Returns the domain of the context. #[no_mangle] -pub extern "system" fn sq_context_domain(ctx: Option<&Context>) -> *const c_char { +pub extern "system" fn sq_context_domain(ctx: *const Context) -> *const c_char { let ctx = ffi_param_ref!(ctx); ctx.c.domain().as_bytes().as_ptr() as *const c_char } /// Returns the directory containing shared state. #[no_mangle] -pub extern "system" fn sq_context_home(ctx: Option<&Context>) -> *const c_char { +pub extern "system" fn sq_context_home(ctx: *const Context) -> *const c_char { let ctx = ffi_param_ref!(ctx); ctx.c.home().to_string_lossy().as_ptr() as *const c_char } /// Returns the directory containing backend servers. #[no_mangle] -pub extern "system" fn sq_context_lib(ctx: Option<&Context>) -> *const c_char { +pub extern "system" fn sq_context_lib(ctx: *const Context) -> *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 { +pub extern "system" fn sq_context_network_policy(ctx: *const Context) -> 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 { +pub extern "system" fn sq_context_ipc_policy(ctx: *const Context) -> 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 { +pub extern "system" fn sq_context_ephemeral(ctx: *const Context) -> uint8_t { let ctx = ffi_param_ref!(ctx); if ctx.c.ephemeral() { 1 } else { 0 } } @@ -200,7 +200,7 @@ pub extern "system" fn sq_config_build(cfg: *mut Config, /// Sets the directory containing shared state. #[no_mangle] -pub extern "system" fn sq_config_home(cfg: Option<&mut Config>, +pub extern "system" fn sq_config_home(cfg: *mut Config, home: *const c_char) { let cfg = ffi_param_ref_mut!(cfg); assert!(! home.is_null()); @@ -212,7 +212,7 @@ pub extern "system" fn sq_config_home(cfg: Option<&mut Config>, /// Set the directory containing backend servers. #[no_mangle] -pub extern "system" fn sq_config_lib(cfg: Option<&mut Config>, +pub extern "system" fn sq_config_lib(cfg: *mut Config, lib: *const c_char) { let cfg = ffi_param_ref_mut!(cfg); assert!(! lib.is_null()); @@ -224,7 +224,7 @@ pub extern "system" fn sq_config_lib(cfg: Option<&mut Config>, /// Sets the network policy. #[no_mangle] -pub extern "system" fn sq_config_network_policy(cfg: Option<&mut Config>, +pub extern "system" fn sq_config_network_policy(cfg: *mut Config, policy: c_int) { let cfg = ffi_param_ref_mut!(cfg); if policy < 0 || policy > 3 { @@ -235,7 +235,7 @@ pub extern "system" fn sq_config_network_policy(cfg: Option<&mut Config>, /// Sets the IPC policy. #[no_mangle] -pub extern "system" fn sq_config_ipc_policy(cfg: Option<&mut Config>, +pub extern "system" fn sq_config_ipc_policy(cfg: *mut Config, policy: c_int) { let cfg = ffi_param_ref_mut!(cfg); if policy < 0 || policy > 2 { @@ -246,7 +246,7 @@ pub extern "system" fn sq_config_ipc_policy(cfg: Option<&mut Config>, /// Makes this context ephemeral. #[no_mangle] -pub extern "system" fn sq_config_ephemeral(cfg: Option<&mut Config>) { +pub extern "system" fn sq_config_ephemeral(cfg: *mut Config) { let cfg = ffi_param_ref_mut!(cfg); cfg.set_ephemeral(); } @@ -255,7 +255,7 @@ pub extern "system" fn sq_config_ephemeral(cfg: Option<&mut Config>) { /// Opens a file returning a reader. #[no_mangle] -pub extern "system" fn sq_reader_from_file(ctx: Option<&mut Context>, +pub extern "system" fn sq_reader_from_file(ctx: *mut Context, filename: *const c_char) -> *mut Box<Read> { let ctx = ffi_param_ref_mut!(ctx); @@ -296,8 +296,8 @@ pub extern "system" fn sq_reader_free(reader: *mut Box<Read>) { /// Reads up to `len` bytes into `buf`. #[no_mangle] -pub extern "system" fn sq_reader_read(ctx: Option<&mut Context>, - reader: Option<&mut Box<Read>>, +pub extern "system" fn sq_reader_read(ctx: *mut Context, + reader: *mut Box<Read>, buf: *mut uint8_t, len: size_t) -> ssize_t { let ctx = ffi_param_ref_mut!(ctx); @@ -315,7 +315,7 @@ pub extern "system" fn sq_reader_read(ctx: Option<&mut Context>, /// The file will be created if it does not exist, or be truncated /// otherwise. If you need more control, use `sq_writer_from_fd`. #[no_mangle] -pub extern "system" fn sq_writer_from_file(ctx: Option<&mut Context>, +pub extern "system" fn sq_writer_from_file(ctx: *mut Context, filename: *const c_char) -> *mut Box<Write> { let ctx = ffi_param_ref_mut!(ctx); @@ -357,8 +357,8 @@ pub extern "system" fn sq_writer_from_bytes(buf: *mut uint8_t, /// The caller is responsible to `free` it once the writer has been /// destroyed. #[no_mangle] -pub extern "system" fn sq_writer_alloc(buf: Option<&'static mut *mut c_void>, - len: Option<&'static mut size_t>) +pub extern "system" fn sq_writer_alloc(buf: *mut *mut c_void, + len: *mut size_t) -> *mut Box<Write> { let buf = ffi_param_ref_mut!(buf); let len = ffi_param_ref_mut!(len); @@ -410,8 +410,8 @@ pub extern "system" fn sq_writer_free(writer: *mut Box<Write>) { /// Writes up to `len` bytes of `buf` into `writer`. #[no_mangle] -pub extern "system" fn sq_writer_write(ctx: Option<&mut Context>, - writer: Option<&mut Box<Write>>, +pub extern "system" fn sq_writer_write(ctx: *mut Context, + writer: *mut Box<Write>, buf: *const uint8_t, len: size_t) -> ssize_t { let ctx = ffi_param_ref_mut!(ctx); diff --git a/ffi/src/error.rs b/ffi/src/error.rs index e54139d1..25640556 100644 --- a/ffi/src/error.rs +++ b/ffi/src/error.rs @@ -18,7 +18,7 @@ pub extern "system" fn sq_error_free(error: *mut failure::Error) { /// /// The returned value must be freed with `sq_string_free`. #[no_mangle] -pub extern "system" fn sq_error_string(error: Option<&failure::Error>) +pub extern "system" fn sq_error_string(error: *const failure::Error) -> *mut c_char { let error = ffi_param_ref!(error); CString::new(format!("{}", error)) @@ -29,7 +29,7 @@ pub extern "system" fn sq_error_string(error: Option<&failure::Error>) /// Returns the error status code. #[no_mangle] -pub extern "system" fn sq_error_status(error: Option<&failure::Error>) +pub extern "system" fn sq_error_status(error: *const failure::Error) -> Status { let error = ffi_param_ref!(error); error.into() diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 67312a56..8c73e1b0 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -53,19 +53,20 @@ //! # References //! //! When references are transferred across the FFI boundary, we use -//! `Option<&T>`, or `Option<&mut T>`. This takes advantage of the -//! NULL-pointer optimization that maps `NULL` to `None`, and `*p` to -//! `Some(&p)`. In Rust, references always point to some object, but -//! in C they can be `NULL`. +//! `*const T`, or `*mut T`. If the parameter is optional, a +//! `Option<&T>` or `Option<&mut T>` is used. //! //! Application code must adhere to Rust's reference rules: //! //! - Either one mutable reference or any number of immutable ones. +//! - All references are non-`NULL`. //! - All references are valid. //! //! In this crate we enforce the second rule by asserting that all -//! pointers handed in are non-`NULL` unless explicitly stated -//! (e.g. destructors may be called with a `NULL` reference). +//! pointers handed in are non-`NULL`. There are two exceptions: +//! +//! - It is explicitly stated by using `Option<&T>` or `Option<&mut T>`. +//! - Destructors (`sq_*_free`) may be called with `NULL`. //! //! # Lifetimes //! @@ -166,10 +167,12 @@ macro_rules! ffi_param_move { /// Panics if called with NULL. macro_rules! ffi_param_ref { ($name:ident) => {{ - if $name.is_none() { + if $name.is_null() { panic!("Parameter {} is NULL", stringify!($name)); } - $name.unwrap() + unsafe { + &*$name + } }}; } @@ -180,10 +183,12 @@ macro_rules! ffi_param_ref { /// Panics if called with NULL. macro_rules! ffi_param_ref_mut { ($name:ident) => {{ - if $name.is_none() { + if $name.is_null() { panic!("Parameter {} is NULL", stringify!($name)); } - $name.unwrap() + unsafe { + &mut *$name + } }}; } diff --git a/ffi/src/net.rs b/ffi/src/net.rs index 1506911a..177badea 100644 --- a/ffi/src/net.rs +++ b/ffi/src/net.rs @@ -49,7 +49,7 @@ use super::core::Context; /// /// Returns `NULL` on errors. #[no_mangle] -pub extern "system" fn sq_keyserver_new(ctx: Option<&mut Context>, +pub extern "system" fn sq_keyserver_new(ctx: *mut Context, uri: *const c_char) -> *mut KeyServer { let ctx = ffi_param_ref_mut!(ctx); let uri = unsafe { @@ -67,7 +67,7 @@ pub extern "system" fn sq_keyserver_new(ctx: Option<&mut Context>, /// /// Returns `NULL` on errors. #[no_mangle] -pub extern "system" fn sq_keyserver_with_cert(ctx: Option<&mut Context>, +pub extern "system" fn sq_keyserver_with_cert(ctx: *mut Context, uri: *const c_char, cert: *const uint8_t, len: size_t) -> *mut KeyServer { @@ -99,7 +99,7 @@ pub extern "system" fn sq_keyserver_with_cert(ctx: Option<&mut Context>, /// /// Returns `NULL` on errors. #[no_mangle] -pub extern "system" fn sq_keyserver_sks_pool(ctx: Option<&mut Context>) +pub extern "system" fn sq_keyserver_sks_pool(ctx: *mut Context) -> *mut KeyServer { let ctx = ffi_param_ref_mut!(ctx); fry_box!(ctx, KeyServer::sks_pool(&ctx.c)) @@ -115,9 +115,10 @@ pub extern "system" fn sq_keyserver_free(ks: *mut KeyServer) { /// /// Returns `NULL` on errors. #[no_mangle] -pub extern "system" fn sq_keyserver_get(ctx: Option<&mut Context>, - ks: Option<&mut KeyServer>, - id: Option<&KeyID>) -> *mut TPK { +pub extern "system" fn sq_keyserver_get(ctx: *mut Context, + ks: *mut KeyServer, + id: *const KeyID) + -> *mut TPK { let ctx = ffi_param_ref_mut!(ctx); let ks = ffi_param_ref_mut!(ks); let id = ffi_param_ref!(id); @@ -129,9 +130,9 @@ pub extern "system" fn sq_keyserver_get(ctx: Option<&mut Context>, /// /// Returns != 0 on errors. #[no_mangle] -pub extern "system" fn sq_keyserver_send(ctx: Option<&mut Context>, - ks: Option<&mut KeyServer>, - tpk: Option<&TPK>) +pub extern "system" fn sq_keyserver_send(ctx: *mut Context, + ks: *mut KeyServer, + tpk: *const TPK) -> Status { let ctx = ffi_param_ref_mut!(ctx); let ks = ffi_param_ref_mut!(ks); diff --git a/ffi/src/openpgp/armor.rs b/ffi/src/openpgp/armor.rs index f426fb0a..80b0e74c 100644 --- a/ffi/src/openpgp/armor.rs +++ b/ffi/src/openpgp/armor.rs @@ -130,7 +130,7 @@ fn kind_to_int(kind: Option<armor::Kind>) -> c_int { /// } /// ``` #[no_mangle] -pub extern "system" fn sq_armor_reader_new(inner: Option<&'static mut Box<Read>>, +pub extern "system" fn sq_armor_reader_new(inner: *mut Box<Read>, kind: c_int) -> *mut Box<Read> { let inner = ffi_param_ref_mut!(inner); @@ -141,7 +141,7 @@ pub extern "system" fn sq_armor_reader_new(inner: Option<&'static mut Box<Read>> /// Creates a `Reader` from a file. #[no_mangle] -pub extern "system" fn sq_armor_reader_from_file(ctx: Option<&mut Context>, +pub extern "system" fn sq_armor_reader_from_file(ctx: *mut Context, filename: *const c_char, kind: c_int) -> *mut Box<Read> { @@ -213,9 +213,9 @@ pub extern "system" fn sq_armor_reader_kind(reader: *mut Box<Read>) /// /// [this]: fn.sq_armor_reader_new.html #[no_mangle] -pub extern "system" fn sq_armor_reader_headers(ctx: Option<&mut Context>, +pub extern "system" fn sq_armor_reader_headers(ctx: *mut Context, reader: *mut Box<Read>, - len: Option<&mut size_t>) + len: *mut size_t) -> *mut ArmorHeader { let ctx = ffi_param_ref_mut!(ctx); let len = ffi_param_ref_mut!(len); @@ -345,10 +345,10 @@ fn strdup(s: &str) -> *mut c_char { /// ``` #[no_mangle] pub extern "system" fn sq_armor_writer_new - (ctx: Option<&mut Context>, - inner: Option<&'static mut Box<Write>>, + (ctx: *mut Context, + inner: *mut Box<Write>, kind: c_int, - header: Option<&ArmorHeader>, + header: *const ArmorHeader, header_len: size_t) -> *mut Box<Write> { diff --git a/ffi/src/openpgp/fingerprint.rs b/ffi/src/openpgp/fingerprint.rs index ee614bc4..92696601 100644 --- a/ffi/src/openpgp/fingerprint.rs +++ b/ffi/src/openpgp/fingerprint.rs @@ -46,7 +46,7 @@ pub extern "system" fn sq_fingerprint_free(fp: *mut Fingerprint) { /// Clones the Fingerprint. #[no_mangle] -pub extern "system" fn sq_fingerprint_clone(fp: Option<&Fingerprint>) +pub extern "system" fn sq_fingerprint_clone(fp: *const Fingerprint) -> *mut Fingerprint { let fp = ffi_param_ref!(fp); box_raw!(fp.clone()) @@ -54,7 +54,7 @@ pub extern "system" fn sq_fingerprint_clone(fp: Option<&Fingerprint>) /// Hashes the Fingerprint. #[no_mangle] -pub extern "system" fn sq_fingerprint_hash(fp: Option<&Fingerprint>) +pub extern "system" fn sq_fingerprint_hash(fp: *const Fingerprint) -> uint64_t { let fp = ffi_param_ref!(fp); let mut hasher = build_hasher(); @@ -67,7 +67,8 @@ pub extern "system" fn sq_fingerprint_hash(fp: Option<&Fingerprint>) /// This returns a reference to the internal buffer that is valid as /// long as the fingerprint is. #[no_mangle] -pub extern "system" fn sq_fingerprint_as_bytes(fp: Option<&Fingerprint>, fp_len: Option<&mut size_t>) +pub extern "system" fn sq_fingerprint_as_bytes(fp: *const Fingerprint, + fp_len: Option<&mut size_t>) -> *const uint8_t { let fp = ffi_param_ref!(fp); if let Some(p) = fp_len { @@ -78,7 +79,7 @@ pub extern "system" fn sq_fingerprint_as_bytes(fp: Option<&Fingerprint>, fp_len: /// Converts the fingerprint to its standard representation. #[no_mangle] -pub extern "system" fn sq_fingerprint_to_string(fp: Option<&Fingerprint>) +pub extern "system" fn sq_fingerprint_to_string(fp: *const Fingerprint) -> *mut c_char { let fp = ffi_param_ref!(fp); CString::new(fp.to_string()) @@ -88,7 +89,7 @@ pub extern "system" fn sq_fingerprint_to_string(fp: Option<&Fingerprint>) /// Converts the fingerprint to a hexadecimal number. #[no_mangle] -pub extern "system" fn sq_fingerprint_to_hex(fp: Option<&Fingerprint>) +pub extern "system" fn sq_fingerprint_to_hex(fp: *const Fingerprint) -> *mut c_char { let fp = ffi_param_ref!(fp); CString::new(fp.to_hex()) @@ -98,7 +99,7 @@ pub extern "system" fn sq_fingerprint_to_hex(fp: Option<&Fingerprint>) /// Converts the fingerprint to a key ID. #[no_mangle] -pub extern "system" fn sq_fingerprint_to_keyid(fp: Option<&Fingerprint>) +pub extern "system" fn sq_fingerprint_to_keyid(fp: *const Fingerprint) -> *mut KeyID { let fp = ffi_param_ref!(fp); Box::into_raw(Box::new(fp.to_keyid())) @@ -106,8 +107,8 @@ pub extern "system" fn sq_fingerprint_to_keyid(fp: Option<&Fingerprint>) /// Compares Fingerprints. #[no_mangle] -pub extern "system" fn sq_fingerprint_equal(a: Option<&Fingerprint>, - b: Option<&Fingerprint>) +pub extern "system" fn sq_fingerprint_equal(a: *const Fingerprint, + b: *const Fingerprint) -> bool { let a = ffi_param_ref!(a); let b = ffi_param_ref!(b); diff --git a/ffi/src/openpgp/keyid.rs b/ffi/src/openpgp/keyid.rs index 2a4e2ff6..e4e716bb 100644 --- a/ffi/src/openpgp/keyid.rs +++ b/ffi/src/openpgp/keyid.rs @@ -57,7 +57,7 @@ pub extern "system" fn sq_keyid_free(keyid: *mut KeyID) { /// Clones the KeyID. #[no_mangle] -pub extern "system" fn sq_keyid_clone(id: Option<&KeyID>) +pub extern "system" fn sq_keyid_clone(id: *const KeyID) -> *mut KeyID { let id = ffi_param_ref!(id); box_raw!(id.clone()) @@ -65,7 +65,7 @@ pub extern "system" fn sq_keyid_clone(id: Option<&KeyID>) /// Hashes the KeyID. #[no_mangle] -pub extern "system" fn sq_keyid_hash(id: Option<&KeyID>) +pub extern "system" fn sq_keyid_hash(id: *const KeyID) -> uint64_t { let id = ffi_param_ref!(id); let mut hasher = build_hasher(); @@ -75,7 +75,7 @@ pub extern "system" fn sq_keyid_hash(id: Option<&KeyID>) /// Converts the KeyID to its standard representation. #[no_mangle] -pub extern "system" fn sq_keyid_to_string(id: Option<&KeyID>) +pub extern "system" fn sq_keyid_to_string(id: *const KeyID) -> *mut c_char { let id = ffi_param_ref!(id); CString::new(id.to_string()) @@ -85,7 +85,7 @@ pub extern "system" fn sq_keyid_to_string(id: Option<&KeyID>) /// Converts the KeyID to a hexadecimal number. #[no_mangle] -pub extern "system" fn sq_keyid_to_hex(id: Option<&KeyID>) +pub extern "system" fn sq_keyid_to_hex(id: *const KeyID) -> *mut c_char { let id = ffi_param_ref!(id); CString::new(id.to_hex()) @@ -95,8 +95,8 @@ pub extern "system" fn sq_keyid_to_hex(id: Option<&KeyID>) /// Compares KeyIDs. #[no_mangle] -pub extern "system" fn sq_keyid_equal(a: Option<&KeyID>, - b: Option<&KeyID>) +pub extern "system" fn sq_keyid_equal(a: *const KeyID, + b: *const KeyID) -> bool { let a = ffi_param_ref!(a); let b = ffi_param_ref!(b); diff --git a/ffi/src/openpgp/mod.rs b/ffi/src/openpgp/mod.rs index f87b24eb..859d8096 100644 --- a/ffi/src/openpgp/mod.rs +++ b/ffi/src/openpgp/mod.rs @@ -126,10 +126,10 @@ pub extern "system" fn sq_revocation_status_free( /// Generates a new RSA 3072 bit key with UID `primary_uid`. #[no_mangle] -pub extern "system" fn sq_tsk_new(ctx: Option<&mut Context>, +pub extern "system" fn sq_tsk_new(ctx: *mut Context, primary_uid: *const c_char, - tsk_out: Option<&mut *mut TSK>, - revocation_out: Option<&mut *mut Signature>) + tsk_out: *mut *mut TSK, + revocation_out: *mut *mut Signature) -> Status { let ctx = ffi_param_ref_mut!(ctx); @@ -157,7 +157,7 @@ pub extern "system" fn sq_tsk_free(tsk: *mut TSK) { /// Returns a reference to the corresponding TPK. #[no_mangle] -pub extern "system" fn sq_tsk_tpk(tsk: Option<&TSK>) +pub extern "system" fn sq_tsk_tpk(tsk: *const TSK) -> *const TPK { let tsk = ffi_param_ref!(tsk); tsk.tpk() @@ -174,9 +174,9 @@ pub extern "system" fn sq_tsk_into_tpk(tsk: *mut TSK) /// Serializes the TSK. #[no_mangle] -pub extern "system" fn sq_tsk_serialize(ctx: Option<&mut Context>, - tsk: Option<&TSK>, - writer: Option<&mut Box<Write>>) +pub extern "system" fn sq_tsk_serialize(ctx: *mut Context, + tsk: *const TSK, + writer: *mut Box<Write>) -> Status { let ctx = ffi_param_ref_mut!(ctx); let tsk = ffi_param_ref!(tsk); @@ -198,7 +198,7 @@ pub extern "system" fn sq_packet_free(p: *mut Packet) { /// /// [Section 4.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-4.3 #[no_mangle] -pub extern "system" fn sq_packet_tag(p: Option<&Packet>) +pub extern "system" fn sq_packet_tag(p: *const Packet) -> uint8_t { let p = ffi_param_ref!(p); let tag: u8 = p.tag().into(); @@ -213,7 +213,7 @@ pub extern "system" fn sq_packet_tag(p: Option<&Packet>) /// into an `Packet::Unknown`. `tag()` returns `SQ_TAG_SIGNATURE`, /// whereas `kind()` returns `0`. #[no_mangle] -pub extern "system" fn sq_packet_kind(p: Option<&Packet>) +pub extern "system" fn sq_packet_kind(p: *const Packet) -> uint8_t { let p = ffi_param_ref!(p); if let Some(kind) = p.kind() { @@ -244,7 +244,7 @@ pub extern "system" fn sq_signature_to_packet(s: *mut Signature) /// there is no Issuer subpacket, but there is an IssuerFingerprint /// subpacket, this still returns NULL. #[no_mangle] -pub extern "system" fn sq_signature_issuer(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_issuer(sig: *const packet::Signature) -> *mut KeyID { let sig = ffi_param_ref!(sig); maybe_box_raw!(sig.issuer()) @@ -257,7 +257,7 @@ pub extern "system" fn sq_signature_issuer(sig: Option<&packet::Signature>) /// Issuer subpacket, this still returns NULL. #[no_mangle] pub extern "system" fn sq_signature_issuer_fingerprint( - sig: Option<&packet::Signature>) + sig: *const packet::Signature) -> *mut Fingerprint { let sig = ffi_param_ref!(sig); @@ -268,7 +268,7 @@ pub extern "system" fn sq_signature_issuer_fingerprint( /// Returns whether the KeyFlags indicates that the key can be used to /// make certifications. #[no_mangle] -pub extern "system" fn sq_signature_can_certify(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_can_certify(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -278,7 +278,7 @@ pub extern "system" fn sq_signature_can_certify(sig: Option<&packet::Signature>) /// Returns whether the KeyFlags indicates that the key can be used to /// make signatures. #[no_mangle] -pub extern "system" fn sq_signature_can_sign(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_can_sign(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -288,7 +288,7 @@ pub extern "system" fn sq_signature_can_sign(sig: Option<&packet::Signature>) /// Returns whether the KeyFlags indicates that the key can be used to /// encrypt data for transport. #[no_mangle] -pub extern "system" fn sq_signature_can_encrypt_for_transport(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_can_encrypt_for_transport(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -298,7 +298,7 @@ pub extern "system" fn sq_signature_can_encrypt_for_transport(sig: Option<&packe /// Returns whether the KeyFlags indicates that the key can be used to /// encrypt data at rest. #[no_mangle] -pub extern "system" fn sq_signature_can_encrypt_at_rest(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_can_encrypt_at_rest(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -308,7 +308,7 @@ pub extern "system" fn sq_signature_can_encrypt_at_rest(sig: Option<&packet::Sig /// Returns whether the KeyFlags indicates that the key can be used /// for authentication. #[no_mangle] -pub extern "system" fn sq_signature_can_authenticate(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_can_authenticate(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -318,7 +318,7 @@ pub extern "system" fn sq_signature_can_authenticate(sig: Option<&packet::Signat /// Returns whether the KeyFlags indicates that the key is a split /// key. #[no_mangle] -pub extern "system" fn sq_signature_is_split_key(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_is_split_key(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -328,7 +328,7 @@ pub extern "system" fn sq_signature_is_split_key(sig: Option<&packet::Signature> /// Returns whether the KeyFlags indicates that the key is a group /// key. #[no_mangle] -p |