falcon_multisig/error.rs
1//! Error types for the falcon-multisig library.
2
3use thiserror::Error;
4
5/// All errors that can be produced by this library.
6#[derive(Debug, Error, Clone, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum Error {
9 /// The supplied public key has an incorrect byte length.
10 ///
11 /// Falcon-512 public keys must be exactly [`crate::PUBLIC_KEY_BYTES`] bytes.
12 #[error("invalid public key length: expected {expected} bytes, got {actual}")]
13 InvalidPublicKeyLength {
14 /// The required length.
15 expected: usize,
16 /// The actual length received.
17 actual: usize,
18 },
19
20 /// The supplied signature has an incorrect or out-of-range byte length.
21 #[error("invalid signature length: {actual} bytes (valid range {min}..={max})")]
22 InvalidSignatureLength {
23 /// Actual length received.
24 actual: usize,
25 /// Inclusive minimum valid length.
26 min: usize,
27 /// Inclusive maximum valid length.
28 max: usize,
29 },
30
31 /// Cryptographic verification of a Falcon-512 signature failed.
32 ///
33 /// This is returned by [`crate::verify::verify_partial`] and
34 /// [`crate::session::SigningSession::add_signature`] when the raw
35 /// Falcon-512 check does not pass.
36 #[error("signature verification failed for signer index {index}")]
37 VerificationFailed {
38 /// Zero-based index of the signer whose signature failed.
39 index: usize,
40 },
41
42 /// The public key provided during signing does not belong to the configured committee.
43 #[error("signer index {index} is out of range for a {total}-member committee")]
44 SignerIndexOutOfRange {
45 /// The index that was supplied.
46 index: usize,
47 /// The total number of committee members.
48 total: usize,
49 },
50
51 /// A signature for this index has already been recorded in the session.
52 #[error("duplicate signature: index {index} has already been signed")]
53 DuplicateSignature {
54 /// The index that was supplied twice.
55 index: usize,
56 },
57
58 /// The threshold configuration is invalid.
59 ///
60 /// `required` must be in the range `1..=total_keys`.
61 #[error("invalid threshold: required={required} must satisfy 1 <= required <= total_keys={total_keys}")]
62 InvalidThreshold {
63 /// The requested number of required signatures.
64 required: usize,
65 /// The total number of keys in the committee.
66 total_keys: usize,
67 },
68
69 /// The committee must have at least two members.
70 #[error("committee must have at least 2 members; got {count}")]
71 CommitteeTooSmall {
72 /// Number of keys provided.
73 count: usize,
74 },
75
76 /// The signing session has not yet collected enough valid signatures to
77 /// satisfy the configured threshold.
78 #[error("threshold not met: have {have} valid signatures, need {need}")]
79 ThresholdNotMet {
80 /// Number of valid signatures currently held.
81 have: usize,
82 /// Number required by the threshold policy.
83 need: usize,
84 },
85
86 /// Failed to parse a Falcon-512 public key from raw bytes.
87 #[error("failed to parse public key at index {index}")]
88 PublicKeyParseError {
89 /// Zero-based committee index of the key that failed to parse.
90 index: usize,
91 },
92
93 /// Failed to parse a Falcon-512 signature from raw bytes.
94 #[error("failed to parse signature at signer index {index}")]
95 SignatureParseError {
96 /// Zero-based committee index of the failing signature.
97 index: usize,
98 },
99}