use thiserror::Error;
#[derive(Error, Debug)]
pub enum CarbonadoError {
#[error(transparent)]
StdIoError(#[from] std::io::Error),
#[error(transparent)]
StdArrayTryFromSliceError(#[from] std::array::TryFromSliceError),
#[error(transparent)]
Infallible(#[from] std::convert::Infallible),
#[error(transparent)]
HexDecodeError(#[from] hex::FromHexError),
#[error(transparent)]
Bech32EncodeError(#[from] bech32::EncodeError),
#[error(transparent)]
Bech32DecodeError(#[from] bech32::DecodeError),
#[error(transparent)]
Bech32HrpError(#[from] bech32::primitives::hrp::Error),
#[error(transparent)]
SnapError(#[from] snap::Error),
#[error("Snappy into_inner error when writing bytes to compression.")]
SnapWriteIntoInnerError(String),
#[error(transparent)]
EciesError(#[from] libsecp256k1_core::Error),
#[error(transparent)]
BaoDecodeError(#[from] bao::decode::Error),
#[error(transparent)]
ZfecError(#[from] zfec_rs::Error),
#[error(transparent)]
NostrSecp256k1Error(#[from] nostr::secp256k1::Error),
#[error(transparent)]
NostrNip19Error(#[from] nostr::nips::nip19::Error),
#[error("Input bytes must divide evenly over number of zfec chunks.")]
UnevenZfecChunks,
#[error("Data does not need to be scrubbed.")]
UnnecessaryScrub,
#[error("Scrubbed padding should remain the same.")]
ScrubbedPaddingMismatch,
#[error("Mismatch between scrubbed data length, input len: {0}, scrubbed len: {1}")]
ScrubbedLengthMismatch(usize, usize),
#[error("Hash must be {0} bytes long, an input of {1} bytes was provided.")]
HashDecodeError(usize, usize),
#[error("Scrubbed hash is not equal to original hash.")]
InvalidScrubbedHash,
#[error("Padding from Zfec should always be zero, since Carbonado adds its own padding. Padding was {0}.")]
EncodeZfecPaddingError(usize),
#[error("Chunk length should be as calculated. Calculated chunk length was {0}, but actual chunk length was {1}")]
EncodeInvalidChunkLength(u32, usize),
#[error("Verifiable slice count should be evenly divisible by 8. Remainder was {0}.")]
InvalidVerifiableSliceCount(u16),
#[error("File header lacks Carbonado magic number and may not be a proper Carbonado file. Magic number found was {0}.")]
InvalidMagicNumber(String),
#[error("Pubkey did not serialize into expected length.")]
PubkeySerializationError,
#[error("Hash bytes were not of expected length.")]
HashBytesLengthError,
#[error("Signature bytes were not of expected length. Length was: {0}.")]
UnexpectedSignatureBytesLength(usize),
#[error("Invalid header length calculation")]
InvalidHeaderLength,
#[error("Incorrect public key format")]
IncorrectPubKeyFormat,
}