diff options
| author | Igor Tolmachev <me@igorek.dev> | 2024-07-20 16:52:39 +0900 |
|---|---|---|
| committer | Igor Tolmachev <me@igorek.dev> | 2024-07-20 16:52:39 +0900 |
| commit | 7bcdc3b4ca460aec2b98fb2dca6165788c562b05 (patch) | |
| tree | 63f9616fc1b7f9ca6e414a4d32910720e155690c /src/zip/error.rs | |
| parent | 5f4ceda88c7299deb317f8d22a99ab2521c5a380 (diff) | |
| download | archivator-7bcdc3b4ca460aec2b98fb2dca6165788c562b05.tar.gz archivator-7bcdc3b4ca460aec2b98fb2dca6165788c562b05.zip | |
Partial aes implementation and others improvements
Diffstat (limited to 'src/zip/error.rs')
| -rw-r--r-- | src/zip/error.rs | 38 |
1 files changed, 26 insertions, 12 deletions
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 @@ | |||
| 1 | use crate::{ArchiveError, ArchiveResult}; | ||
| 2 | use std::error::Error; | 1 | use std::error::Error; |
| 3 | use std::fmt::Display; | 2 | use std::fmt::Display; |
| 3 | use std::io::Error as IoError; | ||
| 4 | 4 | ||
| 5 | pub type ZipResult<T> = ArchiveResult<T, ZipError>; | 5 | pub type ZipResult<T> = Result<T, ZipError>; |
| 6 | 6 | ||
| 7 | #[derive(Debug, PartialEq, Eq)] | 7 | #[derive(Debug)] |
| 8 | pub enum ZipError { | 8 | pub enum ZipError { |
| 9 | Io(IoError), | ||
| 10 | |||
| 9 | EocdrNotFound, | 11 | EocdrNotFound, |
| 10 | InvalidEOCDR64Signature, | 12 | InvalidEOCDR64Signature, |
| 11 | InvalidFileHeaderSignature, | 13 | InvalidFileHeaderSignature, |
| 12 | InvalidCDRSignature, | 14 | InvalidCDRSignature, |
| 13 | 15 | ||
| 14 | InvalidCompressionMethod(u16), | ||
| 15 | UnsupportedCompressionMethod(u16), | 16 | UnsupportedCompressionMethod(u16), |
| 16 | UnsupportedEncryptionMethod, | 17 | UnsupportedEncryptionMethod, |
| 17 | InvalidDate, | 18 | InvalidDate, |
| 18 | InvalidTime, | 19 | InvalidTime, |
| 19 | InvalidFileName, | 20 | InvalidFileName, |
| 21 | InvalidExtraFields, | ||
| 22 | AesExtraFieldNotFound, | ||
| 20 | InvalidFileComment, | 23 | InvalidFileComment, |
| 21 | 24 | ||
| 22 | FileNotFound, | 25 | FileNotFound, |
| @@ -26,18 +29,30 @@ pub enum ZipError { | |||
| 26 | EncryptedDataIsUnseekable, | 29 | EncryptedDataIsUnseekable, |
| 27 | } | 30 | } |
| 28 | 31 | ||
| 29 | impl From<ZipError> for ArchiveError<ZipError> { | 32 | impl From<IoError> for ZipError { |
| 30 | fn from(value: ZipError) -> Self { | 33 | fn from(value: IoError) -> Self { |
| 31 | Self::Archivator { | 34 | Self::Io(value) |
| 32 | module: "Zip", | 35 | } |
| 33 | error: value, | 36 | } |
| 37 | |||
| 38 | impl PartialEq for ZipError { | ||
| 39 | fn eq(&self, other: &Self) -> bool { | ||
| 40 | match (self, other) { | ||
| 41 | (Self::Io(l0), Self::Io(r0)) => l0.kind() == r0.kind(), | ||
| 42 | (Self::UnsupportedCompressionMethod(l0), Self::UnsupportedCompressionMethod(r0)) => { | ||
| 43 | l0 == r0 | ||
| 44 | } | ||
| 45 | _ => core::mem::discriminant(self) == core::mem::discriminant(other), | ||
| 34 | } | 46 | } |
| 35 | } | 47 | } |
| 36 | } | 48 | } |
| 37 | 49 | ||
| 50 | impl Eq for ZipError {} | ||
| 51 | |||
| 38 | impl Display for ZipError { | 52 | impl Display for ZipError { |
| 39 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 53 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 40 | match self { | 54 | match self { |
| 55 | Self::Io(error) => write!(f, "{}", error), | ||
| 41 | Self::EocdrNotFound => write!(f, "End of central directory record not found"), | 56 | Self::EocdrNotFound => write!(f, "End of central directory record not found"), |
| 42 | Self::InvalidEOCDR64Signature => { | 57 | Self::InvalidEOCDR64Signature => { |
| 43 | write!( | 58 | write!( |
| @@ -52,9 +67,6 @@ impl Display for ZipError { | |||
| 52 | write!(f, "Invalid signature of central directory record") | 67 | write!(f, "Invalid signature of central directory record") |
| 53 | } | 68 | } |
| 54 | 69 | ||
| 55 | Self::InvalidCompressionMethod(id) => { | ||
| 56 | writeln!(f, "Invalid compression method {}", id) | ||
| 57 | } | ||
| 58 | Self::UnsupportedCompressionMethod(id) => { | 70 | Self::UnsupportedCompressionMethod(id) => { |
| 59 | writeln!(f, "Unsupported compression method {}", id) | 71 | writeln!(f, "Unsupported compression method {}", id) |
| 60 | } | 72 | } |
| @@ -64,6 +76,8 @@ impl Display for ZipError { | |||
| 64 | Self::InvalidDate => write!(f, "Invalid date"), | 76 | Self::InvalidDate => write!(f, "Invalid date"), |
| 65 | Self::InvalidTime => write!(f, "Invalid time"), | 77 | Self::InvalidTime => write!(f, "Invalid time"), |
| 66 | Self::InvalidFileName => write!(f, "Invalid file name"), | 78 | Self::InvalidFileName => write!(f, "Invalid file name"), |
| 79 | Self::InvalidExtraFields => write!(f, "Invalid extra fields"), | ||
| 80 | Self::AesExtraFieldNotFound => write!(f, "Aes extra field not found"), | ||
| 67 | Self::InvalidFileComment => write!(f, "Invalid file comment"), | 81 | Self::InvalidFileComment => write!(f, "Invalid file comment"), |
| 68 | 82 | ||
| 69 | Self::FileNotFound => write!(f, "File not found"), | 83 | Self::FileNotFound => write!(f, "File not found"), |
