1#[macro_use]
2extern crate lazy_static;
3#[macro_use]
4extern crate log;
5
6extern crate num_traits;
7#[macro_use]
8extern crate num_derive;
9
10#[macro_use]
11mod macros;
12
13pub mod anoncreds;
14pub mod blob_storage;
15pub mod crypto;
16pub mod did;
17pub mod ledger;
18pub mod payments;
19pub mod pairwise;
20pub mod pool;
21pub mod wallet;
22pub mod utils;
23pub mod native;
24
25use std::sync::mpsc;
26
27pub type IndyHandle = i32;
28
29#[derive(Debug, PartialEq, Copy, Clone, FromPrimitive, ToPrimitive)]
30#[repr(i32)]
31#[allow(dead_code)]
32pub enum ErrorCode
33{
34 Success = 0,
35
36 CommonInvalidParam1 = 100,
40
41 CommonInvalidParam2 = 101,
43
44 CommonInvalidParam3 = 102,
46
47 CommonInvalidParam4 = 103,
49
50 CommonInvalidParam5 = 104,
52
53 CommonInvalidParam6 = 105,
55
56 CommonInvalidParam7 = 106,
58
59 CommonInvalidParam8 = 107,
61
62 CommonInvalidParam9 = 108,
64
65 CommonInvalidParam10 = 109,
67
68 CommonInvalidParam11 = 110,
70
71 CommonInvalidParam12 = 111,
73
74 CommonInvalidState = 112,
76
77 CommonInvalidStructure = 113,
79
80 CommonIOError = 114,
82
83 CommonInvalidParam13 = 115,
85
86 CommonInvalidParam14 = 116,
88
89 CommonInvalidParam15 = 117,
91
92 CommonInvalidParam16 = 118,
94
95 CommonInvalidParam17 = 119,
97
98 CommonInvalidParam18 = 120,
100
101 CommonInvalidParam19 = 121,
103
104 CommonInvalidParam20 = 122,
106
107 CommonInvalidParam21 = 123,
109
110 CommonInvalidParam22 = 124,
112
113 CommonInvalidParam23 = 125,
115
116 CommonInvalidParam24 = 126,
118
119 CommonInvalidParam25 = 127,
121
122 CommonInvalidParam26 = 128,
124
125 CommonInvalidParam27 = 129,
127
128 WalletInvalidHandle = 200,
131
132 WalletUnknownTypeError = 201,
134
135 WalletTypeAlreadyRegisteredError = 202,
137
138 WalletAlreadyExistsError = 203,
140
141 WalletNotFoundError = 204,
143
144 WalletIncompatiblePoolError = 205,
146
147 WalletAlreadyOpenedError = 206,
149
150 WalletAccessFailed = 207,
152
153 WalletInputError = 208,
155
156 WalletDecodingError = 209,
158
159 WalletStorageError = 210,
161
162 WalletEncryptionError = 211,
164
165 WalletItemNotFound = 212,
167
168 WalletItemAlreadyExists = 213,
170
171 WalletQueryError = 214,
173
174 PoolLedgerNotCreatedError = 300,
177
178 PoolLedgerInvalidPoolHandle = 301,
180
181 PoolLedgerTerminated = 302,
183
184 LedgerNoConsensusError = 303,
186
187 LedgerInvalidTransaction = 304,
189
190 LedgerSecurityError = 305,
192
193 PoolLedgerConfigAlreadyExistsError = 306,
195
196 PoolLedgerTimeout = 307,
198
199 PoolIncompatibleProtocolVersion = 308,
202
203 AnoncredsRevocationRegistryFullError = 400,
205
206 AnoncredsInvalidUserRevocIndex = 401,
207
208 AnoncredsMasterSecretDuplicateNameError = 404,
210
211 AnoncredsProofRejected = 405,
212
213 AnoncredsCredentialRevoked = 406,
214
215 AnoncredsCredDefAlreadyExistsError = 407,
217
218 UnknownCryptoTypeError = 500,
221
222 DidAlreadyExistsError = 600,
224
225 UnknownPaymentMethod = 700,
227
228 IncompatiblePaymentError = 701,
230
231 PaymentInsufficientFundsError = 702,
233
234 PaymentSourceDoesNotExistError = 703,
236
237 PaymentExtraFundsError = 705,
239}
240
241impl ErrorCode {
242 #[allow(non_snake_case)]
243 #[allow(dead_code)]
244 #[allow(unused)]
245 pub fn description(&self) -> &'static str {
246 match self {
247 CommonInvalidParam1 => "Caller passed invalid value as param 1",
248 CommonInvalidParam2 => "Caller passed invalid value as param 2",
249 CommonInvalidParam3 => "Caller passed invalid value as param 3",
250 CommonInvalidParam4 => "Caller passed invalid value as param 4",
251 CommonInvalidParam5 => "Caller passed invalid value as param 5",
252 CommonInvalidParam6 => "Caller passed invalid value as param 6",
253 CommonInvalidParam7 => "Caller passed invalid value as param 7",
254 CommonInvalidParam8 => "Caller passed invalid value as param 8",
255 CommonInvalidParam9 => "Caller passed invalid value as param 9",
256 CommonInvalidParam10 => "Caller passed invalid value as param 10",
257 CommonInvalidParam11 => "Caller passed invalid value as param 11",
258 CommonInvalidParam12 => "Caller passed invalid value as param 12",
259 CommonInvalidParam13 => "Caller passed invalid value as param 13",
260 CommonInvalidParam14 => "Caller passed invalid value as param 14",
261 CommonInvalidParam15 => "Caller passed invalid value as param 15",
262 CommonInvalidParam16 => "Caller passed invalid value as param 16",
263 CommonInvalidParam17 => "Caller passed invalid value as param 17",
264 CommonInvalidParam18 => "Caller passed invalid value as param 18",
265 CommonInvalidParam19 => "Caller passed invalid value as param 19",
266 CommonInvalidParam20 => "Caller passed invalid value as param 20",
267 CommonInvalidParam21 => "Caller passed invalid value as param 21",
268 CommonInvalidParam22 => "Caller passed invalid value as param 22",
269 CommonInvalidParam23 => "Caller passed invalid value as param 23",
270 CommonInvalidParam24 => "Caller passed invalid value as param 24",
271 CommonInvalidParam25 => "Caller passed invalid value as param 25",
272 CommonInvalidParam26 => "Caller passed invalid value as param 26",
273 CommonInvalidParam27 => "Caller passed invalid value as param 27",
274 CommonInvalidState => "Invalid library state was detected in runtime. It signals library bug",
275 CommonInvalidStructure => "Object (json, config, key, credential and etc...) passed by library caller has invalid structure",
276 CommonIOError => "IO Error",
277 WalletInvalidHandle => "Caller passed invalid wallet handle",
278 WalletUnknownTypeError => "Caller passed invalid wallet handle",
279 WalletTypeAlreadyRegisteredError => "Attempt to register already existing wallet type",
280 WalletAlreadyExistsError => "Attempt to create wallet with name used for another exists wallet",
281 WalletNotFoundError => "Requested entity id isn't present in wallet",
282 WalletIncompatiblePoolError => "Trying to use wallet with pool that has different name",
283 WalletAccessFailed => "Trying to open wallet encrypted wallet with invalid credentials",
284 WalletAlreadyOpenedError => "Trying to open wallet that was opened already",
285 WalletInputError => "Input provided to wallet operations is considered not valid",
286 WalletDecodingError => "Decoding of wallet data during input/output failed",
287 WalletStorageError => "Storage error occurred during wallet operation",
288 WalletEncryptionError => "Error during encryption-related operations",
289 WalletItemNotFound => "Requested wallet item not found",
290 WalletItemAlreadyExists => "Returned if wallet's add_record operation is used with record name that already exists",
291 WalletQueryError => "Returned if provided wallet query is invalid",
292 PoolLedgerNotCreatedError => "Trying to open pool ledger that wasn't created before",
293 PoolLedgerInvalidPoolHandle => "Caller passed invalid pool ledger handle",
294 PoolLedgerTerminated => "Pool ledger terminated",
295 LedgerNoConsensusError => "No concensus during ledger operation",
296 LedgerInvalidTransaction => "Attempt to send unknown or incomplete transaction message",
297 LedgerSecurityError => "Attempt to send transaction without the necessary privileges",
298 PoolLedgerConfigAlreadyExistsError => "Attempt to create pool ledger config with name used for another existing pool",
299 PoolLedgerTimeout => "Timeout for action",
300 PoolIncompatibleProtocolVersion => "Attempt to open Pool for witch Genesis Transactions are not compatible with set Protocol version. Set the correct Protocol version first.",
301 AnoncredsRevocationRegistryFullError => "Revocation registry is full and creation of new registry is necessary",
302 AnoncredsInvalidUserRevocIndex => "Invalid user revocation index",
303 AnoncredsMasterSecretDuplicateNameError => "Attempt to generate master secret with duplicated name",
304 AnoncredsProofRejected => "Proof rejected",
305 AnoncredsCredentialRevoked => "Credential revoked",
306 AnoncredsCredDefAlreadyExistsError => "Credential definition already exists",
307 UnknownCryptoTypeError => "Unknown format of DID entity keys",
308 DidAlreadyExistsError => "Did already exists",
309 UnknownPaymentMethod => "Unknown payment method was given",
310 IncompatiblePaymentError => "Multiple different payment methods were specified",
311 PaymentInsufficientFundsError => "Payment cannot be processed because there was insufficient funds",
312 PaymentSourceDoesNotExistError => "No such source on a ledger.",
313 PaymentExtraFundsError => "Payment cannot be processed because there were more funds than required",
314 }
315 }
316
317 pub fn is_ok(&self) -> bool {
318 *self == ErrorCode::Success
319 }
320
321 pub fn is_err(&self) -> bool {
322 *self != ErrorCode::Success
323 }
324
325 pub fn try_err(&self) -> Result<(), ErrorCode> {
326 if self.is_err() {
327 return Err(*self)
328 }
329 Ok(())
330 }
331}
332
333impl From<i32> for ErrorCode {
334 fn from(i: i32) -> Self {
335 let conversion = num_traits::FromPrimitive::from_i32(i);
336 if conversion.is_some() {
337 conversion.unwrap()
338 } else {
339 panic!("Unable to convert from {}, unknown error code", i)
340 }
341 }
342}
343
344impl Into<i32> for ErrorCode {
345 fn into(self) -> i32 {
346 num_traits::ToPrimitive::to_i32(&self).unwrap()
347 }
348}
349
350impl From<mpsc::RecvTimeoutError> for ErrorCode {
351 fn from(err: mpsc::RecvTimeoutError) -> Self {
352 match err {
353 mpsc::RecvTimeoutError::Timeout => {
354 warn!("Timed out waiting for libindy to call back");
355 ErrorCode::CommonIOError
356 },
357 mpsc::RecvTimeoutError::Disconnected => {
358 warn!("Channel to libindy was disconnected unexpectedly");
359 ErrorCode::CommonIOError
360 }
361 }
362 }
363}
364
365impl From<mpsc::RecvError> for ErrorCode {
366 fn from(e: mpsc::RecvError) -> Self {
367 warn!("Channel returned an error - {:?}", e);
368 ErrorCode::CommonIOError
369 }
370}