1use thiserror::Error;
4
5#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
9#[non_exhaustive]
10pub enum Error {
11 #[error("invalid configuration")]
13 InvalidConfiguration,
14 #[error("limit exceeded")]
16 LimitExceeded,
17 #[error("malformed envelope")]
19 MalformedEnvelope,
20 #[error("unsupported protocol version")]
22 UnsupportedVersion,
23 #[error("unsupported cryptographic suite")]
25 UnsupportedSuite,
26 #[error("unsupported HTTP method")]
28 UnsupportedMethod,
29 #[error("unknown recipient key")]
31 UnknownRecipientKey,
32 #[error("invalid credential")]
34 InvalidCredential,
35 #[error("authentication failed")]
37 AuthenticationFailed,
38 #[error("request replay rejected")]
40 ReplayRejected,
41 #[error("invalid request time")]
43 InvalidRequestTime,
44 #[error("replay decision does not match request")]
46 ReplayDecisionMismatch,
47 #[error("system clock unavailable")]
49 ClockUnavailable,
50 #[error("secure entropy unavailable")]
52 EntropyUnavailable,
53 #[error("cryptographic operation failed")]
55 CryptoFailure,
56}
57
58impl Error {
59 #[must_use]
61 pub const fn code(self) -> &'static str {
62 match self {
63 Self::InvalidConfiguration => "invalid_configuration",
64 Self::LimitExceeded => "limit_exceeded",
65 Self::MalformedEnvelope => "malformed_envelope",
66 Self::UnsupportedVersion => "unsupported_version",
67 Self::UnsupportedSuite => "unsupported_suite",
68 Self::UnsupportedMethod => "unsupported_method",
69 Self::UnknownRecipientKey => "unknown_recipient_key",
70 Self::InvalidCredential => "invalid_credential",
71 Self::AuthenticationFailed => "authentication_failed",
72 Self::ReplayRejected => "replay_rejected",
73 Self::InvalidRequestTime => "invalid_request_time",
74 Self::ReplayDecisionMismatch => "replay_decision_mismatch",
75 Self::ClockUnavailable => "clock_unavailable",
76 Self::EntropyUnavailable => "entropy_unavailable",
77 Self::CryptoFailure => "crypto_failure",
78 }
79 }
80}