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)]
11#[non_exhaustive]
12pub enum AlgorithmError {
13    /// The requested operation is not supported for this algorithm.
14    #[error("unsupported algorithm: {0}")]
15    UnsupportedAlgorithm(Algorithm),
16
17    /// The requested AEAD algorithm is not supported.
18    #[error("unsupported AEAD algorithm: {0}")]
19    UnsupportedAeadAlgorithm(AeadAlgorithm),
20
21    /// The requested hash algorithm is not supported.
22    #[error("unsupported hash algorithm: {0}")]
23    UnsupportedHashAlgorithm(HashAlgorithm),
24
25    /// The requested MAC algorithm is not supported.
26    #[error("unsupported MAC algorithm: {0}")]
27    UnsupportedMacAlgorithm(MacAlgorithm),
28
29    /// The supplied key is malformed or invalid for the algorithm.
30    #[error("invalid key for algorithm: {0}")]
31    InvalidKey(Algorithm),
32
33    /// A signature failed verification (dispatch fails closed here).
34    #[error("signature verification failed for {0}")]
35    SignatureInvalid(Algorithm),
36
37    /// An error propagated from an underlying crypto primitive.
38    #[error(transparent)]
39    Crypto(#[from] CryptoError),
40}