From fd95fa4f42afa73d09a3d32e88acd083fef756d5 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 9 Jan 2019 16:07:50 +0100 Subject: 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. --- ffi/src/core.rs | 40 ++++----- ffi/src/error.rs | 4 +- ffi/src/lib.rs | 25 +++--- ffi/src/net.rs | 19 +++-- ffi/src/openpgp/armor.rs | 14 ++-- ffi/src/openpgp/fingerprint.rs | 17 ++-- ffi/src/openpgp/keyid.rs | 12 +-- ffi/src/openpgp/mod.rs | 182 ++++++++++++++++++++--------------------- ffi/src/openpgp/packet_pile.rs | 16 ++-- ffi/src/openpgp/tpk.rs | 92 ++++++++++----------- ffi/src/store.rs | 98 +++++++++++----------- 11 files changed, 263 insertions(+), 256 deletions(-) (limited to 'ffi') 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 { let ctx = ffi_param_ref_mut!(ctx); @@ -296,8 +296,8 @@ pub extern "system" fn sq_reader_free(reader: *mut Box) { /// Reads up to `len` bytes into `buf`. #[no_mangle] -pub extern "system" fn sq_reader_read(ctx: Option<&mut Context>, - reader: Option<&mut Box>, +pub extern "system" fn sq_reader_read(ctx: *mut Context, + reader: *mut Box, 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 { 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 { 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) { /// 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>, +pub extern "system" fn sq_writer_write(ctx: *mut Context, + writer: *mut Box, 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) -> c_int { /// } /// ``` #[no_mangle] -pub extern "system" fn sq_armor_reader_new(inner: Option<&'static mut Box>, +pub extern "system" fn sq_armor_reader_new(inner: *mut Box, kind: c_int) -> *mut Box { let inner = ffi_param_ref_mut!(inner); @@ -141,7 +141,7 @@ pub extern "system" fn sq_armor_reader_new(inner: Option<&'static mut Box> /// 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 { @@ -213,9 +213,9 @@ pub extern "system" fn sq_armor_reader_kind(reader: *mut Box) /// /// [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, - 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>, + (ctx: *mut Context, + inner: *mut Box, kind: c_int, - header: Option<&ArmorHeader>, + header: *const ArmorHeader, header_len: size_t) -> *mut Box { 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>) +pub extern "system" fn sq_tsk_serialize(ctx: *mut Context, + tsk: *const TSK, + writer: *mut Box) -> 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] -pub extern "system" fn sq_signature_is_group_key(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_is_group_key(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -341,7 +341,7 @@ pub extern "system" fn sq_signature_is_group_key(sig: Option<&packet::Signature> /// A signature is alive if the creation date is in the past, and the /// signature has not expired. #[no_mangle] -pub extern "system" fn sq_signature_alive(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_alive(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -353,7 +353,7 @@ pub extern "system" fn sq_signature_alive(sig: Option<&packet::Signature>) /// A signature is alive if the creation date is in the past, and the /// signature has not expired at the specified time. #[no_mangle] -pub extern "system" fn sq_signature_alive_at(sig: Option<&packet::Signature>, +pub extern "system" fn sq_signature_alive_at(sig: *const packet::Signature, when: time_t) -> bool { @@ -363,7 +363,7 @@ pub extern "system" fn sq_signature_alive_at(sig: Option<&packet::Signature>, /// Returns whether the signature is expired. #[no_mangle] -pub extern "system" fn sq_signature_expired(sig: Option<&packet::Signature>) +pub extern "system" fn sq_signature_expired(sig: *const packet::Signature) -> bool { let sig = ffi_param_ref!(sig); @@ -372,7 +372,7 @@ pub extern "system" fn sq_signature_expired(sig: Option<&packet::Signature>) /// Returns whether the signature is expired at the specified time. #[no_mangle] -pub extern "system" fn sq_signature_expired_at(sig: Option<&packet::Signature>, +pub extern "system" fn sq_signature_expired_at(sig: *const packet::Signature, when: time_t) -> bool { @@ -383,7 +383,7 @@ pub extern "system" fn sq_signature_expired_at(sig: Option<&packet::Signature>, /// Clones the key. #[no_mangle] -pub extern "system" fn sq_p_key_clone(key: Option<&packet::Key>) +pub extern "system" fn sq_p_key_clone(key: *const packet::Key) -> *mut packet::Key { let key = ffi_param_ref!(key); box_raw!(key.clone()) @@ -392,7 +392,7 @@ pub extern "system" fn sq_p_key_clone(key: Option<&packet::Key>) /// Computes and returns the key's fingerprint as per Section 12.2 /// of RFC 4880. #[no_mangle] -pub extern "system" fn sq_p_key_fingerprint(key: Option<&packet::Key>) +pub extern "system" fn sq_p_key_fingerprint(key: *const packet::Key) -> *mut Fingerprint { let key = ffi_param_ref!(key); box_raw!(key.fingerprint()) @@ -401,7 +401,7 @@ pub extern "system" fn sq_p_key_fingerprint(key: Option<&packet::Key>) /// Computes and returns the key's key ID as per Section 12.2 of RFC /// 4880. #[no_mangle] -pub extern "system" fn sq_p_key_keyid(key: Option<&packet::Key>) +pub extern "system" fn sq_p_key_keyid(key: *const packet::Key) -> *mut KeyID { let key = ffi_param_ref!(key); box_raw!(key.keyid()) @@ -414,8 +414,8 @@ pub extern "system" fn sq_p_key_keyid(key: Option<&packet::Key>) /// checked for validity. That is, we do not check whether the /// signature is a valid self-signature for the given key. #[no_mangle] -pub extern "system" fn sq_p_key_expired(key: Option<&packet::Key>, - sig: Option<&packet::Signature>) +pub extern "system" fn sq_p_key_expired(key: *const packet::Key, + sig: *const packet::Signature) -> bool { let key = ffi_param_ref!(key); @@ -426,8 +426,8 @@ pub extern "system" fn sq_p_key_expired(key: Option<&packet::Key>, /// Like sq_p_key_expired, but at a specific time. #[no_mangle] -pub extern "system" fn sq_p_key_expired_at(key: Option<&packet::Key>, - sig: Option<&packet::Signature>, +pub extern "system" fn sq_p_key_expired_at(key: *const packet::Key, + sig: *const packet::Signature, when: time_t) -> bool { @@ -447,8 +447,8 @@ pub extern "system" fn sq_p_key_expired_at(key: Option<&packet::Key>, /// checked for validity. That is, we do not check whether the /// signature is a valid self-signature for the given key. #[no_mangle] -pub extern "system" fn sq_p_key_alive(key: Option<&packet::Key>, - sig: Option<&packet::Signature>) +pub extern "system" fn sq_p_key_alive(key: *const packet::Key, + sig: *const packet::Signature) -> bool { let key = ffi_param_ref!(key); @@ -459,8 +459,8 @@ pub extern "system" fn sq_p_key_alive(key: Option<&packet::Key>, /// Like sq_p_key_alive, but at a specific time. #[no_mangle] -pub extern "system" fn sq_p_key_alive_at(key: Option<&packet::Key>, - sig: Option<&packet::Signature>, +pub extern "system" fn sq_p_key_alive_at(key: *const packet::Key, + sig: *const packet::Signature, when: time_t) -> bool { @@ -472,7 +472,7 @@ pub extern "system" fn sq_p_key_alive_at(key: Option<&packet::Key>, /// Returns the key's creation time. #[no_mangle] -pub extern "system" fn sq_p_key_creation_time(key: Option<&packet::Key>) +pub extern "system" fn sq_p_key_creation_time(key: *const packet::Key) -> u32 { let key = ffi_param_ref!(key); @@ -483,7 +483,7 @@ pub extern "system" fn sq_p_key_creation_time(key: Option<&packet::Key>) /// Returns the key's public key algorithm. #[no_mangle] -pub extern "system" fn sq_p_key_public_key_algo(key: Option<&packet::Key>) +pub extern "system" fn sq_p_key_public_key_algo(key: *const packet::Key) -> c_int { let key = ffi_param_ref!(key); @@ -493,7 +493,7 @@ pub extern "system" fn sq_p_key_public_key_algo(key: Option<&packet::Key>) /// Returns the public key's size in bits. #[no_mangle] -pub extern "system" fn sq_p_key_public_key_bits(key: Option<&packet::Key>) +pub extern "system" fn sq_p_key_public_key_bits(key: *const packet::Key) -> c_int { use self::openpgp::crypto::mpis::PublicKey::*; @@ -515,7 +515,7 @@ pub extern "system" fn sq_p_key_public_key_bits(key: Option<&packet::Key>) /// The returned pointer is valid until `uid` is deallocated. If /// `value_len` is not `NULL`, the size of value is stored there. #[no_mangle] -pub extern "system" fn sq_user_id_value(uid: Option<&Packet>, +pub extern "system" fn sq_user_id_value(uid: *const Packet, value_len: Option<&mut size_t>) -> *const uint8_t { let uid = ffi_param_ref!(uid); @@ -534,7 +534,7 @@ pub extern "system" fn sq_user_id_value(uid: Option<&Packet>, /// The returned pointer is valid until `ua` is deallocated. If /// `value_len` is not `NULL`, the size of value is stored there. #[no_mangle] -pub extern "system" fn sq_user_attribute_value(ua: Option<&Packet>, +pub extern "system" fn sq_user_attribute_value(ua: *const Packet, value_len: Option<&mut size_t>) -> *const uint8_t { let ua = ffi_param_ref!(ua); @@ -555,13 +555,13 @@ pub extern "system" fn sq_user_attribute_value(ua: Option<&Packet>, /// is not written to it. Either way, `key_len` is set to the size of /// the session key. #[no_mangle] -pub extern "system" fn sq_skesk_decrypt(ctx: Option<&mut Context>, - skesk: Option<&Packet>, +pub extern "system" fn sq_skesk_decrypt(ctx: *mut Context, + skesk: *const Packet, password: *const uint8_t, password_len: size_t, - algo: Option<&mut uint8_t>, // XXX + algo: *mut uint8_t, // XXX key: *mut uint8_t, - key_len: Option<&mut size_t>) + key_len: *mut size_t) -> Status { let ctx = ffi_param_ref_mut!(ctx); let skesk = ffi_param_ref!(skesk); @@ -598,7 +598,7 @@ pub extern "system" fn sq_skesk_decrypt(ctx: Option<&mut Context>, /// The return value is a reference ot a `KeyID`. The caller must not /// modify or free it. #[no_mangle] -pub extern "system" fn sq_pkesk_recipient(pkesk: Option<&PKESK>) +pub extern "system" fn sq_pkesk_recipient(pkesk: *const PKESK) -> *const KeyID { let pkesk = ffi_param_ref!(pkesk); pkesk.recipient() @@ -611,12 +611,12 @@ pub extern "system" fn sq_pkesk_recipient(pkesk: Option<&PKESK>) /// is not written to it. Either way, `key_len` is set to the size of /// the session key. #[no_mangle] -pub extern "system" fn sq_pkesk_decrypt(ctx: Option<&mut Context>, - pkesk: Option<&PKESK>, - secret_key: Option<&packet::Key>, - algo: Option<&mut uint8_t>, // XXX +pub extern "system" fn sq_pkesk_decrypt(ctx: *mut Context, + pkesk: *const PKESK, + secret_key: *const packet::Key, + algo: *mut uint8_t, // XXX key: *mut uint8_t, - key_len: Option<&mut size_t>) + key_len: *mut size_t) -> Status { let ctx = ffi_param_ref_mut!(ctx); let pkesk = ffi_param_ref!(pkesk); @@ -655,7 +655,7 @@ pub extern "system" fn sq_pkesk_decrypt(ctx: Option<&mut Context>, /// the stream. #[no_mangle] pub extern "system" fn sq_packet_parser_from_reader<'a> - (ctx: Option<&mut Context>, reader: Option<&'a mut Box<'a + Read>>) + (ctx: *mut Context, reader: *mut Box<'a + Read>) -> *mut PacketParserResult<'a> { let ctx = ffi_param_ref_mut!(ctx); let reader = ffi_param_ref_mut!(reader); @@ -668,9 +668,9 @@ pub extern "system" fn sq_packet_parser_from_reader<'a> /// the stream. #[no_mangle] pub extern "system" fn sq_packet_parser_from_file - (ctx: Option<&mut Context>, filename: *const c_char) - -> *mut PacketParserResult { - let ctx = ffi_param_ref!(ctx); + (ctx: *mut Context, filename: *const c_char) + -> *mut PacketParserResult<'static> { + let ctx = ffi_param_ref_mut!(ctx); assert!(! filename.is_null()); let filename = unsafe { CStr::from_ptr(filename).to_string_lossy().into_owned() @@ -684,8 +684,8 @@ pub extern "system" fn sq_packet_parser_from_file /// the stream. #[no_mangle] pub extern "system" fn sq_packet_parser_from_bytes - (ctx: Option<&mut Context>, b: *const uint8_t, len: size_t) - -> *mut PacketParserResult { + (ctx: *mut Context, b: *const uint8_t, len: size_t) + -> *mut PacketParserResult<'static> { let ctx = ffi_param_ref_mut!(ctx); assert!(!b.is_null()); let buf = unsafe { @@ -712,7 +712,7 @@ pub extern "system" fn sq_packet_parser_free(pp: *mut PacketParser) { /// Frees the packet parser EOF object. #[no_mangle] pub extern "system" fn sq_packet_parser_eof_is_message( - eof: Option<&PacketParserEOF>) -> bool + eof: *const PacketParserEOF) -> bool { let eof = ffi_param_ref!(eof); @@ -728,7 +728,7 @@ pub extern "system" fn sq_packet_parser_eof_free(eof: *mut PacketParserEOF) { /// Returns a reference to the packet that is being parsed. #[no_mangle] pub extern "system" fn sq_packet_parser_packet - (pp: Option<&PacketParser>) + (pp: *const PacketParser) -> *const Packet { let pp = ffi_param_ref!(pp); &pp.packet @@ -740,7 +740,7 @@ pub extern "system" fn sq_packet_parser_packet /// top-level container have a recursion depth of 1, etc. #[no_mangle] pub extern "system" fn sq_packet_parser_recursion_depth - (pp: Option<&PacketParser>) + (pp: *const PacketParser) -> uint8_t { let pp = ffi_param_ref!(pp); pp.recursion_depth() as u8 @@ -815,12 +815,12 @@ pub extern "system" fn sq_packet_parser_recursion_depth /// Consumes the given packet parser. #[no_mangle] pub extern "system" fn sq_packet_parser_next<'a> - (ctx: Option<&mut Context>, + (ctx: *mut Context, pp: *mut PacketParser<'a>, old_packet: Option<&mut *mut Packet>, ppr: Option<&mut *mut PacketParserResult<'a>>) -> Status { - let ctx = ffi_param_ref!(ctx); + let ctx = ffi_param_ref_mut!(ctx); let pp = ffi_param_move!(pp); match pp.next() { @@ -859,12 +859,12 @@ pub extern "system" fn sq_packet_parser_next<'a> /// Consumes the given packet parser. #[no_mangle] pub extern "system" fn sq_packet_parser_recurse<'a> - (ctx: Option<&mut Context>, + (ctx: *mut Context, pp: *mut PacketParser<'a>, old_packet: Option<&mut *mut Packet>, ppr: Option<&mut *mut PacketParserResult<'a>>) -> Status { - let ctx = ffi_param_ref!(ctx); + let ctx = ffi_param_ref_mut!(ctx); let pp = ffi_param_move!(pp); match pp.recurse() { @@ -889,9 +889,9 @@ pub extern "system" fn sq_packet_parser_recurse<'a> /// content is small. #[no_mangle] pub extern "system" fn sq_packet_parser_buffer_unread_content<'a> - (ctx: Option<&mut Context>, - pp: Option<&mut PacketParser<'a>>, - len: Option<&mut usize>) + (ctx: *mut Context, + pp: *mut PacketParser<'a>, + len: *mut usize) -> *const uint8_t { let ctx = ffi_param_ref_mut!(ctx); let pp = ffi_param_ref_mut!(pp); @@ -907,7 +907,7 @@ pub extern "system" fn sq_packet_parser_buffer_unread_content<'a> /// `PacketParserBuild` to customize the default behavior. #[no_mangle] pub extern "system" fn sq_packet_parser_finish<'a> - (ctx: Option<&mut Context>, pp: Option<&mut PacketParser<'a>>, + (ctx: *mut Context, pp: *mut PacketParser<'a>, packet: Option<&mut *const Packet>) -> Status { @@ -939,8 +939,8 @@ pub extern "system" fn sq_packet_parser_finish<'a> /// returns `Error::InvalidOperation`. #[no_mangle] pub extern "system" fn sq_packet_parser_decrypt<'a> - (ctx: Option<&mut Context>, - pp: Option<&mut PacketParser<'a>>, + (ctx: *mut Context, + pp: *mut PacketParser<'a>, algo: uint8_t, // XXX key: *const uint8_t, key_len: size_t) -> Status { @@ -966,7 +966,7 @@ pub extern "system" fn sq_packet_parser_decrypt<'a> /// Returns 0 if the PacketParserResult does not contain a packet. #[no_mangle] pub extern "system" fn sq_packet_parser_result_tag<'a> - (ppr: Option<&mut PacketParserResult<'a>>) + (ppr: *mut PacketParserResult<'a>) -> c_int { let ppr = ffi_param_ref_mut!(ppr); @@ -1061,8 +1061,8 @@ pub extern "system" fn sq_writer_stack_message /// Writes up to `len` bytes of `buf` into `writer`. #[no_mangle] pub extern "system" fn sq_writer_stack_write - (ctx: Option<&mut Context>, - writer: Option<&mut writer::Stack<'static, Cookie>>, + (ctx: *mut Context, + writer: *mut writer::Stack<'static, Cookie>, buf: *const uint8_t, len: size_t) -> ssize_t { @@ -1082,8 +1082,8 @@ pub extern "system" fn sq_writer_stack_write /// EINTR. #[no_mangle] pub extern "system" fn sq_writer_stack_write_all - (ctx: Option<&mut Context>, - writer: Option<&mut writer::Stack<'static, Cookie>>, + (ctx: *mut Context, + writer: *mut writer::Stack<'static, Cookie>, buf: *const uint8_t, len: size_t) -> Status { @@ -1099,7 +1099,7 @@ pub extern "system" fn sq_writer_stack_write_all /// Finalizes this writer, returning the underlying writer. #[no_mangle] pub extern "system" fn sq_writer_stack_finalize_one - (ctx: Option<&mut Context>, + (ctx: *mut Context, writer: *mut writer::Stack<'static, Cookie>) -> *mut writer::Stack<'static, Cookie> { @@ -1115,7 +1115,7 @@ pub extern "system" fn sq_writer_stack_finalize_one /// Finalizes all writers, tearing down the whole stack. #[no_mangle] pub extern "system" fn sq_writer_stack_finalize - (ctx: Option<&mut Context>, + (ctx: *mut Context, writer: *mut writer::Stack<'static, Cookie>) -> Status { @@ -1135,7 +1135,7 @@ pub extern "system" fn sq_writer_stack_finalize /// body is short, using full length encoding. #[no_mangle] pub extern "system" fn sq_arbitrary_writer_new - (ctx: Option<&mut Context>, + (ctx: *mut Context, inner: *mut writer::Stack<'static, Cookie>, tag: uint8_t) -> *mut writer::Stack<'static, Cookie> @@ -1152,9 +1152,9 @@ pub extern "system" fn sq_arbitrary_writer_new /// writes a signature packet. #[no_mangle] pub extern "system" fn sq_signer_new - (ctx: Option<&mut Context>, + (ctx: *mut Context, inner: *mut writer::Stack<'static, Cookie>, - signers: Option<&&'static TPK>, signers_len: size_t) + signers: *const &'static TPK, signers_len: size_t) -> *mut writer::Stack<'static, Cookie> { let ctx = ffi_param_ref_mut!(ctx); @@ -1169,7 +1169,7 @@ pub extern "system" fn sq_signer_new /// Creates a signer for a detached signature. #[no_mangle] pub extern "system" fn sq_signer_new_detached - (ctx: Option<&mut Context>, + (ctx: *mut Context, inner: *mut writer::Stack<'static, Cookie>, signers: Option<&&'static TPK>, signers_len: size_t) -> *mut writer::Stack<'static, Cookie> @@ -1189,7 +1189,7 @@ pub extern "system" fn sq_signer_new_detached /// body is short, using full length encoding. #[no_mangle] pub extern "system" fn sq_literal_writer_new - (ctx: Option<&mut Context>, + (ctx: *mut Context, inner: *mut writer::Stack<'static, Cookie>) -> *mut writer::Stack<'static, Cookie> { @@ -1211,7 +1211,7 @@ pub extern "system" fn sq_literal_writer_new /// preferences. #[no_mangle] pub extern "system" fn sq_encryptor_new - (ctx: Option<&mut Context>, + (ctx: *mut Context, inner: *mut writer::Stack<'static, Cookie>, passwords: Option<&*const c_char>, passwords_len: size_t, recipients: Option<&&TPK>, recipients_len: size_t, @@ -1304,10 +1304,10 @@ pub struct VerificationResults<'a> { /// level. The result is an array of references to /// `VerificationResult`. #[no_mangle] -pub fn sq_verification_results_at_level<'a>(results: Option<&'a VerificationResults>, +pub fn sq_verification_results_at_level<'a>(results: *const VerificationResults<'a>, level: size_t, - r: Option<&mut *const &'a VerificationResult>, - r_count: Option<&mut size_t>) { + r: *mut *const &'a VerificationResult, + r_count: *mut size_t) { let results = ffi_param_ref!(results); let r = ffi_param_ref_mut!(r); let r_count = ffi_param_ref_mut!(r_count); @@ -1323,7 +1323,7 @@ pub fn sq_verification_results_at_level<'a>(results: Option<&'a VerificationResu /// Returns the verification result code. #[no_mangle] -pub fn sq_verification_result_code(result: Option<&VerificationResult>) +pub fn sq_verification_result_code(result: *const VerificationResult) -> c_int { let result = ffi_param_ref!(result); @@ -1336,7 +1336,7 @@ pub fn sq_verification_result_code(result: Option<&VerificationResult>) /// Returns the verification result code. #[no_mangle] -pub fn sq_verification_result_signature(result: Option<&VerificationResult>) +pub fn sq_verification_result_signature(result: *const VerificationResult) -> *const packet::Signature { let result = ffi_param_ref!(result); @@ -1351,7 +1351,7 @@ pub fn sq_verification_result_signature(result: Option<&VerificationResult>) /// Returns the verification result code. #[no_mangle] -pub fn sq_verification_result_level(result: Option<&VerificationResult>) +pub fn sq_verification_result_level(result: *const VerificationResult) -> c_int { let result = ffi_param_ref!(result); @@ -1528,8 +1528,8 @@ fn verify_real<'a>(input: &'a mut Box<'a + Read>, /// /// Note: output may be NULL, if the output is not required. #[no_mangle] -pub fn sq_verify<'a>(ctx: Option<&mut Context>, - input: Option<&'a mut Box<'a + Read>>, +pub fn sq_verify<'a>(ctx: *mut Context, + input: *mut Box<'a + Read>, dsig: Option<&'a mut Box<'a + Read>>, output: Option<&'a mut Box<'a + Write>>, get_public_keys: GetPublicKeysCallback, @@ -1651,9 +1651,9 @@ fn decrypt_real<'a>(input: &'a mut Box<'a + Read>, /// /// Note: all of the parameters are required; none may be NULL. #[no_mangle] -pub fn sq_decrypt<'a>(ctx: Option<&mut Context>, - input: Option<&'a mut Box<'a + Read>>, - output: Option<&'a mut Box<'a + Write>>, +pub fn sq_decrypt<'a>(ctx: *mut Context, + input: *mut Box<'a + Read>, + output: *mut Box<'a + Write>, get_public_keys: GetPublicKeysCallback, get_secret_keys: GetSecretKeysCallback, check_signatures: CheckSignaturesCallback, diff --git a/ffi/src/openpgp/packet_pile.rs b/ffi/src/openpgp/packet_pile.rs index cec8283b..33a3735f 100644 --- a/ffi/src/openpgp/packet_pile.rs +++ b/ffi/src/openpgp/packet_pile.rs @@ -31,8 +31,8 @@ use ::error::Status; /// /// Note: this interface *does* buffer the contents of packets. #[no_mangle] -pub extern "system" fn sq_packet_pile_from_reader(ctx: Option<&mut Context>, - reader: Option<&mut Box>) +pub extern "system" fn sq_packet_pile_from_reader(ctx: *mut Context, + reader: *mut Box) -> *mut PacketPile { let ctx = ffi_param_ref_mut!(ctx); let reader = ffi_param_ref_mut!(reader); @@ -44,7 +44,7 @@ pub extern "system" fn sq_packet_pile_from_reader(ctx: Option<&mut Context>, /// /// See `sq_packet_pile_from_reader` for more details and caveats. #[no_mangle] -pub extern "system" fn sq_packet_pile_from_file(ctx: Option<&mut Context>, +pub extern "system" fn sq_packet_pile_from_file(ctx: *mut Context, filename: *const c_char) -> *mut PacketPile { let ctx = ffi_param_ref_mut!(ctx); @@ -59,7 +59,7 @@ pub extern "system" fn sq_packet_pile_from_file(ctx: Option<&mut Context>, /// /// See `sq_packet_pile_from_reader` for more details and caveats. #[no_mangle] -pub extern "system" fn sq_packet_pile_from_bytes(ctx: Option<&mut Context>, +pub extern "system" fn sq_packet_pile_from_bytes(ctx: *mut Context, b: *const uint8_t, len: size_t) -> *mut PacketPile { let ctx = ffi_param_ref_mut!(ctx); @@ -79,7 +79,7 @@ pub extern "system" fn sq_packet_pile_free(packet_pile: *mut PacketPile) { /// Clones the PacketPile. #[no_mangle] -pub extern "system" fn sq_packet_pile_clone(packet_pile: Option<&PacketPile>) +pub extern "system" fn sq_packet_pile_clone(packet_pile: *const PacketPile) -> *mut PacketPile { let packet_pile = ffi_param_ref!(packet_pile); box_raw!(packet_pile.clone()) @@ -87,9 +87,9 @@ pub extern "system" fn sq_packet_pile_clone(packet_pile: Option<&PacketPile>) /// Serializes the packet pile. #[no_mangle] -pub extern "system" fn sq_packet_pile_serialize(ctx: Option<&mut Context>, - packet_pile: Option<&PacketPile>, - writer: Option<&mut Box>) +pub extern "system" fn sq_packet_pile_serialize(ctx: *mut Context, + packet_pile: *const PacketPile, + writer: *mut Box) -> Status { let ctx = ffi_param_ref_mut!(ctx); let packet_pile = ffi_param_ref!(packet_pile); diff --git a/ffi/src/openpgp/tpk.rs b/ffi/src/openpgp/tpk.rs index 4d1289ac..471f4b93 100644 --- a/ffi/src/openpgp/tpk.rs +++ b/ffi/src/openpgp/tpk.rs @@ -39,8 +39,8 @@ use ::error::Status; /// Returns the first TPK encountered in the reader. #[no_mangle] -pub extern "system" fn sq_tpk_from_reader(ctx: Option<&mut Context>, - reader: Option<&mut Box>) +pub extern "system" fn sq_tpk_from_reader(ctx: *mut Context, + reader: *mut Box) -> *mut TPK { let ctx = ffi_param_ref_mut!(ctx); let reader = ffi_param_ref_mut!(reader); @@ -49,7 +49,7 @@ pub extern "system" fn sq_tpk_from_reader(ctx: Option<&mut Context>, /// Returns the first TPK encountered in the file. #[no_mangle] -pub extern "system" fn sq_tpk_from_file(ctx: Option<&mut Context>, +pub extern "system" fn sq_tpk_from_file(ctx: *mut Context, filename: *const c_char) -> *mut TPK { let ctx = ffi_param_ref_mut!(ctx); @@ -64,7 +64,7 @@ pub extern "system" fn sq_tpk_from_file(ctx: Option<&mut Context>, /// /// Consumes `m`. #[no_mangle] -pub extern "system" fn sq_tpk_from_packet_pile(ctx: Option<&mut Context>, +pub extern "system" fn sq_tpk_from_packet_pile(ctx: *mut Context, m: *mut PacketPile) -> *mut TPK { let ctx = ffi_param_ref_mut!(ctx); @@ -76,7 +76,7 @@ pub extern "system" fn sq_tpk_from_packet_pile(ctx: Option<&mut Context>, /// /// `buf` must be an OpenPGP-encoded TPK. #[no_mangle] -pub extern "system" fn sq_tpk_from_bytes(ctx: Option<&mut Context>, +pub extern "system" fn sq_tpk_from_bytes(ctx: *mut Context, b: *const uint8_t, len: size_t) -> *mut TPK { let ctx = ffi_param_ref_mut!(ctx); @@ -92,7 +92,7 @@ pub extern "system" fn sq_tpk_from_bytes(ctx: Option<&mut Context>, /// /// Consumes the packet parser result. #[no_mangle] -pub extern "system" fn sq_tpk_from_packet_parser(ctx: Option<&mut Context>, +pub extern "system" fn sq_tpk_from_packet_parser(ctx: *mut Context, ppr: *mut PacketParserResult) -> *mut TPK { @@ -110,7 +110,7 @@ pub extern "system" fn sq_tpk_free(tpk: *mut TPK) { /// Clones the TPK. #[no_mangle] -pub extern "system" fn sq_tpk_clone(tpk: Option<&TPK>) +pub extern "system" fn sq_tpk_clone(tpk: *const TPK) -> *mut TPK { let tpk = ffi_param_ref!(tpk); box_raw!(tpk.clone()) @@ -118,8 +118,8 @@ pub extern "system" fn sq_tpk_clone(tpk: Option<&TPK>) /// Compares TPKs. #[no_mangle] -pub extern "system" fn sq_tpk_equal(a: Option<&TPK>, - b: Option<&TPK>) +pub extern "system" fn sq_tpk_equal(a: *const TPK, + b: *const TPK) -> bool { let a = ffi_param_ref!(a); let b = ffi_param_ref!(b); @@ -128,9 +128,9 @@ pub extern "system" fn sq_tpk_equal(a: Option<&TPK>, /// Serializes the TPK. #[no_mangle] -pub extern "system" fn sq_tpk_serialize(ctx: Option<&mut Context>, - tpk: Option<&TPK>, - writer: Option<&mut Box>) +pub extern "system" fn sq_tpk_serialize(ctx: *mut Context, + tpk: *const TPK, + writer: *mut Box) -> Status { let ctx = ffi_param_ref_mut!(ctx); let tpk = ffi_param_ref!(tpk); @@ -145,7 +145,7 @@ pub extern "system" fn sq_tpk_serialize(ctx: Option<&mut Context>, /// /// Consumes `tpk` and `other`. #[no_mangle] -pub extern "system" fn sq_tpk_merge(ctx: Option<&mut Context>, +pub extern "system" fn sq_tpk_merge(ctx: *mut Context, tpk: *mut TPK, other: *mut TPK) -> *mut TPK { @@ -163,7 +163,7 @@ pub extern "system" fn sq_tpk_merge(ctx: Option<&mut Context>, /// Consumes `tpk` and the packets in `packets`. The buffer, however, /// must be managed by the caller. #[no_mangle] -pub extern "system" fn sq_tpk_merge_packets(ctx: Option<&mut Context>, +pub extern "system" fn sq_tpk_merge_packets(ctx: *mut Context, tpk: *mut TPK, packets: *mut *mut Packet, packets_len: size_t) @@ -182,14 +182,14 @@ pub extern "system" fn sq_tpk_merge_packets(ctx: Option<&mut Context>, /// /// XXX Remove this. #[no_mangle] -pub extern "system" fn sq_tpk_dump(tpk: Option<&TPK>) { +pub extern "system" fn sq_tpk_dump(tpk: *const TPK) { let tpk = ffi_param_ref!(tpk); println!("{:?}", *tpk); } /// Returns the fingerprint. #[no_mangle] -pub extern "system" fn sq_tpk_fingerprint(tpk: Option<&TPK>) +pub extern "system" fn sq_tpk_fingerprint(tpk: *const TPK) -> *mut Fingerprint { let tpk = ffi_param_ref!(tpk); box_raw!(tpk.fingerprint()) @@ -209,7 +209,7 @@ pub extern "system" fn sq_tpk_into_tsk(tpk: *mut TPK) /// The tpk still owns the key. The caller should neither modify nor /// free the key. #[no_mangle] -pub extern "system" fn sq_tpk_primary(tpk: Option<&TPK>) +pub extern "system" fn sq_tpk_primary(tpk: *const TPK) -> *const packet::Key { let tpk = ffi_param_ref!(tpk); tpk.primary() @@ -221,8 +221,8 @@ pub extern "system" fn sq_tpk_primary(tpk: Option<&TPK>) /// not reflect whether an individual user id, user attribute or /// subkey has been revoked. #[no_mangle] -pub extern "system" fn sq_tpk_revocation_status(tpk: Option<&TPK>) - -> *mut RevocationStatus { +pub extern "system" fn sq_tpk_revocation_status(tpk: *const TPK) + -> *mut RevocationStatus<'static> { let tpk = ffi_param_ref!(tpk); box_raw!(tpk.revoked()) } @@ -281,8 +281,8 @@ fn int_to_reason_for_revocation(code: c_int) -> ReasonForRevocation { /// sq_context_free (ctx); /// ``` #[no_mangle] -pub extern "system" fn sq_tpk_revoke(ctx: Option<&mut Context>, - tpk: Option<&mut TPK>, +pub extern "system" fn sq_tpk_revoke(ctx: *mut Context, + tpk: *mut TPK, code: c_int, reason: Option<*const c_char>) -> *mut packet::Signature @@ -337,7 +337,7 @@ pub extern "system" fn sq_tpk_revoke(ctx: Option<&mut Context>, /// sq_context_free (ctx); /// ``` #[no_mangle] -pub extern "system" fn sq_tpk_revoke_in_place(ctx: Option<&mut Context>, +pub extern "system" fn sq_tpk_revoke_in_place(ctx: *mut Context, tpk: *mut TPK, code: c_int, reason: Option<*const c_char>) @@ -359,7 +359,7 @@ pub extern "system" fn sq_tpk_revoke_in_place(ctx: Option<&mut Context>, /// Returns whether the TPK has expired. #[no_mangle] -pub extern "system" fn sq_tpk_expired(tpk: Option<&TPK>) +pub extern "system" fn sq_tpk_expired(tpk: *const TPK) -> c_int { let tpk = ffi_param_ref!(tpk); @@ -368,7 +368,7 @@ pub extern "system" fn sq_tpk_expired(tpk: Option<&TPK>) /// Returns whether the TPK has expired. #[no_mangle] -pub extern "system" fn sq_tpk_expired_at(tpk: Option<&TPK>, when: time_t) +pub extern "system" fn sq_tpk_expired_at(tpk: *const TPK, when: time_t) -> c_int { let tpk = ffi_param_ref!(tpk); tpk.expired_at(time::at(time::Timespec::new(when as i64, 0))) as c_int @@ -376,7 +376,7 @@ pub extern "system" fn sq_tpk_expired_at(tpk: Option<&TPK>, when: time_t) /// Returns whether the TPK is alive. #[no_mangle] -pub extern "system" fn sq_tpk_alive(tpk: Option<&TPK>) +pub extern "system" fn sq_tpk_alive(tpk: *const TPK) -> c_int { let tpk = ffi_param_ref!(tpk); @@ -385,7 +385,7 @@ pub extern "system" fn sq_tpk_alive(tpk: Option<&TPK>) /// Returns whether the TPK is alive at the specified time. #[no_mangle] -pub extern "system" fn sq_tpk_alive_at(tpk: Option<&TPK>, when: time_t) +pub extern "system" fn sq_tpk_alive_at(tpk: *const TPK, when: time_t) -> c_int { let tpk = ffi_param_ref!(tpk); tpk.alive_at(time::at(time::Timespec::new(when as i64, 0))) as c_int @@ -398,7 +398,7 @@ pub extern "system" fn sq_tpk_alive_at(tpk: Option<&TPK>, when: time_t) /// /// This function consumes `tpk` and returns a new `TPK`. #[no_mangle] -pub extern "system" fn sq_tpk_set_expiry(ctx: Option<&mut Context>, +pub extern "system" fn sq_tpk_set_expiry(ctx: *mut Context, tpk: *mut TPK, expiry: u32) -> *mut TPK { let ctx = ffi_param_ref_mut!(ctx); @@ -409,7 +409,7 @@ pub extern "system" fn sq_tpk_set_expiry(ctx: Option<&mut Context>, /// Returns whether the TPK includes any secret key material. #[no_mangle] -pub extern "system" fn sq_tpk_is_tsk(tpk: Option<&TPK>) +pub extern "system" fn sq_tpk_is_tsk(tpk: *const TPK) -> c_int { let tpk = ffi_param_ref!(tpk); tpk.is_tsk() as c_int @@ -417,7 +417,7 @@ pub extern "system" fn sq_tpk_is_tsk(tpk: Option<&TPK>) /// Returns an iterator over the TPK's user id bindings. #[no_mangle] -pub extern "system" fn sq_tpk_primary_user_id(tpk: Option<&TPK>) +pub extern "system" fn sq_tpk_primary_user_id(tpk: *const TPK) -> *mut c_char { let tpk = ffi_param_ref!(tpk); @@ -441,7 +441,7 @@ pub extern "system" fn sq_tpk_primary_user_id(tpk: Option<&TPK>) /// The caller must free the returned value. #[no_mangle] pub extern "system" fn sq_user_id_binding_user_id( - binding: Option<&UserIDBinding>) + binding: *const UserIDBinding) -> *mut c_char { let binding = ffi_param_ref!(binding); @@ -456,8 +456,8 @@ pub extern "system" fn sq_user_id_binding_user_id( /// Returns a reference to the self-signature, if any. #[no_mangle] pub extern "system" fn sq_user_id_binding_selfsig( - binding: Option<&UserIDBinding>) - -> Option<&Signature> + binding: *const UserIDBinding) + -> Option<&'static Signature> { let binding = ffi_param_ref!(binding); binding.binding_signature() @@ -468,8 +468,8 @@ pub extern "system" fn sq_user_id_binding_selfsig( /// Returns an iterator over the TPK's user id bindings. #[no_mangle] -pub extern "system" fn sq_tpk_user_id_binding_iter(tpk: Option<&TPK>) - -> *mut UserIDBindingIter +pub extern "system" fn sq_tpk_user_id_binding_iter(tpk: *const TPK) + -> *mut UserIDBindingIter<'static> { let tpk = ffi_param_ref!(tpk); box_raw!(tpk.userids()) @@ -486,7 +486,7 @@ pub extern "system" fn sq_user_id_binding_iter_free( /// Returns the next `UserIDBinding`. #[no_mangle] pub extern "system" fn sq_user_id_binding_iter_next<'a>( - iter: Option<&mut UserIDBindingIter<'a>>) + iter: *mut UserIDBindingIter<'a>) -> Option<&'a UserIDBinding> { let iter = ffi_param_ref_mut!(iter); @@ -505,8 +505,8 @@ pub struct KeyIterWrapper<'a> { /// /// This iterates over both the primary key and any subkeys. #[no_mangle] -pub extern "system" fn sq_tpk_key_iter(tpk: Option<&TPK>) - -> *mut KeyIterWrapper +pub extern "system" fn sq_tpk_key_iter(tpk: *const TPK) + -> *mut KeyIterWrapper<'static> { let tpk = ffi_param_ref!(tpk); box_raw!(KeyIterWrapper { @@ -534,7 +534,7 @@ pub extern "system" fn sq_tpk_key_iter_free( /// *rso. #[no_mangle] pub extern "system" fn sq_tpk_key_iter_next<'a>( - iter_wrapper: Option<&'a mut KeyIterWrapper<'a>>, + iter_wrapper: *mut KeyIterWrapper<'a>, sigo: Option<&mut Option<&'a packet::Signature>>, rso: Option<&mut &'a RevocationStatus<'a>>) -> Option<&'a packet::Key> @@ -608,7 +608,7 @@ pub extern "system" fn sq_tpk_builder_free(tpkb: *mut TPKBuilder) /// subkeys. #[no_mangle] pub extern "system" fn sq_tpk_builder_set_cipher_suite - (tpkb: Option<&mut *mut TPKBuilder>, cs: c_int) + (tpkb: *mut *mut TPKBuilder, cs: c_int) {