summaryrefslogtreecommitdiffstats
path: root/ffi
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-04-09 11:09:08 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-07-17 11:13:46 +0200
commitd93079487ff27c0f3ddb8b470d5db7483c03e89f (patch)
treeee75030eae262dbfa5a208482bd7dd43cbb83d45 /ffi
parent4ad3f62dc2d22ad4ae95c83d1a6fd08a041a41ee (diff)
openpgp: Add function to query the parsed packets tag.
- This function returns the packets tag iff it has been successfully parsed into the corresponding packet structure.
Diffstat (limited to 'ffi')
-rw-r--r--ffi/include/sequoia/openpgp.h11
-rw-r--r--ffi/src/openpgp.rs18
2 files changed, 29 insertions, 0 deletions
diff --git a/ffi/include/sequoia/openpgp.h b/ffi/include/sequoia/openpgp.h
index 743c5d07..f6402d86 100644
--- a/ffi/include/sequoia/openpgp.h
+++ b/ffi/include/sequoia/openpgp.h
@@ -462,6 +462,17 @@ void sq_packet_free (sq_packet_t p);
sq_tag_t sq_packet_tag (sq_packet_t p);
/*/
+/// Returns the parsed `Packet's` corresponding OpenPGP tag.
+///
+/// Returns the packets tag, but only if it was successfully
+/// parsed into the corresponding packet type. If e.g. a
+/// Signature Packet uses some unsupported methods, it is parsed
+/// into an `Packet::Unknown`. `tag()` returns `SQ_TAG_SIGNATURE`,
+/// whereas `kind()` returns `0`.
+/*/
+sq_tag_t sq_packet_kind (sq_packet_t p);
+
+/*/
/// Computes and returns the key's fingerprint as per Section 12.2
/// of RFC 4880.
/*/
diff --git a/ffi/src/openpgp.rs b/ffi/src/openpgp.rs
index 1417a5a7..0ba06a16 100644
--- a/ffi/src/openpgp.rs
+++ b/ffi/src/openpgp.rs
@@ -468,6 +468,24 @@ pub extern "system" fn sq_packet_tag(p: Option<&Packet>)
tag as uint8_t
}
+/// Returns the parsed `Packet's` corresponding OpenPGP tag.
+///
+/// Returns the packets tag, but only if it was successfully
+/// parsed into the corresponding packet type. If e.g. a
+/// Signature Packet uses some unsupported methods, it is parsed
+/// 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>)
+ -> uint8_t {
+ let p = p.expect("Packet is NULL");
+ if let Some(kind) = p.kind() {
+ kind.into()
+ } else {
+ 0
+ }
+}
+
/// Computes and returns the key's fingerprint as per Section 12.2
/// of RFC 4880.
#[no_mangle]