Skip to main content

crypto_dispatch/
error.rs

1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: Apache-2.0
4
5use thiserror::Error;
6
7use crypto_core::{AeadAlgorithm, Algorithm, CryptoError, HashAlgorithm, MacAlgorithm};
8
9/// Error returned by algorithm dispatch operations.
10#[derive(Debug, Error)]
11pub enum AlgorithmError {
12    /// The requested operation is not supported for this algorithm.
13    #[error("unsupported algorithm: {0}")]
14    UnsupportedAlgorithm(Algorithm),
15
16    /// The requested AEAD algorithm is not supported.
17    #[error("unsupported AEAD algorithm: {0}")]
18    UnsupportedAeadAlgorithm(AeadAlgorithm),
19
20    /// The requested hash algorithm is not supported.
21    #[error("unsupported hash algorithm: {0}")]
22    UnsupportedHashAlgorithm(HashAlgorithm),
23
24    /// The requested MAC algorithm is not supported.
25    #[error("unsupported MAC algorithm: {0}")]
26    UnsupportedMacAlgorithm(MacAlgorithm),
27
28    /// The supplied key is malformed or invalid for the algorithm.
29    #[error("invalid key for algorithm: {0}")]
30    InvalidKey(Algorithm),
31
32    /// A signature failed verification (dispatch fails closed here).
33    #[error("signature verification failed for {0}")]
34    SignatureInvalid(Algorithm),
35
36    /// An error propagated from an underlying crypto primitive.
37    #[error(transparent)]
38    Crypto(#[from] CryptoError),
39}