From 1bb400dcb258f135a3f92f6242e728f0475325c1 Mon Sep 17 00:00:00 2001 From: igorechek06 Date: Sat, 10 Aug 2024 17:58:14 +0900 Subject: Unify zip errors --- src/zip/file/info.rs | 4 ++-- src/zip/file/read.rs | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/zip/file') diff --git a/src/zip/file/info.rs b/src/zip/file/info.rs index 38ea984..93b9f43 100644 --- a/src/zip/file/info.rs +++ b/src/zip/file/info.rs @@ -10,7 +10,7 @@ pub enum CompressionMethod { Lzma, Zstd, Xz, - Unsupported(u16), + Unsupported, } impl CompressionMethod { @@ -23,7 +23,7 @@ impl CompressionMethod { 14 => Self::Lzma, 93 => Self::Zstd, 95 => Self::Xz, - _ => Self::Unsupported(id), + _ => Self::Unsupported, } } } diff --git a/src/zip/file/read.rs b/src/zip/file/read.rs index d25655e..567fb75 100644 --- a/src/zip/file/read.rs +++ b/src/zip/file/read.rs @@ -116,7 +116,9 @@ impl Encryption> { Aes256::new(key.into()), )?) } - EncryptionMethod::Unsupported => return Err(ZipError::UnsupportedEncryptionMethod), + EncryptionMethod::Unsupported => { + return Err(ZipError::Unsupported("encryption method")) + } }) } } @@ -141,7 +143,7 @@ impl Seek for Encryption { Self::None(io) => io.seek(pos), _ => Err(IoError::new( IoErrorKind::Unsupported, - ZipError::EncryptedDataIsUnseekable, + ZipError::UnseekableFile, )), } } @@ -182,8 +184,8 @@ impl Compression { } CompressionMethod::Zstd => Self::Zstd(ZstdDecoder::new(io)?), CompressionMethod::Xz => Self::Xz(XzDecoder::new(io)), - CompressionMethod::Unsupported(id) => { - return Err(ZipError::UnsupportedCompressionMethod(id)) + CompressionMethod::Unsupported => { + return Err(ZipError::Unsupported("compression method")); } }) } @@ -209,7 +211,7 @@ impl Seek for Compression { Compression::Store(io) => io.seek(pos), _ => Err(IoError::new( IoErrorKind::Unsupported, - ZipError::CompressedDataIsUnseekable, + ZipError::UnseekableFile, )), } } @@ -235,7 +237,7 @@ impl<'d, Io: Read + Seek> ZipFileReader<'d, Io> { let buf = io.read_arr::<30>()?; if buf[..4] != FILE_HEADER_SIGNATURE { - return Err(ZipError::InvalidFileHeaderSignature); + return Err(ZipError::InvalidSignature("FileHeader")); } let cursor = io.seek(SeekFrom::Start( -- cgit v1.2.3