Skip to main content

zaun_community_protocol/crypto/
error.rs

1//! Signing and verification errors.
2
3use crate::ids::RngError;
4
5/// Signing failed.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
7pub enum SignError {
8    /// The OS CSPRNG failed while drawing the hedging randomness.
9    #[error(transparent)]
10    Rng(#[from] RngError),
11    /// The context is longer than 255 bytes (never for a [`super::Context`]).
12    #[error("context longer than 255 bytes")]
13    ContextTooLong,
14    /// ML-DSA signing failed (deterministic variant only; FIPS 204 rejection-sampling bound).
15    #[error("ML-DSA signing failed")]
16    MlDsa,
17}
18
19/// Verification failed. Callers map every variant to `INVALID_SIGNATURE`; the variants exist
20/// for tests and diagnostics only.
21#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
22pub enum VerifyError {
23    /// The key's and the signature's suite bytes differ (§3.3 step 1).
24    #[error("signature suite {sig} differs from key suite {key}")]
25    SuiteMismatch {
26        /// The key's suite byte.
27        key: u8,
28        /// The signature's suite byte.
29        sig: u8,
30    },
31    /// The suite is below the community's `min_suite` (§3.3 step 1, downgrade protection).
32    #[error("suite {suite} is below the minimum suite {min_suite}")]
33    SuiteBelowMinimum {
34        /// The signature's suite byte.
35        suite: u8,
36        /// The required minimum.
37        min_suite: u8,
38    },
39    /// The context is longer than 255 bytes.
40    #[error("context longer than 255 bytes")]
41    ContextTooLong,
42    /// The raw key or signature components have the wrong length.
43    #[error("malformed key or signature components")]
44    Malformed,
45    /// The ML-DSA-65 component did not verify (§3.3 step 3).
46    #[error("ML-DSA-65 component did not verify")]
47    MlDsa,
48    /// The Ed25519 component did not verify strictly (§3.3 step 4).
49    #[error("Ed25519 component did not verify")]
50    Ed25519,
51}