scrambledb/
error.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum Error {
3    RandomnessError,
4    CorruptedData,
5    InvalidInput,
6}
7
8impl From<oprf::Error> for Error {
9    fn from(value: oprf::Error) -> Self {
10        match value {
11            oprf::Error::InvalidInputError => Self::CorruptedData,
12            oprf::Error::DeriveKeyPairError => Self::RandomnessError,
13            oprf::Error::CurveError => Self::CorruptedData,
14            oprf::Error::HashToCurveError => Self::CorruptedData,
15            oprf::Error::ElgamalError => Self::RandomnessError,
16            oprf::Error::RandomnessError => Self::RandomnessError,
17        }
18    }
19}
20
21impl From<libcrux::hpke::errors::HpkeError> for Error {
22    fn from(_value: libcrux::hpke::errors::HpkeError) -> Self {
23        Self::CorruptedData
24    }
25}
26
27impl From<hacspec_lib::Error> for Error {
28    fn from(value: hacspec_lib::Error) -> Self {
29        match value {
30            hacspec_lib::Error::InsufficientRandomness => Self::RandomnessError,
31        }
32    }
33}
34
35impl From<std::array::TryFromSliceError> for Error {
36    fn from(_value: std::array::TryFromSliceError) -> Self {
37        Self::RandomnessError
38    }
39}
40
41impl From<p256::Error> for Error {
42    fn from(value: p256::Error) -> Self {
43        match value {
44            p256::Error::InvalidAddition => Self::CorruptedData,
45            p256::Error::DeserializeError => Self::CorruptedData,
46            p256::Error::PointAtInfinity => Self::CorruptedData,
47            p256::Error::SamplingError => Self::RandomnessError,
48        }
49    }
50}
51
52impl From<elgamal::Error> for Error {
53    fn from(value: elgamal::Error) -> Self {
54        match value {
55            elgamal::Error::CurveError => Self::CorruptedData,
56            elgamal::Error::SamplingError => Self::RandomnessError,
57        }
58    }
59}