aranya_crypto/
error.rs

1#![forbid(unsafe_code)]
2
3use buggy::Bug;
4pub use spideroak_crypto::{
5    aead::{OpenError, SealError},
6    hpke::HpkeError,
7    import::{ExportError, ImportError},
8    kdf::KdfError,
9    kem::{EcdhError, KemError},
10    mac::MacError,
11    signer::{PkError, SignerError},
12};
13
14use crate::{
15    engine::{UnwrapError, WrapError},
16    id::IdError,
17};
18
19/// Encompasses the different errors directly returned by this
20/// crate.
21#[derive(Debug, Eq, PartialEq, thiserror::Error)]
22#[non_exhaustive]
23pub enum Error {
24    /// An argument was invalid.
25    ///
26    /// It describes why the argument is invalid.
27    #[error("invalid argument: {0}")]
28    InvalidArgument(&'static str),
29    /// An internal bug was discovered.
30    #[error(transparent)]
31    Bug(#[from] Bug),
32
33    /// An AEAD seal failure.
34    #[error(transparent)]
35    Seal(#[from] SealError),
36    /// An AEAD open failure.
37    #[error(transparent)]
38    Open(#[from] OpenError),
39    /// An ECDH failure.
40    #[error(transparent)]
41    Ecdh(#[from] EcdhError),
42    /// An HPKE failure.
43    #[error(transparent)]
44    Hpke(#[from] HpkeError),
45    /// A KDF failure.
46    #[error(transparent)]
47    Kdf(#[from] KdfError),
48    /// A KEM failure.
49    #[error(transparent)]
50    Kem(#[from] KemError),
51    /// A MAC failure.
52    #[error(transparent)]
53    Mac(#[from] MacError),
54    /// A digital signature failure.
55    #[error(transparent)]
56    Signer(#[from] SignerError),
57    /// An import failure.
58    #[error(transparent)]
59    Import(#[from] ImportError),
60    /// An export failure.
61    #[error(transparent)]
62    Export(#[from] ExportError),
63    /// A key wrapping failure.
64    #[error(transparent)]
65    Wrap(#[from] WrapError),
66    /// A key unwrapping failure.
67    #[error(transparent)]
68    Unwrap(#[from] UnwrapError),
69    /// An identifier failure.
70    #[error(transparent)]
71    Id(#[from] IdError),
72    /// A public key failure.
73    #[error(transparent)]
74    Pk(#[from] PkError),
75}
76
77#[cfg(feature = "afc")]
78impl Error {
79    pub(crate) const fn same_device_id() -> Self {
80        Self::InvalidArgument("same `DeviceId`")
81    }
82}