blsful 4.0.0

BLS signature implementation according to the IETF spec on the BLS12-381 curve.
Documentation
use thiserror::Error;

/// The error types generated by this library
#[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum BlsError {
    /// Invalid signing operation
    #[error("invalid signing operation: {0}")]
    SigningError(String),
    /// Invalid inputs to a function
    #[error("invalid inputs: {0}")]
    InvalidInputs(String),
    /// An invalid signature error
    #[error("invalid signature")]
    InvalidSignature,
    /// The proof was invalid
    #[error("invalid proof")]
    InvalidProof,
    /// The signature schemes do not match.
    #[error("invalid signature scheme")]
    InvalidSignatureScheme,
    /// The decryption share is invalid
    #[error("invalid signcryption share")]
    InvalidDecryptionShare,
    /// A verifiable secret sharing scheme error
    #[error("secret sharing error: {0}")]
    VsssError(vsss_rs::Error),
    /// An error occurred during serialization
    #[error("serialization error: {0}")]
    SerializationError(String),
    /// An error occurred during deserialization
    #[error("deserialization error: {0}")]
    DeserializationError(String),
}

/// The result type generated by this library
pub type BlsResult<T> = Result<T, BlsError>;

impl From<vsss_rs::Error> for BlsError {
    fn from(error: vsss_rs::Error) -> Self {
        Self::VsssError(error)
    }
}

impl From<serde_bare::error::Error> for BlsError {
    fn from(e: serde_bare::error::Error) -> Self {
        Self::DeserializationError(e.to_string())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn preserves_secret_sharing_error_details() {
        let error = BlsError::from(vsss_rs::Error::SharingLimitLessThanThreshold);
        assert_eq!(
            error,
            BlsError::VsssError(vsss_rs::Error::SharingLimitLessThanThreshold)
        );
        assert_eq!(
            error.to_string(),
            "secret sharing error: Limit is less than threshold"
        );
    }
}