aboutsummaryrefslogtreecommitdiff
path: root/src/zip/error.rs
diff options
context:
space:
mode:
authorigorechek06 <me@igorek.dev>2024-08-10 17:58:14 +0900
committerigorechek06 <me@igorek.dev>2024-08-10 17:58:14 +0900
commit1bb400dcb258f135a3f92f6242e728f0475325c1 (patch)
treec71783ceaff073077b7f65705101932ca8f0bbf6 /src/zip/error.rs
parent866516ac50851e2827e6aff0a98c444268c566ff (diff)
downloadarchivator-1bb400dcb258f135a3f92f6242e728f0475325c1.tar.gz
archivator-1bb400dcb258f135a3f92f6242e728f0475325c1.zip
Unify zip errors
Diffstat (limited to 'src/zip/error.rs')
-rw-r--r--src/zip/error.rs68
1 files changed, 22 insertions, 46 deletions
diff --git a/src/zip/error.rs b/src/zip/error.rs
index dbb6bb5..fbc2ba1 100644
--- a/src/zip/error.rs
+++ b/src/zip/error.rs
@@ -8,27 +8,18 @@ pub type ZipResult<T> = Result<T, ZipError>;
8pub enum ZipError { 8pub enum ZipError {
9 Io(IoError), 9 Io(IoError),
10 10
11 EocdrNotFound, 11 // Driver errors
12 InvalidEocdr64Signature, 12 StructNotFound(&'static str),
13 InvalidFileHeaderSignature, 13 InvalidSignature(&'static str),
14 InvalidCdrSignature, 14 InvalidField(&'static str),
15 15 Unsupported(&'static str),
16 Overlapping(&'static str, &'static str), 16 Overlapping(&'static str, &'static str),
17 17
18 UnsupportedCompressionMethod(u16), 18 // API errors
19 UnsupportedEncryptionMethod,
20 InvalidDate,
21 InvalidTime,
22 InvalidFileName,
23 InvalidExtraFields,
24 AesExtraFieldNotFound,
25 InvalidFileComment,
26
27 FileNotFound, 19 FileNotFound,
28 WrongPassword, 20 WrongPassword,
29 PasswordIsNotSpecified, 21 PasswordIsNotSpecified,
30 CompressedDataIsUnseekable, 22 UnseekableFile,
31 EncryptedDataIsUnseekable,
32} 23}
33 24
34impl From<IoError> for ZipError { 25impl From<IoError> for ZipError {
@@ -41,9 +32,10 @@ impl PartialEq for ZipError {
41 fn eq(&self, other: &Self) -> bool { 32 fn eq(&self, other: &Self) -> bool {
42 match (self, other) { 33 match (self, other) {
43 (Self::Io(l0), Self::Io(r0)) => l0.kind() == r0.kind(), 34 (Self::Io(l0), Self::Io(r0)) => l0.kind() == r0.kind(),
44 (Self::UnsupportedCompressionMethod(l0), Self::UnsupportedCompressionMethod(r0)) => { 35 (Self::StructNotFound(l0), Self::StructNotFound(r0)) => l0 == r0,
45 l0 == r0 36 (Self::InvalidSignature(l0), Self::InvalidSignature(r0)) => l0 == r0,
46 } 37 (Self::InvalidField(l0), Self::InvalidField(r0)) => l0 == r0,
38 (Self::Overlapping(l0, l1), Self::Overlapping(r0, r1)) => l0 == r0 && l1 == r1,
47 _ => core::mem::discriminant(self) == core::mem::discriminant(other), 39 _ => core::mem::discriminant(self) == core::mem::discriminant(other),
48 } 40 }
49 } 41 }
@@ -56,42 +48,26 @@ impl Display for ZipError {
56 match self { 48 match self {
57 Self::Io(error) => write!(f, "{}", error), 49 Self::Io(error) => write!(f, "{}", error),
58 50
59 Self::EocdrNotFound => write!(f, "End of central directory record not found"), 51 Self::StructNotFound(struct_name) => {
60 Self::InvalidEocdr64Signature => { 52 write!(f, "Struct '{}' not found", struct_name)
61 write!(
62 f,
63 "Invalid signature of zip64 end of central directory record"
64 )
65 } 53 }
66 Self::InvalidFileHeaderSignature => { 54 Self::InvalidSignature(struct_name) => {
67 write!(f, "Invalid file header signature") 55 write!(f, "Invalid signature of struct '{}'", struct_name)
68 } 56 }
69 Self::InvalidCdrSignature => { 57 Self::InvalidField(field_name) => {
70 write!(f, "Invalid signature of central directory record") 58 write!(f, "Field '{}' has invalid data", field_name)
71 } 59 }
72 60 Self::Unsupported(data_type) => {
73 Self::Overlapping(struct1, struct2) => { 61 writeln!(f, "Unsupported {}", data_type)
74 write!(f, "`{}` overlapt `{}`", struct1, struct2)
75 }
76
77 Self::UnsupportedCompressionMethod(id) => {
78 writeln!(f, "Unsupported compression method `{}`", id)
79 } 62 }
80 Self::UnsupportedEncryptionMethod => { 63 Self::Overlapping(struct_name1, struct_name2) => {
81 writeln!(f, "Unsupported encryption method") 64 write!(f, "`{}` overlap `{}`", struct_name1, struct_name2)
82 } 65 }
83 Self::InvalidDate => write!(f, "Invalid date"),
84 Self::InvalidTime => write!(f, "Invalid time"),
85 Self::InvalidFileName => write!(f, "Invalid file name"),
86 Self::InvalidExtraFields => write!(f, "Invalid extra fields"),
87 Self::AesExtraFieldNotFound => write!(f, "Aes extra field not found"),
88 Self::InvalidFileComment => write!(f, "Invalid file comment"),
89 66
90 Self::FileNotFound => write!(f, "File not found"), 67 Self::FileNotFound => write!(f, "File not found"),
91 Self::WrongPassword => write!(f, "Wrong password"), 68 Self::WrongPassword => write!(f, "Wrong password"),
92 Self::PasswordIsNotSpecified => write!(f, "Password is not specified"), 69 Self::PasswordIsNotSpecified => write!(f, "Password is not specified"),
93 Self::CompressedDataIsUnseekable => write!(f, "Compressed data is unseekable"), 70 Self::UnseekableFile => write!(f, "File is unseekable"),
94 Self::EncryptedDataIsUnseekable => write!(f, "Encrypted data is unseekable"),
95 } 71 }
96 } 72 }
97} 73}