ecdh-omr 0.2.0

ECDH based Oblivious Message Retrieval
Documentation
// SPDX-FileCopyrightText: 2024 eaon <eaon@posteo.net>
// SPDX-License-Identifier: EUPL-1.2

/// Error type.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum Error {
    /// An AEAD related error.
    Aead(aead::Error),
    /// Message length must be static per application, if it isn't this is returned.
    MessageLength,
    /// [`Hint`](crate::Hint), [`Hints`](crate::Hints) or
    /// [`BlindedPublicKey`](crate::BlindedPublicKey) decoding error. All of these types have their
    /// raw bytes naïvely concatenated and have an static length dependent on the application's
    /// specifications. Deviation will result in this error.
    Decoding,
    /// [`Hints`](crate::Hints) always assemble a static amount of [`Hint`](crate::Hint) instances.
    /// This error is the result of an overflow in the type's creation, as well as deviation in any
    /// direction after decoding.
    HintsLength,
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Error::Aead(error) => f.write_str(&format!("{}", error)),
            Error::MessageLength => f.write_str("ecdh_omr::Error::MessageLength"),
            Error::Decoding => f.write_str("ecdh_omr::Error::Decoding"),
            Error::HintsLength => f.write_str("ecdh_omr::Error::HintsLength"),
        }
    }
}

impl std::error::Error for Error {}

impl From<aead::Error> for Error {
    fn from(error: aead::Error) -> Error {
        Error::Aead(error)
    }
}

pub(crate) type Result<T> = std::result::Result<T, Error>;