zsign_rs/
error.rs

1//! Error types for zsign operations.
2//!
3//! This module defines the [`enum@Error`] enum covering all failure cases
4//! in code signing operations, including I/O, parsing, cryptography,
5//! and configuration errors.
6//!
7//! # See Also
8//!
9//! - [`crate::Result`] - Convenience type alias using this error
10
11use thiserror::Error;
12
13/// Error type for zsign operations.
14///
15/// All public functions in this crate return [`crate::Result<T>`], which uses this error type.
16/// Match on variants to handle specific failure cases.
17///
18/// # Examples
19///
20/// ```no_run
21/// use zsign::{ZSign, Error};
22///
23/// let result = ZSign::new().sign_ipa("input.ipa", "output.ipa");
24/// match result {
25///     Ok(()) => println!("Signed successfully"),
26///     Err(Error::MissingCredentials(msg)) => eprintln!("Need credentials: {msg}"),
27///     Err(Error::Io(e)) => eprintln!("IO error: {e}"),
28///     Err(e) => eprintln!("Other error: {e}"),
29/// }
30/// ```
31#[derive(Debug, Error)]
32pub enum Error {
33    /// I/O operation failed.
34    ///
35    /// Occurs when reading input files, writing output files, or accessing
36    /// the filesystem during signing operations.
37    #[error("IO error: {0}")]
38    Io(#[from] std::io::Error),
39
40    /// Invalid or unsupported Mach-O binary format.
41    ///
42    /// The input file is not a valid Mach-O binary or uses an unsupported
43    /// architecture or format.
44    #[error("Invalid Mach-O: {0}")]
45    MachO(String),
46
47    /// Code signing operation failed.
48    ///
49    /// A general signing failure occurred during signature generation
50    /// or embedding.
51    #[error("Signing failed: {0}")]
52    Signing(String),
53
54    /// Invalid or malformed certificate.
55    ///
56    /// The provided certificate could not be parsed or is not suitable
57    /// for code signing. See [`crate::SigningCredentials`] for valid formats.
58    #[error("Invalid certificate: {0}")]
59    Certificate(String),
60
61    /// Incorrect password for private key or PKCS#12 file.
62    ///
63    /// The password provided to [`crate::SigningCredentials::from_p12`] or
64    /// [`crate::SigningCredentials::from_pem`] is incorrect.
65    #[error("Invalid password for private key or PKCS#12")]
66    InvalidPassword,
67
68    /// Required credentials not configured.
69    ///
70    /// Signing was attempted without first calling [`crate::ZSign::credentials`].
71    #[error("Missing credentials: {0}")]
72    MissingCredentials(String),
73
74    /// Invalid builder configuration.
75    ///
76    /// A configuration value is invalid or conflicting options were specified.
77    #[error("Configuration error: {0}")]
78    Config(String),
79
80    /// Invalid or malformed provisioning profile.
81    ///
82    /// The `.mobileprovision` file could not be parsed or does not contain
83    /// required entitlements.
84    #[error("Invalid provisioning profile: {0}")]
85    ProvisioningProfile(String),
86
87    /// Property list parsing failed.
88    ///
89    /// Failed to parse `Info.plist`, entitlements, or other plist data.
90    #[error("Plist error: {0}")]
91    Plist(#[from] plist::Error),
92
93    /// ZIP archive operation failed.
94    ///
95    /// Occurs during IPA extraction or creation. See [`crate::ipa`] module.
96    #[error("Zip error: {0}")]
97    Zip(#[from] zip::result::ZipError),
98
99    /// Mach-O binary parsing failed.
100    ///
101    /// Low-level binary parsing error from the goblin library.
102    #[error("Binary parsing error: {0}")]
103    Goblin(String),
104
105    /// Symlinks not supported on this platform.
106    ///
107    /// Some platforms do not support symbolic links in app bundles.
108    #[error("Symlink handling not supported on this platform")]
109    SymlinkNotSupported,
110}