diff options
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/Cargo.toml | 2 | ||||
-rw-r--r-- | openpgp-ffi/src/armor.rs | 6 | ||||
-rw-r--r-- | openpgp-ffi/src/cert.rs | 2 | ||||
-rw-r--r-- | openpgp-ffi/src/common.rs | 6 | ||||
-rw-r--r-- | openpgp-ffi/src/error.rs | 17 | ||||
-rw-r--r-- | openpgp-ffi/src/io.rs | 12 | ||||
-rw-r--r-- | openpgp-ffi/src/lib.rs | 1 | ||||
-rw-r--r-- | openpgp-ffi/src/packet/pkesk.rs | 3 | ||||
-rw-r--r-- | openpgp-ffi/src/packet/skesk.rs | 3 | ||||
-rw-r--r-- | openpgp-ffi/src/parse/mod.rs | 4 | ||||
-rw-r--r-- | openpgp-ffi/src/parse/stream.rs | 10 | ||||
-rw-r--r-- | openpgp-ffi/src/serialize.rs | 10 | ||||
-rw-r--r-- | openpgp-ffi/tests/c-tests.rs | 3 |
13 files changed, 37 insertions, 42 deletions
diff --git a/openpgp-ffi/Cargo.toml b/openpgp-ffi/Cargo.toml index 7e3277ca..7afedee4 100644 --- a/openpgp-ffi/Cargo.toml +++ b/openpgp-ffi/Cargo.toml @@ -24,7 +24,7 @@ maintenance = { status = "actively-developed" } [dependencies] sequoia-ffi-macros = { path = "../ffi-macros", version = "0.15" } sequoia-openpgp = { path = "../openpgp", version = "0.15" } -failure = "0.1.2" +anyhow = "1" lazy_static = "1.0.0" libc = "0.2.33" memsec = "0.5.6" diff --git a/openpgp-ffi/src/armor.rs b/openpgp-ffi/src/armor.rs index a083c573..dd79c9e3 100644 --- a/openpgp-ffi/src/armor.rs +++ b/openpgp-ffi/src/armor.rs @@ -143,7 +143,7 @@ pub extern "C" fn pgp_armor_reader_from_file(errp: Option<&mut *mut crate::error armor::Reader::from_file(&filename, mode) .map(|r| ReaderKind::Armored(r)) - .map_err(|e| ::failure::Error::from(e)) + .map_err(|e| ::anyhow::Error::from(e)) .move_into_raw(errp) } @@ -270,7 +270,7 @@ pub extern "C" fn pgp_armor_reader_headers(errp: Option<&mut *mut crate::error:: expected armor reader"); }; - match reader.headers().map_err(|e| ::failure::Error::from(e)) { + match reader.headers().map_err(|e| ::anyhow::Error::from(e)) { Ok(headers) => { // Allocate space for the result. let buf = unsafe { @@ -391,7 +391,7 @@ pub extern "C" fn pgp_armor_writer_new armor::Writer::new(inner, kind, &header) .map(|w| WriterKind::Armored(w)) - .map_err(|e| ::failure::Error::from(e)) + .map_err(|e| ::anyhow::Error::from(e)) .move_into_raw(errp) } diff --git a/openpgp-ffi/src/cert.rs b/openpgp-ffi/src/cert.rs index a1c42337..d0b83e0f 100644 --- a/openpgp-ffi/src/cert.rs +++ b/openpgp-ffi/src/cert.rs @@ -1012,7 +1012,7 @@ pub extern "C" fn pgp_cert_builder_generate }, Err(e) => { *cert_out = None; - Err::<(), failure::Error>(e).move_into_raw(errp) + Err::<(), anyhow::Error>(e).move_into_raw(errp) }, } } diff --git a/openpgp-ffi/src/common.rs b/openpgp-ffi/src/common.rs index 592c4776..f212c2a1 100644 --- a/openpgp-ffi/src/common.rs +++ b/openpgp-ffi/src/common.rs @@ -150,7 +150,7 @@ macro_rules! ffi_make_fry_from_errp { Ok(_) => crate::error::Status::Success, Err(e) => { use crate::MoveIntoRaw; - use failure::Error; + use anyhow::Error; let status = crate::error::Status::from(&e); if let Some(errp) = $errp { let e : Error = e.into(); @@ -174,7 +174,7 @@ macro_rules! ffi_make_fry_from_errp { Ok(v) => v, Err(e) => { use crate::MoveIntoRaw; - use failure::Error; + use anyhow::Error; let status = crate::error::Status::from(&e); if let Some(errp) = $errp { let e : Error = e.into(); @@ -197,7 +197,7 @@ macro_rules! ffi_make_fry_from_errp { Ok(v) => v, Err(e) => { use crate::MoveIntoRaw; - use failure::Error; + use anyhow::Error; if let Some(errp) = $errp { let e : Error = e.into(); *errp = e.move_into_raw(); diff --git a/openpgp-ffi/src/error.rs b/openpgp-ffi/src/error.rs index 01e4ed44..5b2bc06d 100644 --- a/openpgp-ffi/src/error.rs +++ b/openpgp-ffi/src/error.rs @@ -1,6 +1,5 @@ //! Maps various errors to status codes. -use failure; use std::io; use libc::c_char; @@ -11,14 +10,14 @@ use crate::RefRaw; /// Complex errors. /// -/// This wraps [`failure::Error`]s. +/// This wraps [`anyhow::Error`]s. /// -/// [`failure::Error`]: https://docs.rs/failure/0.1.5/failure/struct.Error.html +/// [`anyhow::Error`]: https://docs.rs/failure/0.1.5/failure/struct.Error.html #[crate::ffi_wrapper_type(prefix = "pgp_", derive = "Display")] -pub struct Error(failure::Error); +pub struct Error(anyhow::Error); -impl<T> From<failure::Fallible<T>> for Status { - fn from(f: failure::Fallible<T>) -> crate::error::Status { +impl<T> From<anyhow::Result<T>> for Status { + fn from(f: anyhow::Result<T>) -> crate::error::Status { match f { Ok(_) => crate::error::Status::Success, Err(e) => crate::error::Status::from(&e), @@ -26,7 +25,7 @@ impl<T> From<failure::Fallible<T>> for Status { } } -impl crate::MoveResultIntoRaw<crate::error::Status> for ::failure::Fallible<()> +impl crate::MoveResultIntoRaw<crate::error::Status> for ::anyhow::Result<()> { fn move_into_raw(self, errp: Option<&mut *mut crate::error::Error>) -> crate::error::Status { @@ -210,8 +209,8 @@ pub extern "C" fn pgp_status_to_string(status: Status) -> *const c_char { }.as_bytes().as_ptr() as *const c_char } -impl<'a> From<&'a failure::Error> for Status { - fn from(e: &'a failure::Error) -> Self { +impl<'a> From<&'a anyhow::Error> for Status { + fn from(e: &'a anyhow::Error) -> Self { if let Some(e) = e.downcast_ref::<openpgp::Error>() { return match e { &openpgp::Error::InvalidArgument(_) => diff --git a/openpgp-ffi/src/io.rs b/openpgp-ffi/src/io.rs index c9e96557..953ec4b2 100644 --- a/openpgp-ffi/src/io.rs +++ b/openpgp-ffi/src/io.rs @@ -47,7 +47,7 @@ pub extern "C" fn pgp_reader_from_file(errp: Option<&mut *mut crate::error::Erro let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned(); File::open(Path::new(&filename)) .map(|r| ReaderKind::Generic(Box::new(r))) - .map_err(|e| ::failure::Error::from(e)) + .map_err(|e| ::anyhow::Error::from(e)) .move_into_raw(errp) } @@ -123,7 +123,7 @@ pub extern "C" fn pgp_reader_read(errp: Option<&mut *mut crate::error::Error>, .map(|n_read| n_read as ssize_t) .unwrap_or_else(|e| { if let Some(errp) = errp { - *errp = ::failure::Error::from(e).move_into_raw(); + *errp = ::anyhow::Error::from(e).move_into_raw(); }; // Signal failure. @@ -145,7 +145,7 @@ pub extern "C" fn pgp_reader_copy(errp: Option<&mut *mut crate::error::Error>, .map(|n_read| n_read as ssize_t) .unwrap_or_else(|e| { if let Some(errp) = errp { - *errp = ::failure::Error::from(e).move_into_raw(); + *errp = ::anyhow::Error::from(e).move_into_raw(); }; // Signal failure. @@ -164,7 +164,7 @@ pub extern "C" fn pgp_reader_discard(errp: Option<&mut *mut crate::error::Error> .map(|n_read| n_read as ssize_t) .unwrap_or_else(|e| { if let Some(errp) = errp { - *errp = ::failure::Error::from(e).move_into_raw(); + *errp = ::anyhow::Error::from(e).move_into_raw(); }; // Signal failure. @@ -215,7 +215,7 @@ fn pgp_writer_from_file(errp: Option<&mut *mut crate::error::Error>, let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned(); File::create(Path::new(&filename)) .map(|w| WriterKind::Generic(Box::new(w))) - .map_err(|e| ::failure::Error::from(e)) + .map_err(|e| ::anyhow::Error::from(e)) .move_into_raw(errp) } @@ -348,7 +348,7 @@ fn pgp_writer_write(errp: Option<&mut *mut crate::error::Error>, .map(|n_read| n_read as ssize_t) .unwrap_or_else(|e| { if let Some(errp) = errp { - *errp = ::failure::Error::from(e).move_into_raw(); + *errp = ::anyhow::Error::from(e).move_into_raw(); }; // Signal failure. diff --git a/openpgp-ffi/src/lib.rs b/openpgp-ffi/src/lib.rs index a3991f50..28cba4f1 100644 --- a/openpgp-ffi/src/lib.rs +++ b/openpgp-ffi/src/lib.rs @@ -315,7 +315,6 @@ #![warn(missing_docs)] -extern crate failure; #[macro_use] extern crate lazy_static; extern crate libc; diff --git a/openpgp-ffi/src/packet/pkesk.rs b/openpgp-ffi/src/packet/pkesk.rs index 50845fe8..a00c4ff0 100644 --- a/openpgp-ffi/src/packet/pkesk.rs +++ b/openpgp-ffi/src/packet/pkesk.rs @@ -1,6 +1,5 @@ //! Asymmetrically encrypted session keys. -use failure; use libc::size_t; extern crate sequoia_openpgp as openpgp; @@ -61,7 +60,7 @@ pub extern "C" fn pgp_pkesk_decrypt(errp: Option<&mut *mut crate::error::Error>, *key_len = k.len(); Status::Success }, - Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)), + Err(e) => ffi_try_status!(Err::<(), anyhow::Error>(e)), } }, Err(e) => { diff --git a/openpgp-ffi/src/packet/skesk.rs b/openpgp-ffi/src/packet/skesk.rs index 95b276a5..cf4ba297 100644 --- a/openpgp-ffi/src/packet/skesk.rs +++ b/openpgp-ffi/src/packet/skesk.rs @@ -3,7 +3,6 @@ use std::slice; use libc::size_t; -use failure; extern crate sequoia_openpgp as openpgp; use super::Packet; @@ -47,7 +46,7 @@ pub extern "C" fn pgp_skesk_decrypt(errp: Option<&mut *mut crate::error::Error>, *key_len = k.len(); Status::Success }, - Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)), + Err(e) => ffi_try_status!(Err::<(), anyhow::Error>(e)), } } else { panic!("Not a SKESK packet"); diff --git a/openpgp-ffi/src/parse/mod.rs b/openpgp-ffi/src/parse/mod.rs index a2569b2b..d3ed1407 100644 --- a/openpgp-ffi/src/parse/mod.rs +++ b/openpgp-ffi/src/parse/mod.rs @@ -216,7 +216,7 @@ pub extern "C" fn pgp_packet_parser_next<'a> } Status::Success }, - Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)), + Err(e) => ffi_try_status!(Err::<(), anyhow::Error>(e)), } } @@ -260,7 +260,7 @@ pub extern "C" fn pgp_packet_parser_recurse<'a> } Status::Success }, - Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)), + Err(e) => ffi_try_status!(Err::<(), anyhow::Error>(e)), } } diff --git a/openpgp-ffi/src/parse/stream.rs b/openpgp-ffi/src/parse/stream.rs index eb2d28fe..b36bb640 100644 --- a/openpgp-ffi/src/parse/stream.rs +++ b/openpgp-ffi/src/parse/stream.rs @@ -451,7 +451,7 @@ impl VHelper { impl VerificationHelper for VHelper { fn get_public_keys(&mut self, ids: &[openpgp::KeyHandle]) - -> Result<Vec<openpgp::Cert>, failure::Error> + -> Result<Vec<openpgp::Cert>, anyhow::Error> { // The size of ID is not known in C. Convert to KeyID, and // move it to C. @@ -496,7 +496,7 @@ impl VerificationHelper for VHelper { } fn check(&mut self, structure: stream::MessageStructure) - -> Result<(), failure::Error> + -> Result<(), anyhow::Error> { let result = (self.check_signatures_cb)(self.cookie, structure.move_into_raw()); @@ -784,13 +784,13 @@ impl DHelper { impl VerificationHelper for DHelper { fn get_public_keys(&mut self, ids: &[openpgp::KeyHandle]) - -> Result<Vec<openpgp::Cert>, failure::Error> + -> Result<Vec<openpgp::Cert>, anyhow::Error> { self.vhelper.get_public_keys(ids) } fn check(&mut self, structure: stream::MessageStructure) - -> Result<(), failure::Error> + -> Result<(), anyhow::Error> { self.vhelper.check(structure) } @@ -802,7 +802,7 @@ impl DecryptionHelper for DHelper { match cb(self.vhelper.cookie, pp) { Status::Success => Ok(()), // XXX: Convert the status to an error better. - status => Err(failure::format_err!( + status => Err(anyhow::anyhow!( "Inspect Callback returned an error: {:?}", status).into()), } } else { diff --git a/openpgp-ffi/src/serialize.rs b/openpgp-ffi/src/serialize.rs index 1f16b7d5..dbbb537c 100644 --- a/openpgp-ffi/src/serialize.rs +++ b/openpgp-ffi/src/serialize.rs @@ -63,7 +63,7 @@ pub extern "C" fn pgp_writer_stack_write let buf = unsafe { slice::from_raw_parts(buf, len as usize) }; - ffi_try_or!(writer.write(buf).map_err(|e| ::failure::Error::from(e)), -1) as ssize_t + ffi_try_or!(writer.write(buf).map_err(|e| ::anyhow::Error::from(e)), -1) as ssize_t } /// Writes up to `len` bytes of `buf` into `writer`. @@ -84,7 +84,7 @@ pub extern "C" fn pgp_writer_stack_write_all let buf = unsafe { slice::from_raw_parts(buf, len as usize) }; - ffi_try_status!(writer.write_all(buf).map_err(|e| ::failure::Error::from(e))) + ffi_try_status!(writer.write_all(buf).map_err(|e| ::anyhow::Error::from(e))) } /// Finalizes this writer, returning the underlying writer. @@ -168,7 +168,7 @@ pub extern "C" fn pgp_signer_new let mut signer = Signer::new(*inner, ffi_try!(signers.pop().ok_or_else(|| { - failure::format_err!("signers is empty") + anyhow::anyhow!("signers is empty") }))); for s in signers { signer = signer.add_signer(s); @@ -205,7 +205,7 @@ pub extern "C" fn pgp_signer_new_detached let mut signer = Signer::new(*inner, ffi_try!(signers.pop().ok_or_else(|| { - failure::format_err!("signers is empty") + anyhow::anyhow!("signers is empty") }))); for s in signers { signer = signer.add_signer(s); @@ -386,7 +386,7 @@ pub extern "C" fn pgp_encryptor_new<'a> Some(aead_algo.into()) }; if passwords_.len() + recipients_.len() == 0 { - ffi_try!(Err(failure::format_err!( + ffi_try!(Err(anyhow::anyhow!( "Neither recipient nor password given"))); } diff --git a/openpgp-ffi/tests/c-tests.rs b/openpgp-ffi/tests/c-tests.rs index fff25f55..8dc38227 100644 --- a/openpgp-ffi/tests/c-tests.rs +++ b/openpgp-ffi/tests/c-tests.rs @@ -1,5 +1,4 @@ -extern crate failure; -use failure::{Fallible as Result, ResultExt}; +use anyhow::{Result, Context}; extern crate filetime; use std::cmp::min; |