summaryrefslogtreecommitdiffstats
path: root/ffi/src/error.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-17 11:11:27 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-17 16:48:28 +0100
commit3f58832474a4b270e136544016a401ef773ac065 (patch)
treec617160250c3040ca964c1b72ab5957cd872b82f /ffi/src/error.rs
parent38b4108cc1eac851ac17932c5c33623dd535bebb (diff)
openpgp-ffi: New crate.
- This creates a new crate, 'sequoia-openpgp-ffi', and moves a handful of functions from 'sequoia-ffi' to it. - The 'sequoia-ffi' crate is a superset of the 'sequoia-openpgp-ffi' crate. This is accomplished by some include! magic. - My first attempt involved having 'sequoia-ffi' depend on 'sequoia-openpgp-ffi', so that the former just re-exports the symbols. However, that turned out to be unreliable, and might be not what we want, because it could also duplicate parts of Rust's standard library. - Fixes #144.
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(_) =>