summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-02-12 14:04:32 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-02-12 14:34:50 +0100
commitcb73fa51b3a7c93784cf565da61d863dc619f547 (patch)
tree041f9eadf086306a002d3846d948add7dd31f7e1
parent7ec34a916033917f2e1aa3eec03ec3175d50b39c (diff)
openpgp-ffi: Wrap openpgp::packet::signature::Signature.
-rw-r--r--openpgp-ffi/include/sequoia/openpgp.h42
-rw-r--r--openpgp-ffi/src/packet/signature.rs161
-rw-r--r--openpgp-ffi/src/tpk.rs17
-rw-r--r--openpgp-ffi/src/tsk.rs6
4 files changed, 116 insertions, 110 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h
index e3acf157..5156d1df 100644
--- a/openpgp-ffi/include/sequoia/openpgp.h
+++ b/openpgp-ffi/include/sequoia/openpgp.h
@@ -571,6 +571,48 @@ pgp_status_t pgp_packet_pile_serialize (pgp_error_t *errp,
void pgp_signature_free (pgp_signature_t signature);
/*/
+/// Clones the Signature.
+/*/
+pgp_signature_t pgp_signature_clone (pgp_signature_t this);
+
+/*/
+/// Returns a human readable description of this object suitable for
+/// debugging.
+/*/
+char *pgp_signature_debug (const pgp_signature_t this);
+
+/*/
+/// Compares Signatures.
+/*/
+bool pgp_signature_equal (const pgp_signature_t a,
+ const pgp_signature_t b);
+
+/*/
+/// Parses an object from the given reader.
+/*/
+pgp_signature_t pgp_signature_from_reader (pgp_error_t *errp,
+ pgp_reader_t reader);
+
+/*/
+/// Parses an object from the given file.
+/*/
+pgp_signature_t pgp_signature_from_file (pgp_error_t *errp,
+ const char *filename);
+
+/*/
+/// Parses an object from the given buffer.
+/*/
+pgp_signature_t pgp_signature_from_bytes (pgp_error_t *errp,
+ const uint8_t *b, size_t len);
+
+/*/
+/// Serializes this object.
+/*/
+pgp_status_t pgp_signature_serialize (pgp_error_t *errp,
+ const pgp_signature_t this,
+ pgp_writer_t writer);
+
+/*/
/// Converts the signature to a packet.
/*/
pgp_packet_t pgp_signature_into_packet (pgp_signature_t signature);
diff --git a/openpgp-ffi/src/packet/signature.rs b/openpgp-ffi/src/packet/signature.rs
index 21bba540..09eb7c6e 100644
--- a/openpgp-ffi/src/packet/signature.rs
+++ b/openpgp-ffi/src/packet/signature.rs
@@ -10,32 +10,34 @@
use libc::time_t;
extern crate sequoia_openpgp as openpgp;
-use self::openpgp::{
- packet,
- Packet,
-};
-use self::openpgp::packet::{
- Signature,
-};
use super::super::fingerprint::Fingerprint;
use super::super::keyid::KeyID;
use Maybe;
+use MoveFromRaw;
use MoveIntoRaw;
+use RefRaw;
-/// Frees the Signature.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_free(s: Option<&mut Signature>) {
- ffi_free!(s)
-}
+/// Holds a signature packet.
+///
+/// Signature packets are used both for certification purposes as well
+/// as for document signing purposes.
+///
+/// See [Section 5.2 of RFC 4880] for details.
+///
+/// [Section 5.2 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2
+///
+/// Wraps [`sequoia-openpgp::packet::signature::Signature`].
+///
+/// [`sequoia-openpgp::packet::signature::Signature`]: ../../sequoia_openpgp/packet/signature/struct.Signature.html
+#[::ffi_wrapper_type(prefix = "pgp_",
+ derive = "Clone, Debug, PartialEq, Parse, Serialize")]
+pub struct Signature(openpgp::packet::Signature);
/// Converts the signature to a packet.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_into_packet(s: *mut Signature)
- -> *mut Packet
-{
- let s = ffi_param_move!(s);
- box_raw!((*s).into())
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_into_packet(s: *mut Signature) -> *mut openpgp::Packet {
+ box_raw!(s.move_from_raw().into())
}
/// Returns the value of the `Signature` packet's Issuer subpacket.
@@ -43,11 +45,9 @@ pub extern "system" fn pgp_signature_into_packet(s: *mut Signature)
/// If there is no Issuer subpacket, this returns NULL. Note: if
/// there is no Issuer subpacket, but there is an IssuerFingerprint
/// subpacket, this still returns NULL.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_issuer(sig: *const packet::Signature)
- -> Maybe<KeyID> {
- let sig = ffi_param_ref!(sig);
- sig.issuer().move_into_raw()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_issuer(sig: *const Signature) -> Maybe<KeyID> {
+ sig.ref_raw().issuer().move_into_raw()
}
/// Returns the value of the `Signature` packet's IssuerFingerprint subpacket.
@@ -55,84 +55,61 @@ pub extern "system" fn pgp_signature_issuer(sig: *const packet::Signature)
/// If there is no IssuerFingerprint subpacket, this returns NULL.
/// Note: if there is no IssuerFingerprint subpacket, but there is an
/// Issuer subpacket, this still returns NULL.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_issuer_fingerprint(
- sig: *const packet::Signature)
- -> Maybe<Fingerprint>
-{
- let sig = ffi_param_ref!(sig);
- sig.issuer_fingerprint().move_into_raw()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_issuer_fingerprint(sig: *const Signature)
+ -> Maybe<Fingerprint> {
+ sig.ref_raw().issuer_fingerprint().move_into_raw()
}
/// Returns whether the KeyFlags indicates that the key can be used to
/// make certifications.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_can_certify(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.key_flags().can_certify()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_can_certify(sig: *const Signature) -> bool {
+ sig.ref_raw().key_flags().can_certify()
}
/// Returns whether the KeyFlags indicates that the key can be used to
/// make signatures.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_can_sign(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.key_flags().can_sign()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_can_sign(sig: *const Signature) -> bool {
+ sig.ref_raw().key_flags().can_sign()
}
/// Returns whether the KeyFlags indicates that the key can be used to
/// encrypt data for transport.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_can_encrypt_for_transport(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.key_flags().can_encrypt_for_transport()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_can_encrypt_for_transport(sig: *const Signature)
+ -> bool {
+ sig.ref_raw().key_flags().can_encrypt_for_transport()
}
/// Returns whether the KeyFlags indicates that the key can be used to
/// encrypt data at rest.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_can_encrypt_at_rest(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.key_flags().can_encrypt_at_rest()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_can_encrypt_at_rest(sig: *const Signature) -> bool {
+ sig.ref_raw().key_flags().can_encrypt_at_rest()
}
/// Returns whether the KeyFlags indicates that the key can be used
/// for authentication.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_can_authenticate(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.key_flags().can_authenticate()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_can_authenticate(sig: *const Signature) -> bool {
+ sig.ref_raw().key_flags().can_authenticate()
}
/// Returns whether the KeyFlags indicates that the key is a split
/// key.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_is_split_key(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.key_flags().is_split_key()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_is_split_key(sig: *const Signature) -> bool {
+ sig.ref_raw().key_flags().is_split_key()
}
/// Returns whether the KeyFlags indicates that the key is a group
/// key.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_is_group_key(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.key_flags().is_group_key()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_is_group_key(sig: *const Signature) -> bool {
+ sig.ref_raw().key_flags().is_group_key()
}
@@ -140,42 +117,30 @@ pub extern "system" fn pgp_signature_is_group_key(sig: *const packet::Signature)
///
/// A signature is alive if the creation date is in the past, and the
/// signature has not expired.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_alive(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.signature_alive()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_alive(sig: *const Signature) -> bool {
+ sig.ref_raw().signature_alive()
}
/// Returns whether the signature is alive at the specified time.
///
/// A signature is alive if the creation date is in the past, and the
/// signature has not expired at the specified time.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_alive_at(sig: *const packet::Signature,
- when: time_t)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.signature_alive_at(time::at(time::Timespec::new(when as i64, 0)))
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_alive_at(sig: *const Signature, when: time_t) -> bool {
+ sig.ref_raw()
+ .signature_alive_at(time::at(time::Timespec::new(when as i64, 0)))
}
/// Returns whether the signature is expired.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_expired(sig: *const packet::Signature)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.signature_expired()
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_expired(sig: *const Signature) -> bool {
+ sig.ref_raw().signature_expired()
}
/// Returns whether the signature is expired at the specified time.
-#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "system" fn pgp_signature_expired_at(sig: *const packet::Signature,
- when: time_t)
- -> bool
-{
- let sig = ffi_param_ref!(sig);
- sig.signature_expired_at(time::at(time::Timespec::new(when as i64, 0)))
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_signature_expired_at(sig: *const Signature, when: time_t) -> bool {
+ sig.ref_raw()
+ .signature_expired_at(time::at(time::Timespec::new(when as i64, 0)))
}
diff --git a/openpgp-ffi/src/tpk.rs b/openpgp-ffi/src/tpk.rs
index daf87a04..5b035dff 100644
--- a/openpgp-ffi/src/tpk.rs
+++ b/openpgp-ffi/src/tpk.rs
@@ -16,7 +16,7 @@ use self::openpgp::{
autocrypt::Autocrypt,
crypto,
constants::ReasonForRevocation,
- packet::{self, Signature},
+ packet,
parse::PacketParserResult,
tpk::{
CipherSuite,
@@ -29,6 +29,7 @@ use self::openpgp::{
use ::error::Status;
use super::fingerprint::Fingerprint;
+use super::packet::signature::Signature;
use super::packet_pile::PacketPile;
use super::tsk::TSK;
use Maybe;
@@ -223,7 +224,7 @@ fn pgp_tpk_revoke(errp: Option<&mut *mut ::error::Error>,
primary_signer: *mut Box<crypto::Signer>,
code: c_int,
reason: Option<&c_char>)
- -> *mut packet::Signature
+ -> Maybe<Signature>
{
ffi_make_fry_from_errp!(errp);
let tpk = tpk.ref_raw();
@@ -235,7 +236,7 @@ fn pgp_tpk_revoke(errp: Option<&mut *mut ::error::Error>,
b""
};
- ffi_try_box!(tpk.revoke(signer.as_mut(), code, reason))
+ tpk.revoke(signer.as_mut(), code, reason).move_into_raw(errp)
}
/// Adds a revocation certificate to the tpk.
@@ -397,10 +398,10 @@ pub extern "system" fn pgp_user_id_binding_user_id(
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "system" fn pgp_user_id_binding_selfsig(
binding: *const UserIDBinding)
- -> Option<&'static Signature>
+ -> Maybe<Signature>
{
let binding = ffi_param_ref!(binding);
- binding.binding_signature()
+ binding.binding_signature().move_into_raw()
}
@@ -475,7 +476,7 @@ pub extern "system" fn pgp_tpk_key_iter_free(
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "system" fn pgp_tpk_key_iter_next<'a>(
iter_wrapper: *mut KeyIterWrapper<'a>,
- sigo: Option<&mut Option<&'a packet::Signature>>,
+ sigo: Option<&mut Maybe<Signature>>,
rso: Option<&mut &'a RevocationStatus<'a>>)
-> Option<&'a packet::Key>
{
@@ -484,7 +485,7 @@ pub extern "system" fn pgp_tpk_key_iter_next<'a>(
if let Some((sig, rs, key)) = iter_wrapper.iter.next() {
if let Some(ptr) = sigo {
- *ptr = sig;
+ *ptr = sig.move_into_raw();
}
if let Some(ptr) = rso {
@@ -645,7 +646,7 @@ pub extern "system" fn pgp_tpk_builder_generate
match tpkb.generate() {
Ok((tpk, revocation)) => {
*tpk_out = Some(tpk).move_into_raw();
- *revocation_out = box_raw!(revocation);
+ *revocation_out = revocation.move_into_raw();
Status::Success
},
Err(e) => {
diff --git a/openpgp-ffi/src/tsk.rs b/openpgp-ffi/src/tsk.rs
index ea2cf5b0..ef17c285 100644
--- a/openpgp-ffi/src/tsk.rs
+++ b/openpgp-ffi/src/tsk.rs
@@ -8,9 +8,7 @@ use failure;
use libc::c_char;
extern crate sequoia_openpgp as openpgp;
-use self::openpgp::{
- packet::Signature,
-};
+use super::packet::signature::Signature;
use super::tpk::TPK;
use ::error::Status;
@@ -47,7 +45,7 @@ fn pgp_tsk_new(errp: Option<&mut *mut ::error::Error>,
match openpgp::TSK::new(primary_uid) {
Ok((tsk, revocation)) => {
*tsk_out = tsk.move_into_raw();
- *revocation_out = box_raw!(revocation);
+ *revocation_out = revocation.move_into_raw();
Status::Success
},
Err(e) => Err::<(), failure::Error>(e).move_into_raw(errp),