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
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
    RandomnessError,
    CorruptedData,
    InvalidInput,
}

impl From<oprf::Error> for Error {
    fn from(value: oprf::Error) -> Self {
        match value {
            oprf::Error::InvalidInputError => Self::CorruptedData,
            oprf::Error::DeriveKeyPairError => Self::RandomnessError,
            oprf::Error::CurveError => Self::CorruptedData,
            oprf::Error::HashToCurveError => Self::CorruptedData,
            oprf::Error::ElgamalError => Self::RandomnessError,
            oprf::Error::RandomnessError => Self::RandomnessError,
        }
    }
}

impl From<libcrux::hpke::errors::HpkeError> for Error {
    fn from(_value: libcrux::hpke::errors::HpkeError) -> Self {
        Self::CorruptedData
    }
}

impl From<hacspec_lib::Error> for Error {
    fn from(value: hacspec_lib::Error) -> Self {
        match value {
            hacspec_lib::Error::InsufficientRandomness => Self::RandomnessError,
        }
    }
}

impl From<std::array::TryFromSliceError> for Error {
    fn from(_value: std::array::TryFromSliceError) -> Self {
        Self::RandomnessError
    }
}

impl From<p256::Error> for Error {
    fn from(value: p256::Error) -> Self {
        match value {
            p256::Error::InvalidAddition => Self::CorruptedData,
            p256::Error::DeserializeError => Self::CorruptedData,
            p256::Error::PointAtInfinity => Self::CorruptedData,
            p256::Error::SamplingError => Self::RandomnessError,
        }
    }
}

impl From<elgamal::Error> for Error {
    fn from(value: elgamal::Error) -> Self {
        match value {
            elgamal::Error::CurveError => Self::CorruptedData,
            elgamal::Error::SamplingError => Self::RandomnessError,
        }
    }
}