falcon-multisig 0.1.0

Production-grade post-quantum threshold multisignature library using Falcon-512 (NIST FIPS 206 / FN-DSA)
Documentation
//! Error types for the falcon-multisig library.

use thiserror::Error;

/// All errors that can be produced by this library.
#[derive(Debug, Error, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
    /// The supplied public key has an incorrect byte length.
    ///
    /// Falcon-512 public keys must be exactly [`crate::PUBLIC_KEY_BYTES`] bytes.
    #[error("invalid public key length: expected {expected} bytes, got {actual}")]
    InvalidPublicKeyLength {
        /// The required length.
        expected: usize,
        /// The actual length received.
        actual: usize,
    },

    /// The supplied signature has an incorrect or out-of-range byte length.
    #[error("invalid signature length: {actual} bytes (valid range {min}..={max})")]
    InvalidSignatureLength {
        /// Actual length received.
        actual: usize,
        /// Inclusive minimum valid length.
        min: usize,
        /// Inclusive maximum valid length.
        max: usize,
    },

    /// Cryptographic verification of a Falcon-512 signature failed.
    ///
    /// This is returned by [`crate::verify::verify_partial`] and
    /// [`crate::session::SigningSession::add_signature`] when the raw
    /// Falcon-512 check does not pass.
    #[error("signature verification failed for signer index {index}")]
    VerificationFailed {
        /// Zero-based index of the signer whose signature failed.
        index: usize,
    },

    /// The public key provided during signing does not belong to the configured committee.
    #[error("signer index {index} is out of range for a {total}-member committee")]
    SignerIndexOutOfRange {
        /// The index that was supplied.
        index: usize,
        /// The total number of committee members.
        total: usize,
    },

    /// A signature for this index has already been recorded in the session.
    #[error("duplicate signature: index {index} has already been signed")]
    DuplicateSignature {
        /// The index that was supplied twice.
        index: usize,
    },

    /// The threshold configuration is invalid.
    ///
    /// `required` must be in the range `1..=total_keys`.
    #[error("invalid threshold: required={required} must satisfy 1 <= required <= total_keys={total_keys}")]
    InvalidThreshold {
        /// The requested number of required signatures.
        required: usize,
        /// The total number of keys in the committee.
        total_keys: usize,
    },

    /// The committee must have at least two members.
    #[error("committee must have at least 2 members; got {count}")]
    CommitteeTooSmall {
        /// Number of keys provided.
        count: usize,
    },

    /// The signing session has not yet collected enough valid signatures to
    /// satisfy the configured threshold.
    #[error("threshold not met: have {have} valid signatures, need {need}")]
    ThresholdNotMet {
        /// Number of valid signatures currently held.
        have: usize,
        /// Number required by the threshold policy.
        need: usize,
    },

    /// Failed to parse a Falcon-512 public key from raw bytes.
    #[error("failed to parse public key at index {index}")]
    PublicKeyParseError {
        /// Zero-based committee index of the key that failed to parse.
        index: usize,
    },

    /// Failed to parse a Falcon-512 signature from raw bytes.
    #[error("failed to parse signature at signer index {index}")]
    SignatureParseError {
        /// Zero-based committee index of the failing signature.
        index: usize,
    },
}