ecdh_omr/
error.rs

1// SPDX-FileCopyrightText: 2024 eaon <eaon@posteo.net>
2// SPDX-License-Identifier: EUPL-1.2
3
4/// Error type.
5#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
6pub enum Error {
7    /// An AEAD related error.
8    Aead(aead::Error),
9    /// Message length must be static per application, if it isn't this is returned.
10    MessageLength,
11    /// [`Hint`](crate::Hint), [`Hints`](crate::Hints) or
12    /// [`BlindedPublicKey`](crate::BlindedPublicKey) decoding error. All of these types have their
13    /// raw bytes naïvely concatenated and have an static length dependent on the application's
14    /// specifications. Deviation will result in this error.
15    Decoding,
16    /// [`Hints`](crate::Hints) always assemble a static amount of [`Hint`](crate::Hint) instances.
17    /// This error is the result of an overflow in the type's creation, as well as deviation in any
18    /// direction after decoding.
19    HintsLength,
20}
21
22impl std::fmt::Display for Error {
23    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
24        match self {
25            Error::Aead(error) => f.write_str(&format!("{}", error)),
26            Error::MessageLength => f.write_str("ecdh_omr::Error::MessageLength"),
27            Error::Decoding => f.write_str("ecdh_omr::Error::Decoding"),
28            Error::HintsLength => f.write_str("ecdh_omr::Error::HintsLength"),
29        }
30    }
31}
32
33impl std::error::Error for Error {}
34
35impl From<aead::Error> for Error {
36    fn from(error: aead::Error) -> Error {
37        Error::Aead(error)
38    }
39}
40
41pub(crate) type Result<T> = std::result::Result<T, Error>;