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
|
#[derive(Debug)]
pub enum Error {
/// A problem occurred with the AEAD.
#[cfg(feature = "rust-hpke")]
Aead(aead::Error),
/// A problem occurred during cryptographic processing.
#[cfg(feature = "nss")]
Crypto(crate::nss::Error),
/// An error was found in the format.
Format,
/// A problem occurred with HPKE.
#[cfg(feature = "rust-hpke")]
Hpke(::hpke::HpkeError),
/// An internal error occurred.
Internal,
/// The wrong type of key was provided for the selected KEM.
InvalidKeyType,
/// The wrong KEM was specified.
InvalidKem,
/// An IO error.
Io(std::io::Error),
/// The key ID was invalid.
KeyId,
/// A field was truncated.
Truncated,
/// The configuration was not supported.
Unsupported,
/// The configuration contained too many symmetric suites.
TooManySymmetricSuites,
}
macro_rules! forward_errors {
{$($(#[$m:meta])* $t:path => $v:ident),* $(,)?} => {
$(
$(#[$m])*
impl From<$t> for Error {
fn from(e: $t) -> Self {
Self::$v(e)
}
}
)*
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
$( $(#[$m])* Self::$v(e) => Some(e), )*
_ => None,
}
}
}
};
}
forward_errors! {
#[cfg(feature = "rust-hpke")]
aead::Error => Aead,
#[cfg(feature = "nss")]
crate::nss::Error => Crypto,
#[cfg(feature = "rust-hpke")]
::hpke::HpkeError => Hpke,
std::io::Error => Io,
}
impl From<std::num::TryFromIntError> for Error {
fn from(_v: std::num::TryFromIntError) -> Self {
Self::TooManySymmetricSuites
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(f, "{:?}", self)
}
}
pub type Res<T> = Result<T, Error>;
|