indy_crypto/ffi/
mod.rs

1pub mod cl;
2pub mod bls;
3pub mod logger;
4
5use errors::prelude::*;
6
7use libc::c_char;
8
9#[derive(Debug, PartialEq, Copy, Clone)]
10#[repr(usize)]
11pub enum ErrorCode
12{
13    Success = 0,
14
15    // Common errors
16
17    // Caller passed invalid value as param 1 (null, invalid json and etc..)
18    CommonInvalidParam1 = 100,
19
20    // Caller passed invalid value as param 2 (null, invalid json and etc..)
21    CommonInvalidParam2 = 101,
22
23    // Caller passed invalid value as param 3 (null, invalid json and etc..)
24    CommonInvalidParam3 = 102,
25
26    // Caller passed invalid value as param 4 (null, invalid json and etc..)
27    CommonInvalidParam4 = 103,
28
29    // Caller passed invalid value as param 5 (null, invalid json and etc..)
30    CommonInvalidParam5 = 104,
31
32    // Caller passed invalid value as param 6 (null, invalid json and etc..)
33    CommonInvalidParam6 = 105,
34
35    // Caller passed invalid value as param 7 (null, invalid json and etc..)
36    CommonInvalidParam7 = 106,
37
38    // Caller passed invalid value as param 8 (null, invalid json and etc..)
39    CommonInvalidParam8 = 107,
40
41    // Caller passed invalid value as param 9 (null, invalid json and etc..)
42    CommonInvalidParam9 = 108,
43
44    // Caller passed invalid value as param 10 (null, invalid json and etc..)
45    CommonInvalidParam10 = 109,
46
47    // Caller passed invalid value as param 11 (null, invalid json and etc..)
48    CommonInvalidParam11 = 110,
49
50    // Caller passed invalid value as param 11 (null, invalid json and etc..)
51    CommonInvalidParam12 = 111,
52
53    // Invalid library state was detected in runtime. It signals library bug
54    CommonInvalidState = 112,
55
56    // Object (json, config, key, credential and etc...) passed by library caller has invalid structure
57    CommonInvalidStructure = 113,
58
59    // IO Error
60    CommonIOError = 114,
61
62    // Trying to issue non-revocation credential with full anoncreds revocation accumulator
63    AnoncredsRevocationAccumulatorIsFull = 115,
64
65    // Invalid revocation accumulator index
66    AnoncredsInvalidRevocationAccumulatorIndex = 116,
67
68    // Credential revoked
69    AnoncredsCredentialRevoked = 117,
70
71    // Proof rejected
72    AnoncredsProofRejected = 118,
73}
74
75/// Get details for last occurred error.
76///
77/// NOTE: Error is stored until the next one occurs.
78///       Returning pointer has the same lifetime.
79///
80/// #Params
81/// * `error_json_p` - Reference that will contain error details (if any error has occurred before)
82///  in the format:
83/// {
84///     "backtrace": Optional<str> - error backtrace.
85///         Collecting of backtrace can be enabled by setting environment variable `RUST_BACKTRACE=1`
86///     "message": str - human-readable error description
87/// }
88///
89#[no_mangle]
90pub extern fn indy_crypto_get_current_error(error_json_p: *mut *const c_char) {
91    trace!("indy_crypto_get_current_error >>> error_json_p: {:?}", error_json_p);
92
93    let error = get_current_error_c_json();
94    unsafe { *error_json_p = error };
95
96    trace!("indy_crypto_get_current_error: <<<");
97}
98
99#[cfg(test)]
100mod tests {
101    use super::*;
102
103    use std::ptr;
104    use ffi::cl::issuer::indy_crypto_cl_credential_private_key_from_json;
105    use utils::ctypes::*;
106
107    #[test]
108    fn indy_crypto_get_current_error_works() {
109
110        indy_crypto_cl_credential_private_key_from_json(ptr::null(), &mut ptr::null());
111
112        let mut error_json_p: *const c_char = ptr::null();
113        indy_crypto_get_current_error(&mut error_json_p);
114
115        let error_json_1 = c_str_to_string(error_json_p).unwrap();
116        assert!(error_json_1.is_some());
117
118        let credential_priv_key = string_to_cstring("some wrong data".to_string());
119        indy_crypto_cl_credential_private_key_from_json(credential_priv_key.as_ptr(), &mut ptr::null());
120
121        indy_crypto_get_current_error(&mut error_json_p);
122
123        let error_json_2 = c_str_to_string(error_json_p).unwrap();
124        assert!(error_json_2.is_some());
125
126        assert_ne!(error_json_1.unwrap(), error_json_2.unwrap());
127    }
128}