diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-12-14 15:36:58 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-12-17 11:46:44 +0100 |
commit | 05e1b5dc9d189e3129f8da2c6beacb014f3fd698 (patch) | |
tree | ec65fb105a7d85d78a5c2e2e38f71e71ad85b997 /ffi/src/openpgp.rs | |
parent | 4c35f633626895fe734a34c2982b1ece2b7d4f1f (diff) |
ffi: Avoid inline function.
- Inline functions make python-cffi choke on the header file.
Diffstat (limited to 'ffi/src/openpgp.rs')
-rw-r--r-- | ffi/src/openpgp.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ffi/src/openpgp.rs b/ffi/src/openpgp.rs index 3db1aa70..d98aa50c 100644 --- a/ffi/src/openpgp.rs +++ b/ffi/src/openpgp.rs @@ -24,6 +24,7 @@ use self::openpgp::{ Packet, packet::{ Signature, + Tag, PKESK, SKESK, key::SecretKey, @@ -62,6 +63,41 @@ use super::build_hasher; use super::error::Status; use super::core::Context; +/* openpgp::packet::Tag. */ + +/// Returns a human-readable tag name. +/// +/// ```c +/// #include <assert.h> +/// #include <string.h> +/// #include <sequoia.h> +/// +/// assert (strcmp (sq_tag_to_string (2), "SIGNATURE") == 0); +/// ``` +#[no_mangle] +pub extern "system" fn sq_tag_to_string(tag: u8) -> *const c_char { + match Tag::from(tag) { + Tag::PKESK => "PKESK\x00", + Tag::Signature => "SIGNATURE\x00", + Tag::SKESK => "SKESK\x00", + Tag::OnePassSig => "ONE PASS SIG\x00", + Tag::SecretKey => "SECRET KEY\x00", + Tag::PublicKey => "PUBLIC KEY\x00", + Tag::SecretSubkey => "SECRET SUBKEY\x00", + Tag::CompressedData => "COMPRESSED DATA\x00", + Tag::SED => "SED\x00", + Tag::Marker => "MARKER\x00", + Tag::Literal => "LITERAL\x00", + Tag::Trust => "TRUST\x00", + Tag::UserID => "USER ID\x00", + Tag::PublicSubkey => "PUBLIC SUBKEY\x00", + Tag::UserAttribute => "USER ATTRIBUTE\x00", + Tag::SEIP => "SEIP\x00", + Tag::MDC => "MDC\x00", + _ => "OTHER\x00", + }.as_bytes().as_ptr() as *const c_char +} + /* sequoia::openpgp::KeyID. */ /// Reads a binary key ID. |