Skip to main content

apk_info_zip/
errors.rs

1//! Errors returned by this crate.
2//!
3//! This module contains the definitions for all error types returned by this crate.
4
5use openssl::error::ErrorStack;
6use thiserror::Error;
7
8/// Represents all possible errors that can occur while parsing a ZIP archive.
9#[derive(Error, Debug)]
10pub enum ZipError {
11    /// The provided file does not have a valid ZIP header.
12    #[error("provided file is not a zip archive")]
13    InvalidHeader,
14
15    /// An error occurred while decompressing a file entry.
16    #[error("got error while decompressing object")]
17    DecompressionError,
18
19    /// Unexpected end-of-file (EOF) was reached while reading the ZIP archive.
20    #[error("got EOF while parsing zip")]
21    EOF,
22
23    /// The requested file does not exist inside the ZIP archive.
24    #[error("file not exist in zip")]
25    FileNotFound,
26
27    /// The End of Central Directory (EOCD) record could not be found, preventing operations.
28    #[error("can't find EOCD in zip")]
29    NotFoundEOCD,
30
31    /// A general error occurred while parsing the ZIP archive.
32    #[error("got error while parsing zip archive")]
33    ParseError,
34}
35
36/// Represents all errors that can occur while handling certificates.
37#[derive(Error, Debug)]
38pub enum CertificateError {
39    /// Failed to parse the certificate.
40    #[error("got error while parsing certificate")]
41    ParseError,
42
43    /// An error occurred while parsing a ZIP archive within the certificate context.
44    #[error("got zip error while parsing certificate: {0}")]
45    ZipError(#[from] ZipError),
46
47    /// An OpenSSL stack error occurred.
48    #[error("got stack error: {0}")]
49    StackError(#[from] ErrorStack),
50
51    /// A signing error occurred (e.g., invalid signer or signature verification failed).
52    #[error("got signer error")]
53    SignerError,
54
55    /// The certificate format is invalid because the block sizes do not match the expected values.
56    #[error("size of blocks not equals (required by format) - (start - {0}, end - {1})")]
57    InvalidFormat(u64, u64),
58}