1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
use crate::{ArchiveError, ArchiveResult};
use std::error::Error;
use std::fmt::Display;
pub type ZipResult<T> = ArchiveResult<T, ZipError>;
#[derive(Debug, PartialEq, Eq)]
pub enum ZipError {
EocdrNotFound,
InvalidEOCDR64Signature,
InvalidFileHeaderSignature,
InvalidCDRSignature,
InvalidCompressionMethod(u16),
UnsupportedCompressionMethod(u16),
UnsupportedEncryptionMethod,
InvalidDate,
InvalidTime,
InvalidFileName,
InvalidFileComment,
FileNotFound,
IncorrectPassword,
PasswordIsNotSpecified,
CompressedDataIsUnseekable,
EncryptedDataIsUnseekable,
}
impl From<ZipError> for ArchiveError<ZipError> {
fn from(value: ZipError) -> Self {
Self::Archivator {
module: "Zip",
error: value,
}
}
}
impl Display for ZipError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
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::InvalidCompressionMethod(id) => {
writeln!(f, "Invalid compression method {}", id)
}
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::InvalidFileComment => write!(f, "Invalid file comment"),
Self::FileNotFound => write!(f, "File not found"),
Self::IncorrectPassword => write!(f, "Incorrect 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 {}
|