1use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum OpcError {
7 #[error("ZIP error: {0}")]
8 Zip(#[from] zip::result::ZipError),
9
10 #[error("I/O error: {0}")]
11 Io(#[from] std::io::Error),
12
13 #[error("XML error: {0}")]
14 Xml(#[from] quick_xml::Error),
15
16 #[error("XML attribute error: {0}")]
17 XmlAttr(#[from] quick_xml::events::attributes::AttrError),
18
19 #[error("part not found: {0}")]
20 PartNotFound(String),
21
22 #[error("duplicate OPC part name: {0}")]
23 DuplicatePartName(String),
24
25 #[error("OPC package exceeds {kind} limit of {limit}")]
26 PackageLimitExceeded { kind: &'static str, limit: u64 },
27
28 #[error("invalid content types XML")]
29 InvalidContentTypes,
30
31 #[error("invalid relationship XML")]
32 InvalidRelationship,
33
34 #[error(
37 "{part} holds U+{code_point:04X} at line {line}, column {column}, a character XML 1.0 cannot carry"
38 )]
39 InvalidXmlCharacter {
40 part: String,
41 code_point: u32,
42 line: usize,
43 column: usize,
44 },
45
46 #[cfg(feature = "agile-encryption")]
47 #[error("unsupported encryption: {0}")]
48 UnsupportedEncryption(&'static str),
49
50 #[cfg(feature = "agile-encryption")]
51 #[error("unsupported encryption algorithm: {0}")]
52 UnsupportedEncryptionAlgorithm(String),
53
54 #[cfg(feature = "agile-encryption")]
55 #[error("invalid agile encryption information")]
56 InvalidEncryptionInfo,
57
58 #[cfg(feature = "agile-encryption")]
59 #[error("invalid password")]
60 InvalidPassword,
61
62 #[cfg(feature = "agile-encryption")]
63 #[error("encrypted package failed integrity verification")]
64 EncryptedPackageIntegrity,
65
66 #[cfg(feature = "agile-encryption")]
67 #[error("invalid encrypted package stream")]
68 InvalidEncryptedPackage,
69
70 #[cfg(feature = "digital-signatures")]
71 #[error("invalid digital signature XML: {0}")]
72 InvalidSignatureXml(String),
73
74 #[cfg(feature = "digital-signatures")]
75 #[error("unsupported digital signature {kind}: {algorithm}")]
76 UnsupportedSignatureAlgorithm {
77 kind: &'static str,
78 algorithm: String,
79 },
80
81 #[cfg(feature = "digital-signatures")]
82 #[error("invalid signing certificate: {0}")]
83 InvalidSigningCertificate(String),
84
85 #[cfg(feature = "digital-signatures")]
86 #[error("invalid signing key: {0}")]
87 InvalidSigningKey(String),
88
89 #[cfg(feature = "digital-signatures")]
90 #[error("digital signature creation failed: {0}")]
91 SignatureCreationFailed(String),
92
93 #[error("UTF-8 error: {0}")]
94 Utf8(#[from] std::str::Utf8Error),
95}
96
97pub type Result<T> = std::result::Result<T, OpcError>;