summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/src/error.rs
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-05-07 10:35:26 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-05-07 12:18:34 +0200
commit0db7ff8d9c07d10e355d9888b8c42341caa85959 (patch)
tree2496d26b162c60b4bdb62b81726bfc8cb5da4495 /openpgp-ffi/src/error.rs
parent471932ab32ee8d76c7939e8fbb028dc9260ac3bb (diff)
openpgp-ffi: Add a function to convert a Status to a string
Diffstat (limited to 'openpgp-ffi/src/error.rs')
-rw-r--r--openpgp-ffi/src/error.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/openpgp-ffi/src/error.rs b/openpgp-ffi/src/error.rs
index 07b79a77..991b22db 100644
--- a/openpgp-ffi/src/error.rs
+++ b/openpgp-ffi/src/error.rs
@@ -2,6 +2,7 @@
use failure;
use std::io;
+use libc::c_char;
extern crate sequoia_openpgp as openpgp;
@@ -140,6 +141,44 @@ pub enum Status {
// XXX: Skipping MissingSessionKey = -27
}
+/// Returns the error message.
+///
+/// The returned value must *not* be freed.
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
+pub extern "system" fn pgp_status_to_string(status: Status) -> *const c_char {
+ use error::Status::*;
+
+ match status {
+ Success => "Success\x00",
+ UnknownError => "An unknown error occurred\x00",
+ NetworkPolicyViolation =>
+ "The network policy was violated by the given action\x00",
+ IoError => "An IO error occurred\x00",
+ InvalidArgument => "A given argument is invalid\x00",
+ InvalidOperation => "The requested operation is invalid\x00",
+ MalformedPacket => "The packet is malformed\x00",
+ UnsupportedPacketType => "Unsupported packet type\x00",
+ UnsupportedHashAlgorithm => "Unsupported hash algorithm\x00",
+ UnsupportedPublicKeyAlgorithm =>
+ "Unsupported public key algorithm\x00",
+ UnsupportedEllipticCurve => "Unsupported elliptic curve\x00",
+ UnsupportedSymmetricAlgorithm =>
+ "Unsupported symmetric algorithm\x00",
+ UnsupportedAEADAlgorithm => "Unsupported AEAD algorithm\x00",
+ UnsupportedSignatureType => "Unsupport signature type\x00",
+ InvalidPassword => "Invalid password\x00",
+ InvalidSessionKey => "Invalid session key\x00",
+ MissingSessionKey => "Missing session key\x00",
+ MalformedTPK => "Malformed TPK\x00",
+ MalformedMPI => "Malformed MPI\x00",
+ BadSignature => "Bad signature\x00",
+ ManipulatedMessage => "Message has been manipulated\x00",
+ MalformedMessage => "Malformed message\x00",
+ IndexOutOfRange => "Index out of range\x00",
+ UnsupportedTPK => "TPK not supported\x00",
+ }.as_bytes().as_ptr() as *const c_char
+}
+
impl<'a> From<&'a failure::Error> for Status {
fn from(e: &'a failure::Error) -> Self {
if let Some(e) = e.downcast_ref::<openpgp::Error>() {