use aes_gcm::Error as AesGcmError;
use core::num::TryFromIntError;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::curve::{point::Error as PointError, scalar::Scalar};
#[derive(Error, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum DkgError {
#[error("missing public shares from {0:?}")]
MissingPublicShares(Vec<u32>),
#[error("missing private shares for/from {0:?}")]
MissingPrivateShares(Vec<(u32, u32)>),
#[error("bad public shares {0:?}")]
BadPublicShares(Vec<u32>),
#[error("bad private shares {0:?}")]
BadPrivateShares(Vec<u32>),
#[error("point error {0:?}")]
Point(PointError),
#[error("integer conversion error")]
TryFromInt,
}
impl From<PointError> for DkgError {
fn from(e: PointError) -> Self {
DkgError::Point(e)
}
}
impl From<TryFromIntError> for DkgError {
fn from(_e: TryFromIntError) -> Self {
Self::TryFromInt
}
}
#[derive(Error, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum AggregatorError {
#[error("bad poly commitments {0:?}")]
BadPolyCommitments(Vec<Scalar>),
#[error("bad nonce length (expected {0} got {1}")]
BadNonceLen(usize, usize),
#[error("bad party keys from {0:?}")]
BadPartyKeys(Vec<u32>),
#[error("bad party sigs from {0:?}")]
BadPartySigs(Vec<u32>),
#[error("bad group sig")]
BadGroupSig,
#[error("integer conversion error")]
TryFromInt,
}
impl From<TryFromIntError> for AggregatorError {
fn from(_e: TryFromIntError) -> Self {
Self::TryFromInt
}
}
#[derive(Error, Debug, Clone, PartialEq)]
pub enum EncryptionError {
#[error("AES nonce was missing from the buffer")]
MissingNonce,
#[error("AES data was missing from the buffer")]
MissingData,
#[error("AES GCM error {0:?}")]
AesGcm(AesGcmError),
}
impl From<AesGcmError> for EncryptionError {
fn from(e: AesGcmError) -> Self {
Self::AesGcm(e)
}
}