use std::error::Error; use std::fmt::Display; use std::io::Error as IoError; pub type ZipResult = Result; #[derive(Debug)] pub enum ZipError { Io(IoError), EocdrNotFound, InvalidEOCDR64Signature, InvalidFileHeaderSignature, InvalidCDRSignature, UnsupportedCompressionMethod(u16), UnsupportedEncryptionMethod, InvalidDate, InvalidTime, InvalidFileName, InvalidExtraFields, AesExtraFieldNotFound, InvalidFileComment, FileNotFound, WrongPassword, PasswordIsNotSpecified, CompressedDataIsUnseekable, EncryptedDataIsUnseekable, } impl From for ZipError { fn from(value: IoError) -> Self { Self::Io(value) } } impl PartialEq for ZipError { fn eq(&self, other: &Self) -> bool { match (self, other) { (Self::Io(l0), Self::Io(r0)) => l0.kind() == r0.kind(), (Self::UnsupportedCompressionMethod(l0), Self::UnsupportedCompressionMethod(r0)) => { l0 == r0 } _ => core::mem::discriminant(self) == core::mem::discriminant(other), } } } impl Eq for ZipError {} impl Display for ZipError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Io(error) => write!(f, "{}", error), Self::EocdrNotFound => write!(f, "End of central directory record not found"), Self::InvalidEOCDR64Signature => { write!( f, "Invalid signature of zip64 end of central directory record" ) } Self::InvalidFileHeaderSignature => { write!(f, "Invalid file header signature") } Self::InvalidCDRSignature => { write!(f, "Invalid signature of central directory record") } Self::UnsupportedCompressionMethod(id) => { writeln!(f, "Unsupported compression method {}", id) } Self::UnsupportedEncryptionMethod => { writeln!(f, "Unsupported encryption method") } Self::InvalidDate => write!(f, "Invalid date"), Self::InvalidTime => write!(f, "Invalid time"), Self::InvalidFileName => write!(f, "Invalid file name"), Self::InvalidExtraFields => write!(f, "Invalid extra fields"), Self::AesExtraFieldNotFound => write!(f, "Aes extra field not found"), Self::InvalidFileComment => write!(f, "Invalid file comment"), Self::FileNotFound => write!(f, "File not found"), Self::WrongPassword => write!(f, "Wrong password"), Self::PasswordIsNotSpecified => write!(f, "Password is not specified"), Self::CompressedDataIsUnseekable => write!(f, "Compressed data is unseekable"), Self::EncryptedDataIsUnseekable => write!(f, "Encrypted data is unseekable"), } } } impl Error for ZipError {}