From 7bcdc3b4ca460aec2b98fb2dca6165788c562b05 Mon Sep 17 00:00:00 2001 From: Igor Tolmachev Date: Sat, 20 Jul 2024 16:52:39 +0900 Subject: Partial aes implementation and others improvements --- src/zip/error.rs | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/zip/error.rs') diff --git a/src/zip/error.rs b/src/zip/error.rs index 5573cf8..5508177 100644 --- a/src/zip/error.rs +++ b/src/zip/error.rs @@ -1,22 +1,25 @@ -use crate::{ArchiveError, ArchiveResult}; use std::error::Error; use std::fmt::Display; +use std::io::Error as IoError; -pub type ZipResult = ArchiveResult; +pub type ZipResult = Result; -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug)] pub enum ZipError { + Io(IoError), + EocdrNotFound, InvalidEOCDR64Signature, InvalidFileHeaderSignature, InvalidCDRSignature, - InvalidCompressionMethod(u16), UnsupportedCompressionMethod(u16), UnsupportedEncryptionMethod, InvalidDate, InvalidTime, InvalidFileName, + InvalidExtraFields, + AesExtraFieldNotFound, InvalidFileComment, FileNotFound, @@ -26,18 +29,30 @@ pub enum ZipError { EncryptedDataIsUnseekable, } -impl From for ArchiveError { - fn from(value: ZipError) -> Self { - Self::Archivator { - module: "Zip", - error: value, +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!( @@ -52,9 +67,6 @@ impl Display for ZipError { write!(f, "Invalid signature of central directory record") } - Self::InvalidCompressionMethod(id) => { - writeln!(f, "Invalid compression method {}", id) - } Self::UnsupportedCompressionMethod(id) => { writeln!(f, "Unsupported compression method {}", id) } @@ -64,6 +76,8 @@ impl Display for ZipError { 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"), -- cgit v1.2.3