wamu_core/errors.rs
1//! Types and abstractions for protocol errors.
2
3/// A protocol error.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Error {
6 /// Arithmetic error.
7 Arithmetic(ArithmeticError),
8 /// A cryptography error.
9 Crypto(CryptoError),
10 /// Encoding error.
11 Encoding,
12 /// A signature from an unauthorized party.
13 UnauthorizedParty,
14}
15
16/// An arithmetic error.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum ArithmeticError {
19 /// The provided value is larger than the modulus
20 /// (e.g values larger than the curve order for elliptic curve operations).
21 ModulusOverflow,
22}
23
24impl From<ArithmeticError> for Error {
25 fn from(error: ArithmeticError) -> Self {
26 Self::Arithmetic(error)
27 }
28}
29
30impl From<CryptoError> for Error {
31 fn from(error: CryptoError) -> Self {
32 Self::Crypto(error)
33 }
34}
35
36/// A low-level cryptography error.
37#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38pub enum CryptoError {
39 /// An invalid signature for the message.
40 InvalidSignature,
41 /// An invalid verifying key.
42 InvalidVerifyingKey,
43 /// A signature algorithm and/or elliptic curve mismatch between the verifying key and signature.
44 SchemeMismatch,
45 /// An unsupported cryptographic scheme algorithm (e.g unsupported combination of signature algorithm and elliptic curve).
46 UnsupportedScheme,
47 /// An unsupported hash function.
48 UnsupportedDigest,
49 /// An unsupported encoding standard (e.g for either the verifying key or the signature).
50 UnsupportedEncoding,
51}
52
53/// An identity authenticated request verification error.
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55pub enum IdentityAuthedRequestError {
56 /// Not the expected command.
57 CommandMismatch,
58 /// An expired request i.e initiated too far in the past.
59 Expired,
60 /// A request with an invalid timestamp i.e a timestamp too far in the future.
61 InvalidTimestamp,
62 /// A request with either an invalid signature or an unauthorized signer.
63 Unauthorized(Error),
64}
65
66/// Implements `From<Error>` and `From<CryptoError>` for the error type.
67macro_rules! impl_from_error {
68 ($error_type:path) => {
69 impl From<Error> for $error_type {
70 fn from(error: Error) -> Self {
71 Self::Unauthorized(error)
72 }
73 }
74
75 impl From<CryptoError> for $error_type {
76 fn from(error: CryptoError) -> Self {
77 Self::Unauthorized(Error::Crypto(error))
78 }
79 }
80 };
81}
82
83// Implements `From<Error>` and `From<CryptoError>` for `IdentityAuthedRequestError`.
84impl_from_error!(IdentityAuthedRequestError);
85
86/// An identity authenticated request verification error.
87#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88pub enum QuorumApprovedRequestError {
89 /// Not enough approvals to form a quorum.
90 InsufficientApprovals,
91 /// A request with either an invalid signature or an unauthorized signer.
92 Unauthorized(Error),
93}
94
95// Implements `From<Error>` and `From<CryptoError>` for `QuorumApprovedRequestError`.
96impl_from_error!(QuorumApprovedRequestError);
97
98/// A share backup or recovery error.
99#[derive(Debug)]
100pub enum ShareBackupRecoveryError {
101 /// Encrypted data can't be converted into a valid signing share e.g decrypted output that's not 32 bytes long.
102 InvalidSigningShare,
103 /// Encrypted data can't be converted into a valid sub share e.g decrypted output that's not 32 bytes long.
104 InvalidSubShare,
105 /// An encryption/decryption error.
106 EncryptionError(aes_gcm::Error),
107}
108
109impl From<aes_gcm::Error> for ShareBackupRecoveryError {
110 fn from(error: aes_gcm::Error) -> Self {
111 ShareBackupRecoveryError::EncryptionError(error)
112 }
113}