summaryrefslogtreecommitdiffstats
path: root/ffi/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ffi/src/error.rs')
-rw-r--r--ffi/src/error.rs118
1 files changed, 5 insertions, 113 deletions
diff --git a/ffi/src/error.rs b/ffi/src/error.rs
index 369cbb25..d9fb2c21 100644
--- a/ffi/src/error.rs
+++ b/ffi/src/error.rs
@@ -2,125 +2,17 @@
use failure;
use std::io;
-use libc::c_char;
extern crate sequoia_openpgp as openpgp;
use sequoia_core as core;
+pub use openpgp::error::Status;
-/// Frees an error.
-#[::ffi_catch_abort] #[no_mangle]
-pub extern "system" fn sq_error_free(error: Option<&mut failure::Error>) {
- ffi_free!(error)
+trait FromSequoiaError<'a> {
+ fn from_sequoia_error(&'a failure::Error) -> Status;
}
-/// Returns the error message.
-///
-/// The returned value must be freed with `free(3)`.
-#[::ffi_catch_abort] #[no_mangle]
-pub extern "system" fn sq_error_string(error: *const failure::Error)
- -> *mut c_char {
- let error = ffi_param_ref!(error);
- ffi_return_string!(&format!("{}", error))
-}
-
-/// Returns the error status code.
-#[::ffi_catch_abort] #[no_mangle]
-pub extern "system" fn sq_error_status(error: *const failure::Error)
- -> Status {
- let error = ffi_param_ref!(error);
- error.into()
-}
-
-/// XXX: Reorder and name-space before release.
-#[derive(PartialEq, Debug)]
-#[repr(C)]
-pub enum Status {
- /// The operation was successful.
- Success = 0,
-
- /// An unknown error occurred.
- UnknownError = -1,
-
- /// The network policy was violated by the given action.
- NetworkPolicyViolation = -2,
-
- /// An IO error occurred.
- IoError = -3,
-
- /// A given argument is invalid.
- InvalidArgument = -15,
-
- /// The requested operation is invalid.
- InvalidOperation = -4,
-
- /// The packet is malformed.
- MalformedPacket = -5,
-
- /// Unsupported hash algorithm.
- UnsupportedHashAlgorithm = -9,
-
- /// Unsupported public key algorithm.
- UnsupportedPublicKeyAlgorithm = -18,
-
- /// Unsupported elliptic curve.
- UnsupportedEllipticCurve = -21,
-
- /// Unsupported symmetric algorithm.
- UnsupportedSymmetricAlgorithm = -10,
-
- /// Unsupported AEAD algorithm.
- UnsupportedAEADAlgorithm = -26,
-
- /// Unsupport signature type.
- UnsupportedSignatureType = -20,
-
- /// Invalid password.
- InvalidPassword = -11,
-
- /// Invalid session key.
- InvalidSessionKey = -12,
-
- /// Missing session key.
- MissingSessionKey = -27,
-
- /// Malformed TPK.
- MalformedTPK = -13,
-
- // XXX: -14 was UserIDNotFound.
-
- // XXX: Skipping InvalidArgument = -15.
-
- /// Malformed MPI.
- MalformedMPI = -16,
-
- // XXX: Skipping UnknownPublicKeyAlgorithm = -17.
- // XXX: Skipping UnsupportedPublicKeyAlgorithm = -18
-
- /// Bad signature.
- BadSignature = -19,
-
- /// Message has been manipulated.
- ManipulatedMessage = -25,
-
- // XXX: Skipping UnsupportedSignatureType = -20
- // XXX: Skipping UnsupportedEllipticCurve = -21
-
- /// Malformed message.
- MalformedMessage = -22,
-
- /// Index out of range.
- IndexOutOfRange = -23,
-
- /// TPK not supported.
- UnsupportedTPK = -24,
-
- // XXX: Skipping ManipulatedMessage = -25
- // XXX: Skipping UnsupportedAEADAlgorithm = -26
- // XXX: Skipping MissingSessionKey = -27
-}
-
-impl<'a> From<&'a failure::Error> for Status {
- fn from(e: &'a failure::Error) -> Self {
+impl<'a> FromSequoiaError<'a> for Status {
+ fn from_sequoia_error(e: &'a failure::Error) -> Self {
if let Some(e) = e.downcast_ref::<core::Error>() {
return match e {
&core::Error::NetworkPolicyViolation(_) =>