1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
//! Maps various errors to status codes.
use failure;
use std::io;
extern crate sequoia_openpgp as openpgp;
use sequoia_core as core;
pub use openpgp::error::Status;
pub(crate) use ::openpgp::error::Error;
trait FromSequoiaError<'a> {
fn from_sequoia_error(&'a failure::Error) -> Status;
}
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(_) =>
Status::NetworkPolicyViolation,
&core::Error::IoError(_) =>
Status::IoError,
}
}
if let Some(e) = e.downcast_ref::<openpgp::Error>() {
return match e {
&openpgp::Error::InvalidArgument(_) =>
Status::InvalidArgument,
&openpgp::Error::InvalidOperation(_) =>
Status::InvalidOperation,
&openpgp::Error::MalformedPacket(_) =>
Status::MalformedPacket,
&openpgp::Error::UnsupportedHashAlgorithm(_) =>
Status::UnsupportedHashAlgorithm,
&openpgp::Error::UnsupportedPublicKeyAlgorithm(_) =>
Status::UnsupportedPublicKeyAlgorithm,
&openpgp::Error::UnsupportedEllipticCurve(_) =>
Status::UnsupportedEllipticCurve,
&openpgp::Error::UnsupportedSymmetricAlgorithm(_) =>
Status::UnsupportedSymmetricAlgorithm,
&openpgp::Error::UnsupportedAEADAlgorithm(_) =>
Status::UnsupportedAEADAlgorithm,
&openpgp::Error::UnsupportedSignatureType(_) =>
Status::UnsupportedSignatureType,
&openpgp::Error::InvalidPassword =>
Status::InvalidPassword,
&openpgp::Error::InvalidSessionKey(_) =>
Status::InvalidSessionKey,
&openpgp::Error::MissingSessionKey(_) =>
Status::MissingSessionKey,
&openpgp::Error::MalformedMPI(_) =>
Status::MalformedMPI,
&openpgp::Error::BadSignature(_) =>
Status::BadSignature,
&openpgp::Error::ManipulatedMessage =>
Status::ManipulatedMessage,
&openpgp::Error::MalformedMessage(_) =>
Status::MalformedMessage,
&openpgp::Error::MalformedTPK(_) =>
Status::MalformedTPK,
&openpgp::Error::IndexOutOfRange =>
Status::IndexOutOfRange,
&openpgp::Error::UnsupportedTPK(_) =>
Status::UnsupportedTPK,
}
}
if let Some(_) = e.downcast_ref::<io::Error>() {
return Status::IoError;
}
eprintln!("ffi: Error not converted: {}", e);
Status::UnknownError
}
}
|