This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 736
/
non_secrets.rs
513 lines (441 loc) · 22.2 KB
/
non_secrets.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
use indy_api_types::{ErrorCode, CommandHandle, WalletHandle, SearchHandle, INVALID_SEARCH_HANDLE};
use crate::commands::{Command, CommandExecutor};
use crate::commands::non_secrets::NonSecretsCommand;
use indy_api_types::domain::wallet::Tags;
use indy_api_types::errors::prelude::*;
use indy_utils::ctypes;
use serde_json;
use libc::c_char;
/// Create a new non-secret record in the wallet
///
/// #Params
/// command_handle: command handle to map callback to caller context
/// wallet_handle: wallet handle (created by open_wallet)
/// type_: allows to separate different record types collections
/// id: the id of record
/// value: the value of record
/// tags_json: (optional) the record tags used for search and storing meta information as json:
/// {
/// "tagName1": <str>, // string tag (will be stored encrypted)
/// "tagName2": <str>, // string tag (will be stored encrypted)
/// "~tagName3": <str>, // string tag (will be stored un-encrypted)
/// "~tagName4": <str>, // string tag (will be stored un-encrypted)
/// }
/// Note that null means no tags
/// If tag name starts with "~" the tag will be stored un-encrypted that will allow
/// usage of this tag in complex search queries (comparison, predicates)
/// Encrypted tags can be searched only for exact matching
#[no_mangle]
pub extern fn indy_add_wallet_record(command_handle: CommandHandle,
wallet_handle: WalletHandle,
type_: *const c_char,
id: *const c_char,
value: *const c_char,
tags_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode)>) -> ErrorCode {
trace!("indy_add_wallet_record: >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, value: {:?}, tags_json: {:?}", wallet_handle, type_, id, value, tags_json);
check_useful_c_str!(type_, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(value, ErrorCode::CommonInvalidParam5);
check_useful_opt_json!(tags_json, ErrorCode::CommonInvalidParam6, Tags);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam7);
trace!("indy_add_wallet_record: entities >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, value: {:?}, tags_json: {:?}", wallet_handle, type_, id, value, tags_json);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::AddRecord(
wallet_handle,
type_,
id,
value,
tags_json,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_add_wallet_record:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_add_wallet_record: <<< res: {:?}", res);
res
}
/// Update a non-secret wallet record value
///
/// #Params
/// command_handle: command handle to map callback to caller context
/// wallet_handle: wallet handle (created by open_wallet)
/// type_: allows to separate different record types collections
/// id: the id of record
/// value: the new value of record
#[no_mangle]
pub extern fn indy_update_wallet_record_value(command_handle: CommandHandle,
wallet_handle: WalletHandle,
type_: *const c_char,
id: *const c_char,
value: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode)>) -> ErrorCode {
trace!("indy_update_wallet_record_value: >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, value: {:?}", wallet_handle, type_, id, value);
check_useful_c_str!(type_, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(value, ErrorCode::CommonInvalidParam5);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
trace!("indy_update_wallet_record_value: entities >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, value: {:?}", wallet_handle, type_, id, value);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::UpdateRecordValue(
wallet_handle,
type_,
id,
value,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_update_wallet_record_value:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_update_wallet_record_value: <<< res: {:?}", res);
res
}
/// Update a non-secret wallet record tags
///
/// #Params
/// command_handle: command handle to map callback to caller context
/// wallet_handle: wallet handle (created by open_wallet)
/// type_: allows to separate different record types collections
/// id: the id of record
/// tags_json: the record tags used for search and storing meta information as json:
/// {
/// "tagName1": <str>, // string tag (will be stored encrypted)
/// "tagName2": <str>, // string tag (will be stored encrypted)
/// "~tagName3": <str>, // string tag (will be stored un-encrypted)
/// "~tagName4": <str>, // string tag (will be stored un-encrypted)
/// }
/// If tag name starts with "~" the tag will be stored un-encrypted that will allow
/// usage of this tag in complex search queries (comparison, predicates)
/// Encrypted tags can be searched only for exact matching
#[no_mangle]
pub extern fn indy_update_wallet_record_tags(command_handle: CommandHandle,
wallet_handle: WalletHandle,
type_: *const c_char,
id: *const c_char,
tags_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode)>) -> ErrorCode {
trace!("indy_update_wallet_record_tags: >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, tags_json: {:?}", wallet_handle, type_, id, tags_json);
check_useful_c_str!(type_, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam4);
check_useful_json!(tags_json, ErrorCode::CommonInvalidParam5, Tags);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
trace!("indy_update_wallet_record_tags: entities >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, tags_json: {:?}", wallet_handle, type_, id, tags_json);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::UpdateRecordTags(
wallet_handle,
type_,
id,
tags_json,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_update_wallet_record_tags:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_update_wallet_record_tags: <<< res: {:?}", res);
res
}
/// Add new tags to the wallet record
///
/// #Params
/// command_handle: command handle to map callback to caller context
/// wallet_handle: wallet handle (created by open_wallet)
/// type_: allows to separate different record types collections
/// id: the id of record
/// tags_json: the record tags used for search and storing meta information as json:
/// {
/// "tagName1": <str>, // string tag (will be stored encrypted)
/// "tagName2": <str>, // string tag (will be stored encrypted)
/// "~tagName3": <str>, // string tag (will be stored un-encrypted)
/// "~tagName4": <str>, // string tag (will be stored un-encrypted)
/// }
/// If tag name starts with "~" the tag will be stored un-encrypted that will allow
/// usage of this tag in complex search queries (comparison, predicates)
/// Encrypted tags can be searched only for exact matching
/// Note if some from provided tags already assigned to the record than
/// corresponding tags values will be replaced
#[no_mangle]
pub extern fn indy_add_wallet_record_tags(command_handle: CommandHandle,
wallet_handle: WalletHandle,
type_: *const c_char,
id: *const c_char,
tags_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode)>) -> ErrorCode {
trace!("indy_add_wallet_record_tags: >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, tags_json: {:?}", wallet_handle, type_, id, tags_json);
check_useful_c_str!(type_, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam4);
check_useful_json!(tags_json, ErrorCode::CommonInvalidParam5, Tags);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
trace!("indy_add_wallet_record_tags: entities >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, tags_json: {:?}", wallet_handle, type_, id, tags_json);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::AddRecordTags(
wallet_handle,
type_,
id,
tags_json,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_add_wallet_record_tags:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_add_wallet_record_tags: <<< res: {:?}", res);
res
}
/// Delete tags from the wallet record
///
/// #Params
/// command_handle: command handle to map callback to caller context
/// wallet_handle: wallet handle (created by open_wallet)
/// type_: allows to separate different record types collections
/// id: the id of record
/// tag_names_json: the list of tag names to remove from the record as json array:
/// ["tagName1", "tagName2", ...]
#[no_mangle]
pub extern fn indy_delete_wallet_record_tags(command_handle: CommandHandle,
wallet_handle: WalletHandle,
type_: *const c_char,
id: *const c_char,
tag_names_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode)>) -> ErrorCode {
trace!("indy_delete_wallet_record_tags: >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, tag_names_json: {:?}", wallet_handle, type_, id, tag_names_json);
check_useful_c_str!(type_, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(tag_names_json, ErrorCode::CommonInvalidParam5);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
trace!("indy_delete_wallet_record_tags: entities >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, tag_names_json: {:?}", wallet_handle, type_, id, tag_names_json);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::DeleteRecordTags(
wallet_handle,
type_,
id,
tag_names_json,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_delete_wallet_record_tags:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_delete_wallet_record_tags: <<< res: {:?}", res);
res
}
/// Delete an existing wallet record in the wallet
///
/// #Params
/// command_handle: command handle to map callback to caller context
/// wallet_handle: wallet handle (created by open_wallet)
/// type_: record type
/// id: the id of record
#[no_mangle]
pub extern fn indy_delete_wallet_record(command_handle: CommandHandle,
wallet_handle: WalletHandle,
type_: *const c_char,
id: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode)>) -> ErrorCode {
trace!("indy_delete_wallet_record: >>> wallet_handle: {:?}, type_: {:?}, id: {:?}", wallet_handle, type_, id);
check_useful_c_str!(type_, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam4);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5);
trace!("indy_delete_wallet_record: entities >>> wallet_handle: {:?}, type_: {:?}, id: {:?}", wallet_handle, type_, id);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::DeleteRecord(
wallet_handle,
type_,
id,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_delete_wallet_record:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_delete_wallet_record: <<< res: {:?}", res);
res
}
/// Get an wallet record by id
///
/// #Params
/// command_handle: command handle to map callback to caller context
/// wallet_handle: wallet handle (created by open_wallet)
/// type_: allows to separate different record types collections
/// id: the id of record
/// options_json: //TODO: FIXME: Think about replacing by bitmask
/// {
/// retrieveType: (optional, false by default) Retrieve record type,
/// retrieveValue: (optional, true by default) Retrieve record value,
/// retrieveTags: (optional, false by default) Retrieve record tags
/// }
/// #Returns
/// wallet record json:
/// {
/// id: "Some id",
/// type: "Some type", // present only if retrieveType set to true
/// value: "Some value", // present only if retrieveValue set to true
/// tags: <tags json>, // present only if retrieveTags set to true
/// }
#[no_mangle]
pub extern fn indy_get_wallet_record(command_handle: CommandHandle,
wallet_handle: WalletHandle,
type_: *const c_char,
id: *const c_char,
options_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode,
record_json: *const c_char)>) -> ErrorCode {
trace!("indy_get_wallet_record: >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, options_json: {:?}", wallet_handle, type_, id, options_json);
check_useful_c_str!(type_, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(options_json, ErrorCode::CommonInvalidParam5);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
trace!("indy_get_wallet_record: entities >>> wallet_handle: {:?}, type_: {:?}, id: {:?}, options_json: {:?}", wallet_handle, type_, id, options_json);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::GetRecord(
wallet_handle,
type_,
id,
options_json,
boxed_callback_string!("indy_get_wallet_record", cb, command_handle)
)));
let res = prepare_result!(result);
trace!("indy_get_wallet_record: <<< res: {:?}", res);
res
}
/// Search for wallet records.
///
/// Note instead of immediately returning of fetched records
/// this call returns wallet_search_handle that can be used later
/// to fetch records by small batches (with indy_fetch_wallet_search_next_records).
///
/// #Params
/// wallet_handle: wallet handle (created by open_wallet)
/// type_: allows to separate different record types collections
/// query_json: MongoDB style query to wallet record tags:
/// {
/// "tagName": "tagValue",
/// $or: {
/// "tagName2": { $regex: 'pattern' },
/// "tagName3": { $gte: '123' },
/// },
/// }
/// options_json: //TODO: FIXME: Think about replacing by bitmask
/// {
/// retrieveRecords: (optional, true by default) If false only "counts" will be calculated,
/// retrieveTotalCount: (optional, false by default) Calculate total count,
/// retrieveType: (optional, false by default) Retrieve record type,
/// retrieveValue: (optional, true by default) Retrieve record value,
/// retrieveTags: (optional, false by default) Retrieve record tags,
/// }
/// #Returns
/// search_handle: Wallet search handle that can be used later
/// to fetch records by small batches (with indy_fetch_wallet_search_next_records)
#[no_mangle]
pub extern fn indy_open_wallet_search(command_handle: CommandHandle,
wallet_handle: WalletHandle,
type_: *const c_char,
query_json: *const c_char,
options_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode,
search_handle: SearchHandle)>) -> ErrorCode {
trace!("indy_open_wallet_search: >>> wallet_handle: {:?}, type_: {:?}, query_json: {:?}, options_json: {:?}", wallet_handle, type_, query_json, options_json);
check_useful_c_str!(type_, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(query_json, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(options_json, ErrorCode::CommonInvalidParam5);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
trace!("indy_open_wallet_search: entities >>> wallet_handle: {:?}, type_: {:?}, query_json: {:?}, options_json: {:?}", wallet_handle, type_, query_json, options_json);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::OpenSearch(
wallet_handle,
type_,
query_json,
options_json,
Box::new(move |result| {
let (err, handle) = prepare_result_1!(result, INVALID_SEARCH_HANDLE);
trace!("indy_open_wallet_search: handle: {:?}", handle);
cb(command_handle, err, handle)
})
)));
let res = prepare_result!(result);
trace!("indy_open_wallet_search: <<< res: {:?}", res);
res
}
/// Fetch next records for wallet search.
///
/// Not if there are no records this call returns WalletNoRecords error.
///
/// #Params
/// wallet_handle: wallet handle (created by open_wallet)
/// wallet_search_handle: wallet search handle (created by indy_open_wallet_search)
/// count: Count of records to fetch
///
/// #Returns
/// wallet records json:
/// {
/// totalCount: <str>, // present only if retrieveTotalCount set to true
/// records: [{ // present only if retrieveRecords set to true
/// id: "Some id",
/// type: "Some type", // present only if retrieveType set to true
/// value: "Some value", // present only if retrieveValue set to true
/// tags: <tags json>, // present only if retrieveTags set to true
/// }],
/// }
#[no_mangle]
pub extern fn indy_fetch_wallet_search_next_records(command_handle: CommandHandle,
wallet_handle: WalletHandle,
wallet_search_handle: SearchHandle,
count: usize,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode,
records_json: *const c_char)>) -> ErrorCode {
trace!("indy_fetch_wallet_search_next_records: >>> wallet_handle: {:?}, wallet_search_handle: {:?}, count: {:?}", wallet_handle, wallet_search_handle, count);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5);
trace!("indy_fetch_wallet_search_next_records: entities >>> wallet_handle: {:?}, wallet_search_handle: {:?}, count: {:?}", wallet_handle, wallet_search_handle, count);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::FetchSearchNextRecords(
wallet_handle,
wallet_search_handle,
count,
boxed_callback_string!("indy_fetch_wallet_search_next_records", cb, command_handle)
)));
let res = prepare_result!(result);
trace!("indy_fetch_wallet_search_next_records: <<< res: {:?}", res);
res
}
/// Close wallet search (make search handle invalid)
///
/// #Params
/// wallet_search_handle: wallet search handle
#[no_mangle]
pub extern fn indy_close_wallet_search(command_handle: CommandHandle,
wallet_search_handle: SearchHandle,
cb: Option<extern fn(command_handle_: CommandHandle, err: ErrorCode)>) -> ErrorCode {
trace!("indy_close_wallet_search: >>> wallet_search_handle: {:?}", wallet_search_handle);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5);
trace!("indy_close_wallet_search: entities >>> wallet_search_handle: {:?}", wallet_search_handle);
let result = CommandExecutor::instance()
.send(Command::NonSecrets(
NonSecretsCommand::CloseSearch(
wallet_search_handle,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_close_wallet_search:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_close_wallet_search: <<< res: {:?}", res);
res
}