Skip to main content

structured_dstu4145/
error.rs

1use core::fmt;
2
3/// Invalid input and unavailable capabilities, independent of signature mismatch.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum Error {
7    /// A field, basis or domain is outside the implemented capability.
8    UnsupportedDomain,
9    /// A polynomial fails the required field checks.
10    InvalidField,
11    /// Curve coefficients, order or base point fail domain validation.
12    InvalidDomain,
13    /// A custom domain needs independent primitivity/primality evidence.
14    ValidationEvidenceRequired,
15    /// The caller's random source failed to produce a usable bounded sample.
16    RandomSampleRefused,
17    /// The public point is malformed, off-curve or outside the subgroup.
18    InvalidKey,
19    /// The selected encoding has an invalid length or nonzero unused bits.
20    InvalidEncoding,
21    /// A packed substitution table is not eight permutations of 0 through 15.
22    InvalidDke,
23    /// The requested hash output length is unsupported.
24    InvalidOutputSize,
25    /// An input exceeds the bounded interface or hash-length representation.
26    InputTooLong,
27}
28
29impl fmt::Display for Error {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        f.write_str(match self {
32            Self::UnsupportedDomain => "unsupported DSTU domain",
33            Self::InvalidField => "invalid DSTU field",
34            Self::InvalidDomain => "invalid DSTU domain",
35            Self::ValidationEvidenceRequired => "custom domain validation evidence required",
36            Self::RandomSampleRefused => "random sampling bound exhausted",
37            Self::InvalidKey => "invalid DSTU public key",
38            Self::InvalidEncoding => "invalid DSTU encoding",
39            Self::InvalidDke => "invalid GOST substitution table",
40            Self::InvalidOutputSize => "invalid hash output size",
41            Self::InputTooLong => "input exceeds the supported bound",
42        })
43    }
44}
45
46impl core::error::Error for Error {}