summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ffi-macros/src/lib.rs21
-rw-r--r--openpgp-ffi/src/packet_pile.rs13
-rw-r--r--openpgp-ffi/src/tpk.rs13
-rw-r--r--openpgp-ffi/src/tsk.rs14
4 files changed, 24 insertions, 37 deletions
diff --git a/ffi-macros/src/lib.rs b/ffi-macros/src/lib.rs
index 9d486ba5..5e815c3f 100644
--- a/ffi-macros/src/lib.rs
+++ b/ffi-macros/src/lib.rs
@@ -234,6 +234,7 @@ fn derive_functions() -> &'static HashMap<&'static str, DeriveFn>
h.insert("Hash", derive_hash as DeriveFn);
h.insert("Display", derive_to_string as DeriveFn);
h.insert("Debug", derive_debug as DeriveFn);
+ h.insert("Serialize", derive_serialize as DeriveFn);
h
};
}
@@ -643,3 +644,23 @@ fn derive_hash(span: proc_macro2::Span, prefix: &str, name: &str,
}
}
}
+
+/// Derives prefix_name_serialize.
+fn derive_serialize(span: proc_macro2::Span, prefix: &str, name: &str,
+ wrapper: &syn::Ident, _wrapped: &syn::Type)
+ -> TokenStream2
+{
+ let ident = syn::Ident::new(&format!("{}{}_serialize", prefix, name),
+ span);
+ quote! {
+ /// Serializes this object.
+ #[::ffi_catch_abort] #[no_mangle] pub extern "system"
+ fn #ident (errp: Option<&mut *mut ::error::Error>,
+ tsk: *const #wrapper,
+ writer: *mut Box<Write>)
+ -> Status {
+ let writer = ffi_param_ref_mut!(writer);
+ tsk.ref_raw().serialize(writer).move_into_raw(errp)
+ }
+ }
+}
diff --git a/openpgp-ffi/src/packet_pile.rs b/openpgp-ffi/src/packet_pile.rs
index ad91bed3..e1aa97fe 100644
--- a/openpgp-ffi/src/packet_pile.rs
+++ b/openpgp-ffi/src/packet_pile.rs
@@ -24,7 +24,7 @@ use ::error::Status;
///
/// [`sequoia-openpgp::PacketPile`]: ../../sequoia_openpgp/struct.PacketPile.html
#[::ffi_wrapper_type(prefix = "pgp_",
- derive = "Clone, Debug, PartialEq")]
+ derive = "Clone, Debug, PartialEq, Serialize")]
pub struct PacketPile(openpgp::PacketPile);
/// Deserializes the OpenPGP message stored in a `std::io::Read`
@@ -71,14 +71,3 @@ fn pgp_packet_pile_from_bytes(errp: Option<&mut *mut ::error::Error>,
openpgp::PacketPile::from_bytes(buf).move_into_raw(errp)
}
-
-/// Serializes the packet pile.
-#[::ffi_catch_abort] #[no_mangle] pub extern "system"
-fn pgp_packet_pile_serialize(errp: Option<&mut *mut ::error::Error>,
- packet_pile: *const PacketPile,
- writer: *mut Box<Write>)
- -> Status {
- ffi_make_fry_from_errp!(errp);
- let writer = ffi_param_ref_mut!(writer);
- ffi_try_status!(packet_pile.ref_raw().serialize(writer))
-}
diff --git a/openpgp-ffi/src/tpk.rs b/openpgp-ffi/src/tpk.rs
index 90e88448..a17def26 100644
--- a/openpgp-ffi/src/tpk.rs
+++ b/openpgp-ffi/src/tpk.rs
@@ -53,7 +53,7 @@ use Maybe;
///
/// [RFC 4880, section 11.1]: https://tools.ietf.org/html/rfc4880#section-11.1
#[::ffi_wrapper_type(prefix = "pgp_", name = "tpk",
- derive = "Clone, Debug, Display, PartialEq")]
+ derive = "Clone, Debug, Display, PartialEq, Serialize")]
pub struct TPK(openpgp::TPK);
/// Returns the first TPK encountered in the reader.
@@ -112,17 +112,6 @@ fn pgp_tpk_from_packet_parser(errp: Option<&mut *mut ::error::Error>,
openpgp::TPK::from_packet_parser(*ppr).move_into_raw(errp)
}
-/// Serializes the TPK.
-#[::ffi_catch_abort] #[no_mangle] pub extern "system"
-fn pgp_tpk_serialize(errp: Option<&mut *mut ::error::Error>,
- tpk: *const TPK,
- writer: *mut Box<Write>)
- -> Status {
- let tpk = tpk.ref_raw();
- let writer = ffi_param_ref_mut!(writer);
- tpk.serialize(writer).move_into_raw(errp)
-}
-
/// Merges `other` into `tpk`.
///
/// If `other` is a different key, then nothing is merged into
diff --git a/openpgp-ffi/src/tsk.rs b/openpgp-ffi/src/tsk.rs
index b3254456..2f77645e 100644
--- a/openpgp-ffi/src/tsk.rs
+++ b/openpgp-ffi/src/tsk.rs
@@ -28,7 +28,7 @@ use ::error::Status;
///
/// [`sequoia-openpgp::TSK`]: ../../sequoia_openpgp/enum.TSK.html
#[::ffi_wrapper_type(prefix = "pgp_", name = "tsk",
- derive = "Clone, Debug, PartialEq")]
+ derive = "Clone, Debug, PartialEq, Serialize")]
pub struct TSK(openpgp::TSK);
/// Generates a new RSA 3072 bit key with UID `primary_uid`.
@@ -65,15 +65,3 @@ fn pgp_tsk_into_tpk(tsk: *mut TSK)
-> *mut TPK {
tsk.move_from_raw().into_tpk().move_into_raw()
}
-
-
-/// Serializes the TSK.
-#[::ffi_catch_abort] #[no_mangle] pub extern "system"
-fn pgp_tsk_serialize(errp: Option<&mut *mut ::error::Error>,
- tsk: *const TSK,
- writer: *mut Box<Write>)
- -> Status {
- let tsk = tsk.ref_raw();
- let writer = ffi_param_ref_mut!(writer);
- tsk.serialize(writer).move_into_raw(errp)
-}