1use std::fmt;
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4pub enum PeSignErrorKind {
5 IoError,
7
8 InvalidPeFile,
10
11 InvalidContentInfo,
13
14 InvalidContentType,
16
17 InvalidSignedData,
19
20 InvalidEncapsulatedContentType,
22
23 EmptyEncapsulatedContent,
25
26 InvalidSpcIndirectDataContent,
28
29 EmptyCertificate,
31
32 UnsupportedCertificateFormat,
34
35 UnsupportedAlgorithm,
37
38 InvalidCertificateExtension,
40
41 WrongCertChainBuildParam,
43
44 InvalidPEMCertificate,
46
47 InvalidPublicKey,
49
50 NoFoundSignerInfo,
52
53 UnknownSigner,
55
56 NoFoundMessageDigest,
58
59 InvalidCounterSignature,
61
62 InvalidSigningTime,
64
65 NoFoundSigningTime,
67
68 InvalidTSTInfo,
70
71 ExportDerError,
73
74 ExportPemError,
76
77 Unknown,
79}
80
81#[derive(Debug)]
82pub struct PeSignError {
83 pub kind: PeSignErrorKind,
84 pub message: String,
85}
86
87impl fmt::Display for PeSignError {
88 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89 write!(f, "{:?}", self)
90 }
91}
92
93impl std::error::Error for PeSignError {}
94
95pub trait PeSignResult<T> {
96 fn map_app_err(self: Self, kind: PeSignErrorKind) -> Result<T, PeSignError>;
97 fn map_unknown_err(self: Self) -> Result<T, PeSignError>;
98}
99
100impl<T, E> PeSignResult<T> for std::result::Result<T, E>
101where
102 E: std::error::Error + 'static,
103{
104 fn map_app_err(self: Self, kind: PeSignErrorKind) -> Result<T, PeSignError> {
105 self.map_err(|err| PeSignError {
106 kind: kind,
107 message: err.to_string(),
108 })
109 }
110
111 fn map_unknown_err(self: Self) -> Result<T, PeSignError> {
112 self.map_app_err(PeSignErrorKind::Unknown)
113 }
114}