1 #ifndef SEQUOIA_ERRORS_H
2 #define SEQUOIA_ERRORS_H
3 
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <limits.h>
7 
8 /* XXX: Reorder and name-space before release.  */
9 typedef enum pgp_status {
10   /*/
11   /// The operation was successful.
12   /*/
13   PGP_STATUS_SUCCESS = 0,
14 
15   /*/
16   /// An unknown error occurred.
17   /*/
18   PGP_STATUS_UNKNOWN_ERROR = -1,
19 
20   /*/
21   /// The network policy was violated by the given action.
22   /*/
23   PGP_STATUS_NETWORK_POLICY_VIOLATION = -2,
24 
25   /*/
26   /// An IO error occurred.
27   /*/
28   PGP_STATUS_IO_ERROR = -3,
29 
30   /*/
31   /// A given argument is invalid.
32   /*/
33   PGP_STATUS_INVALID_ARGUMENT = -15,
34 
35   /*/
36   /// The requested operation is invalid.
37   /*/
38   PGP_STATUS_INVALID_OPERATION = -4,
39 
40   /*/
41   /// The packet is malformed.
42   /*/
43   PGP_STATUS_MALFORMED_PACKET = -5,
44 
45   /*/
46   /// Packet size exceeds the configured limit.
47   /*/
48   PGP_STATUS_PACKET_TOO_LARGE = -29,
49 
50   /*/
51   /// Unsupported packet type.
52   /*/
53   PGP_STATUS_UNSUPPORTED_PACKET_TYPE = -14,
54 
55   /*/
56   /// Unsupported hash algorithm.
57   /*/
58   PGP_STATUS_UNSUPPORTED_HASH_ALGORITHM = -9,
59 
60   /*/
61   /// Unsupported public key algorithm.
62   /*/
63   PGP_STATUS_UNSUPPORTED_PUBLICKEY_ALGORITHM = -18,
64 
65   /*/
66   /// Unsupported elliptic curve.
67   /*/
68   PGP_STATUS_UNSUPPORTED_ELLIPTIC_CURVE = -21,
69 
70   /*/
71   /// Unsupported symmetric algorithm.
72   /*/
73   PGP_STATUS_UNSUPPORTED_SYMMETRIC_ALGORITHM = -10,
74 
75   /*/
76   /// Unsupported AEAD algorithm.
77   /*/
78   PGP_STATUS_UNSUPPORTED_AEAD_ALGORITHM = -26,
79 
80   /*/
81   /// Unsupported Compression algorithm.
82   /*/
83   PGP_STATUS_UNSUPPORTED_COMPRESSION_ALGORITHM = -28,
84 
85   /*/
86   /// Unsupported signature type.
87   /*/
88   PGP_STATUS_UNSUPPORTED_SIGNATURE_TYPE = -20,
89 
90   /*/
91   /// Invalid password.
92   /*/
93   PGP_STATUS_INVALID_PASSWORD = -11,
94 
95   /*/
96   /// Invalid session key.
97   /*/
98   PGP_STATUS_INVALID_SESSION_KEY = -12,
99 
100   /*/
101   /// Missing session key.
102   /*/
103   PGP_STATUS_MISSING_SESSION_KEY = -27,
104 
105   /*/
106   /// Malformed Cert.
107   /*/
108   PGP_STATUS_MALFORMED_CERT = -13,
109 
110   /*/
111   /// Bad signature.
112   /*/
113   PGP_STATUS_BAD_SIGNATURE = -19,
114 
115   /*/
116   /// Message has been manipulated.
117   /*/
118   PGP_STATUS_MANIPULATED_MESSAGE = -25,
119 
120   /*/
121   /// Malformed message.
122   /*/
123   PGP_STATUS_MALFORMED_MESSAGE = -22,
124 
125   /*/
126   /// Index out of range.
127   /*/
128   PGP_STATUS_INDEX_OUT_OF_RANGE = -23,
129 
130   /*/
131   /// Cert not supported.
132   /*/
133   PGP_STATUS_UNSUPPORTED_CERT = -24,
134 
135   /*/
136   /// Expired.
137   /*/
138   PGP_STATUS_EXPIRED = -30,
139 
140   /*/
141   /// Not yet live.
142   /*/
143   PGP_STATUS_NOT_YET_LIVE = -31,
144 
145   /* Dummy value to make sure the enumeration has a defined size.  Do
146      not use this value.  */
147   PGP_STATUS_FORCE_WIDTH = INT_MAX,
148 } pgp_status_t;
149 
150 /*/
151 /// Returns the error message.
152 ///
153 /// The returned value must *not* be freed.
154 /*/
155 const char *pgp_status_to_string(pgp_status_t status);
156 
157 /*/
158 /// Complex errors returned from Sequoia.
159 /*/
160 typedef struct pgp_error *pgp_error_t;
161 
162 /*/
163 /// Frees an error.
164 /*/
165 void pgp_error_free (pgp_error_t error);
166 
167 /*/
168 /// Returns the error message.
169 ///
170 /// The returned value must be freed with `free(3)`.
171 /*/
172 char *pgp_error_to_string (const pgp_error_t err);
173 
174 /*/
175 /// Returns the error status code.
176 /*/
177 pgp_status_t pgp_error_status (const pgp_error_t err);
178 
179 #endif
180