This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathissuer.rs
3252 lines (2918 loc) · 121 KB
/
issuer.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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use crate::cl::issuer::*;
use crate::cl::*;
use crate::errors::prelude::*;
use crate::ffi::cl::{FFITailPut, FFITailTake, FFITailsAccessor};
use crate::ffi::ErrorCode;
use crate::utils::ctypes::*;
use serde_json;
use std::collections::HashSet;
use std::iter::FromIterator;
use std::os::raw::{c_char, c_void};
use std::ptr::null;
use std::slice;
/// Creates and returns credential definition (public and private keys, correctness proof) entities.
///
/// Note that credential public key instances deallocation must be performed by
/// calling ursa_cl_credential_public_key_free.
///
/// Note that credential private key instances deallocation must be performed by
/// calling ursa_cl_credential_private_key_free.
///
/// Note that credential key correctness proof instances deallocation must be performed by
/// calling ursa_cl_credential_key_correctness_proof_free.
///
/// # Arguments
/// * `credential_schema` - Reference that contains credential schema instance pointer.
/// * `non_credential_schema` - Reference that contains non credential schema instance pointer
/// * `support_revocation` - If true non revocation part of credential keys will be generated.
/// * `credential_pub_key_p` - Reference that will contain credential public key instance pointer.
/// * `credential_priv_key_p` - Reference that will contain credential private key instance pointer.
/// * `credential_key_correctness_proof_p` - Reference that will contain credential keys correctness proof instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_issuer_new_credential_def(
credential_schema: *const c_void,
non_credential_schema: *const c_void,
support_revocation: bool,
credential_pub_key_p: *mut *const c_void,
credential_priv_key_p: *mut *const c_void,
credential_key_correctness_proof_p: *mut *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_issuer_new_credential_def: >>> credential_schema: {:?}, \
non_credential_schema: {:?}, \
support_revocation: {:?}, \
credential_pub_key_p: {:?}, \
credential_priv_key_p: {:?},\
credential_key_correctness_proof_p: {:?}",
credential_schema,
non_credential_schema,
support_revocation,
credential_pub_key_p,
credential_priv_key_p,
credential_key_correctness_proof_p
);
check_useful_c_reference!(
credential_schema,
CredentialSchema,
ErrorCode::CommonInvalidParam1
);
check_useful_c_reference!(
non_credential_schema,
NonCredentialSchema,
ErrorCode::CommonInvalidParam2
);
check_useful_c_ptr!(credential_pub_key_p, ErrorCode::CommonInvalidParam3);
check_useful_c_ptr!(credential_priv_key_p, ErrorCode::CommonInvalidParam4);
check_useful_c_ptr!(
credential_key_correctness_proof_p,
ErrorCode::CommonInvalidParam5
);
trace!(
"ursa_cl_issuer_new_credential_def: entities: \
credential_schema: {:?}, \
non_credential_schema: {:?}, \
support_revocation: {:?}",
credential_schema,
non_credential_schema,
support_revocation
);
let res = match Issuer::new_credential_def(
credential_schema,
non_credential_schema,
support_revocation,
) {
Ok((credential_pub_key, credential_priv_key, credential_key_correctness_proof)) => {
trace!("ursa_cl_issuer_new_credential_def: credential_pub_key: {:?}, credential_priv_key: {:?}, credential_key_correctness_proof: {:?}",
credential_pub_key, secret!(&credential_priv_key), credential_key_correctness_proof);
unsafe {
*credential_pub_key_p =
Box::into_raw(Box::new(credential_pub_key)) as *const c_void;
*credential_priv_key_p =
Box::into_raw(Box::new(credential_priv_key)) as *const c_void;
*credential_key_correctness_proof_p =
Box::into_raw(Box::new(credential_key_correctness_proof)) as *const c_void;
trace!("ursa_cl_issuer_new_credential_def: *credential_pub_key_p: {:?}, *credential_priv_key_p: {:?}, *credential_key_correctness_proof_p: {:?}",
*credential_pub_key_p, *credential_priv_key_p, *credential_key_correctness_proof_p);
}
ErrorCode::Success
}
Err(err) => err.into(),
};
trace!("ursa_cl_issuer_new_credential_def: <<< res: {:?}", res);
res
}
/// Returns json representation of credential public key.
///
/// # Arguments
/// * `credential_pub_key` - Reference that contains credential public key instance pointer.
/// * `credential_pub_key_p` - Reference that will contain credential public key json.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_public_key_to_json(
credential_pub_key: *const c_void,
credential_pub_key_json_p: *mut *const c_char,
) -> ErrorCode {
trace!("ursa_cl_credential_public_key_to_json: >>> credential_pub_key: {:?}, credential_pub_key_json_p: {:?}", credential_pub_key, credential_pub_key_json_p);
check_useful_c_reference!(
credential_pub_key,
CredentialPublicKey,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(credential_pub_key_json_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_credential_public_key_to_json: entity >>> credential_pub_key: {:?}",
credential_pub_key
);
let res = match serde_json::to_string(credential_pub_key) {
Ok(credential_pub_key_json) => {
trace!(
"ursa_cl_credential_public_key_to_json: credential_pub_key_json: {:?}",
credential_pub_key_json
);
unsafe {
let issuer_pub_key_json = string_to_cstring(credential_pub_key_json);
*credential_pub_key_json_p = issuer_pub_key_json.into_raw();
trace!(
"ursa_cl_credential_private_key_to_json: credential_pub_key_json_p: {:?}",
*credential_pub_key_json_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize credential public key as json",
)
.into(),
};
trace!("ursa_cl_credential_public_key_to_json: <<< res: {:?}", res);
res
}
/// Creates and returns credential public key from json.
///
/// Note: Credential public key instance deallocation must be performed
/// by calling ursa_cl_credential_public_key_free
///
/// # Arguments
/// * `credential_pub_key_json` - Reference that contains credential public key json.
/// * `credential_pub_key_p` - Reference that will contain credential public key instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_public_key_from_json(
credential_pub_key_json: *const c_char,
credential_pub_key_p: *mut *const c_void,
) -> ErrorCode {
trace!("ursa_cl_credential_public_key_from_json: >>> credential_pub_key_json: {:?}, credential_pub_key_p: {:?}", credential_pub_key_json, credential_pub_key_p);
check_useful_c_str!(credential_pub_key_json, ErrorCode::CommonInvalidParam1);
check_useful_c_ptr!(credential_pub_key_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_credential_public_key_from_json: entity: credential_pub_key_json: {:?}",
credential_pub_key_json
);
let res = match serde_json::from_str::<CredentialPublicKey>(&credential_pub_key_json) {
Ok(credential_pub_key) => {
trace!(
"ursa_cl_credential_public_key_from_json: credential_pub_key: {:?}",
credential_pub_key
);
unsafe {
*credential_pub_key_p =
Box::into_raw(Box::new(credential_pub_key)) as *const c_void;
trace!(
"ursa_cl_credential_public_key_from_json: *credential_pub_key_p: {:?}",
*credential_pub_key_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize credential public key from json",
)
.into(),
};
trace!(
"ursa_cl_credential_public_key_from_json: <<< res: {:?}",
res
);
res
}
/// Deallocates credential public key instance.
///
/// # Arguments
/// * `credential_pub_key` - Reference that contains credential public key instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_public_key_free(
credential_pub_key: *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_credential_public_key_free: >>> credential_pub_key: {:?}",
credential_pub_key
);
check_useful_c_ptr!(credential_pub_key, ErrorCode::CommonInvalidParam1);
let credential_pub_key =
unsafe { Box::from_raw(credential_pub_key as *mut CredentialPublicKey) };
trace!(
"ursa_cl_credential_public_key_free: entity: credential_pub_key: {:?}",
credential_pub_key
);
let res = ErrorCode::Success;
trace!("ursa_cl_credential_public_key_free: <<< res: {:?}", res);
res
}
/// Returns json representation of credential private key.
///
/// # Arguments
/// * `credential_priv_key` - Reference that contains credential private key instance pointer.
/// * `credential_pub_key_p` - Reference that will contain credential private key json.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_private_key_to_json(
credential_priv_key: *const c_void,
credential_priv_key_json_p: *mut *const c_char,
) -> ErrorCode {
trace!("ursa_cl_credential_private_key_to_json: >>> credential_priv_key: {:?}, credential_priv_key_json_p: {:?}", credential_priv_key, credential_priv_key_json_p);
check_useful_c_reference!(
credential_priv_key,
CredentialPrivateKey,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(credential_priv_key_json_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_credential_private_key_to_json: entity >>> credential_priv_key: {:?}",
secret!(&credential_priv_key)
);
let res = match serde_json::to_string(credential_priv_key) {
Ok(credential_priv_key_json) => {
trace!(
"ursa_cl_credential_private_key_to_json: credential_priv_key_json: {:?}",
secret!(&credential_priv_key_json)
);
unsafe {
let credential_priv_key_json = string_to_cstring(credential_priv_key_json);
*credential_priv_key_json_p = credential_priv_key_json.into_raw();
trace!(
"ursa_cl_credential_private_key_to_json: credential_priv_key_json_p: {:?}",
*credential_priv_key_json_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize credential private key as json",
)
.into(),
};
trace!("ursa_cl_credential_private_key_to_json: <<< res: {:?}", res);
res
}
/// Creates and returns credential private key from json.
///
/// Note: Credential private key instance deallocation must be performed
/// by calling ursa_cl_credential_private_key_free
///
/// # Arguments
/// * `credential_priv_key_json` - Reference that contains credential private key json.
/// * `credential_priv_key_p` - Reference that will contain credential private key instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_private_key_from_json(
credential_priv_key_json: *const c_char,
credential_priv_key_p: *mut *const c_void,
) -> ErrorCode {
trace!("ursa_cl_credential_private_key_from_json: >>> credential_priv_key_json: {:?}, credential_priv_key_p: {:?}", credential_priv_key_json, credential_priv_key_p);
check_useful_c_str!(credential_priv_key_json, ErrorCode::CommonInvalidParam1);
check_useful_c_ptr!(credential_priv_key_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_credential_private_key_from_json: entity: credential_priv_key_json: {:?}",
secret!(&credential_priv_key_json)
);
let res = match serde_json::from_str::<CredentialPrivateKey>(&credential_priv_key_json) {
Ok(credential_priv_key) => {
trace!(
"ursa_cl_credential_private_key_from_json: credential_priv_key: {:?}",
secret!(&credential_priv_key)
);
unsafe {
*credential_priv_key_p =
Box::into_raw(Box::new(credential_priv_key)) as *const c_void;
trace!(
"ursa_cl_credential_private_key_from_json: *credential_priv_key_p: {:?}",
*credential_priv_key_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize credential private key from json",
)
.into(),
};
trace!(
"ursa_cl_credential_private_key_from_json: <<< res: {:?}",
res
);
res
}
/// Deallocates credential private key instance.
///
/// # Arguments
/// * `credential_priv_key` - Reference that contains credential private key instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_private_key_free(
credential_priv_key: *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_credential_private_key_free: >>> credential_priv_key: {:?}",
credential_priv_key
);
check_useful_c_ptr!(credential_priv_key, ErrorCode::CommonInvalidParam1);
let _credential_priv_key =
unsafe { Box::from_raw(credential_priv_key as *mut CredentialPrivateKey) };
trace!(
"ursa_cl_credential_private_key_free: entity: credential_priv_key: {:?}",
secret!(_credential_priv_key)
);
let res = ErrorCode::Success;
trace!("ursa_cl_credential_private_key_free: <<< res: {:?}", res);
res
}
/// Returns json representation of credential key correctness proof.
///
/// # Arguments
/// * `credential_key_correctness_proof` - Reference that contains credential key correctness proof instance pointer.
/// * `credential_key_correctness_proof_p` - Reference that will contain credential key correctness proof json.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_key_correctness_proof_to_json(
credential_key_correctness_proof: *const c_void,
credential_key_correctness_proof_json_p: *mut *const c_char,
) -> ErrorCode {
trace!("ursa_cl_credential_key_correctness_proof_to_json: >>> credential_key_correctness_proof: {:?}, credential_key_correctness_proof_p: {:?}",
credential_key_correctness_proof, credential_key_correctness_proof_json_p);
check_useful_c_reference!(
credential_key_correctness_proof,
CredentialKeyCorrectnessProof,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(
credential_key_correctness_proof_json_p,
ErrorCode::CommonInvalidParam2
);
trace!("ursa_cl_credential_key_correctness_proof_to_json: entity >>> credential_key_correctness_proof: {:?}", credential_key_correctness_proof);
let res = match serde_json::to_string(credential_key_correctness_proof) {
Ok(credential_key_correctness_proof_json) => {
trace!("ursa_cl_credential_key_correctness_proof_to_json: credential_key_correctness_proof_json: {:?}", credential_key_correctness_proof_json);
unsafe {
let credential_key_correctness_proof_json =
string_to_cstring(credential_key_correctness_proof_json);
*credential_key_correctness_proof_json_p =
credential_key_correctness_proof_json.into_raw();
trace!("ursa_cl_credential_key_correctness_proof_to_json: credential_key_correctness_proof_json_p: {:?}", *credential_key_correctness_proof_json_p);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize credential key correctness proof as json",
)
.into(),
};
trace!(
"ursa_cl_credential_key_correctness_proof_to_json: <<< res: {:?}",
res
);
res
}
/// Creates and returns credential key correctness proof from json.
///
/// Note: Credential key correctness proof instance deallocation must be performed
/// by calling ursa_cl_credential_key_correctness_proof_free
///
/// # Arguments
/// * `credential_key_correctness_proof_json` - Reference that contains credential key correctness proof json.
/// * `credential_key_correctness_proof_p` - Reference that will contain credential key correctness proof instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_key_correctness_proof_from_json(
credential_key_correctness_proof_json: *const c_char,
credential_key_correctness_proof_p: *mut *const c_void,
) -> ErrorCode {
trace!("ursa_cl_credential_key_correctness_proof_from_json: >>> credential_key_correctness_proof_json: {:?}, credential_key_correctness_proof_p: {:?}",
credential_key_correctness_proof_json, credential_key_correctness_proof_p);
check_useful_c_str!(
credential_key_correctness_proof_json,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(
credential_key_correctness_proof_p,
ErrorCode::CommonInvalidParam2
);
trace!("ursa_cl_credential_key_correctness_proof_from_json: entity: credential_key_correctness_proof_json: {:?}", credential_key_correctness_proof_json);
let res = match serde_json::from_str::<CredentialKeyCorrectnessProof>(
&credential_key_correctness_proof_json,
) {
Ok(credential_key_correctness_proof) => {
trace!("ursa_cl_credential_key_correctness_proof_from_json: credential_key_correctness_proof: {:?}", credential_key_correctness_proof);
unsafe {
*credential_key_correctness_proof_p =
Box::into_raw(Box::new(credential_key_correctness_proof)) as *const c_void;
trace!("ursa_cl_credential_key_correctness_proof_from_json: *credential_key_correctness_proof_p: {:?}", *credential_key_correctness_proof_p);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize credential key correctness proof from json",
)
.into(),
};
trace!(
"ursa_cl_credential_key_correctness_proof_from_json: <<< res: {:?}",
res
);
res
}
/// Deallocates credential key correctness proof instance.
///
/// # Arguments
/// * `credential_key_correctness_proof` - Reference that contains credential key correctness proof instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_key_correctness_proof_free(
credential_key_correctness_proof: *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_credential_key_correctness_proof_free: >>> credential_key_correctness_proof: {:?}",
credential_key_correctness_proof
);
check_useful_c_ptr!(
credential_key_correctness_proof,
ErrorCode::CommonInvalidParam1
);
let credential_key_correctness_proof = unsafe {
Box::from_raw(credential_key_correctness_proof as *mut CredentialKeyCorrectnessProof)
};
trace!("ursa_cl_credential_key_correctness_proof_free: entity: credential_key_correctness_proof: {:?}", credential_key_correctness_proof);
let res = ErrorCode::Success;
trace!(
"ursa_cl_credential_key_correctness_proof_free: <<< res: {:?}",
res
);
res
}
/// Creates and returns revocation registries definition (public and private keys, accumulator, tails generator) entities.
///
/// Note that keys registries deallocation must be performed by
/// calling ursa_cl_revocation_key_public_free and
/// ursa_cl_revocation_key_private_free.
///
/// Note that accumulator deallocation must be performed by
/// calling ursa_cl_revocation_registry_free.
///
/// Note that tails generator deallocation must be performed by
/// calling ursa_cl_revocation_tails_generator_free.
///
/// # Arguments
/// * `credential_pub_key` - Reference that contains credential pub key instance pointer.
/// * `max_cred_num` - Max credential number in generated registry.
/// * `issuance_by_default` - Type of issuance.
/// If true all indices are assumed to be issued and initial accumulator is calculated over all indices
/// If false nothing is issued initially accumulator is 1
/// * `rev_key_pub_p` - Reference that will contain revocation key public instance pointer.
/// * `rev_key_priv_p` - Reference that will contain revocation key private instance pointer.
/// * `rev_reg_p` - Reference that will contain revocation registry instance pointer.
/// * `rev_tails_generator_p` - Reference that will contain revocation tails generator instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_issuer_new_revocation_registry_def(
credential_pub_key: *const c_void,
max_cred_num: u32,
issuance_by_default: bool,
rev_key_pub_p: *mut *const c_void,
rev_key_priv_p: *mut *const c_void,
rev_reg_p: *mut *const c_void,
rev_tails_generator_p: *mut *const c_void,
) -> ErrorCode {
trace!("ursa_cl_issuer_new_revocation_registry_def: >>> credential_pub_key: {:?}, max_cred_num: {:?}, rev_key_pub_p: {:?}, rev_key_priv_p: {:?}, \
rev_reg_p: {:?}, rev_tails_generator_p: {:?}",
credential_pub_key, max_cred_num, rev_key_pub_p, rev_key_priv_p, rev_reg_p, rev_tails_generator_p);
check_useful_c_reference!(
credential_pub_key,
CredentialPublicKey,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(rev_key_pub_p, ErrorCode::CommonInvalidParam4);
check_useful_c_ptr!(rev_key_priv_p, ErrorCode::CommonInvalidParam5);
check_useful_c_ptr!(rev_reg_p, ErrorCode::CommonInvalidParam6);
check_useful_c_ptr!(rev_tails_generator_p, ErrorCode::CommonInvalidParam7);
trace!("ursa_cl_issuer_new_revocation_registry_def: entities: credential_pub_key: {:?}, max_cred_num: {:?}", credential_pub_key, max_cred_num);
let res = match Issuer::new_revocation_registry_def(
credential_pub_key,
max_cred_num,
issuance_by_default,
) {
Ok((rev_key_pub, rev_key_priv, rev_reg, rev_tails_generator)) => {
trace!("ursa_cl_issuer_new_revocation_registry_def: rev_key_pub_p: {:?}, rev_key_priv: {:?}, rev_reg: {:?}, rev_tails_generator: {:?}",
rev_key_pub_p, secret!(&rev_key_priv), rev_reg, rev_tails_generator);
unsafe {
*rev_key_pub_p = Box::into_raw(Box::new(rev_key_pub)) as *const c_void;
*rev_key_priv_p = Box::into_raw(Box::new(rev_key_priv)) as *const c_void;
*rev_reg_p = Box::into_raw(Box::new(rev_reg)) as *const c_void;
*rev_tails_generator_p =
Box::into_raw(Box::new(rev_tails_generator)) as *const c_void;
trace!("ursa_cl_issuer_new_revocation_registry_def: *rev_key_pub_p: {:?}, *rev_key_priv_p: {:?}, *rev_reg_p: {:?}, *rev_tails_generator_p: {:?}",
*rev_key_pub_p, *rev_key_priv_p, *rev_reg_p, *rev_tails_generator_p);
}
ErrorCode::Success
}
Err(err) => err.into(),
};
trace!(
"ursa_cl_issuer_new_revocation_registry_def: <<< res: {:?}",
res
);
res
}
/// Returns json representation of revocation key public.
///
/// # Arguments
/// * `rev_key_pub` - Reference that contains revocation key public pointer.
/// * `rev_key_pub_json_p` - Reference that will contain revocation key public json.
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_key_public_to_json(
rev_key_pub: *const c_void,
rev_key_pub_json_p: *mut *const c_char,
) -> ErrorCode {
trace!(
"ursa_cl_revocation_key_public_to_json: >>> rev_key_pub: {:?}, rev_key_pub_json_p: {:?}",
rev_key_pub,
rev_key_pub_json_p
);
check_useful_c_reference!(
rev_key_pub,
RevocationKeyPublic,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(rev_key_pub_json_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_revocation_key_public_to_json: entity >>> rev_key_pub: {:?}",
rev_key_pub
);
let res = match serde_json::to_string(rev_key_pub) {
Ok(rev_key_pub_json) => {
trace!(
"ursa_cl_revocation_key_public_to_json: rev_key_pub_json: {:?}",
rev_key_pub_json
);
unsafe {
let rev_reg_def_pub_json = string_to_cstring(rev_key_pub_json);
*rev_key_pub_json_p = rev_reg_def_pub_json.into_raw();
trace!(
"ursa_cl_revocation_key_public_to_json: rev_key_pub_json_p: {:?}",
*rev_key_pub_json_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize revocation key public as json",
)
.into(),
};
trace!("ursa_cl_revocation_key_public_to_json: <<< res: {:?}", res);
res
}
/// Creates and returns revocation key public from json.
///
/// Note: Revocation registry public instance deallocation must be performed
/// by calling ursa_cl_revocation_key_public_free
///
/// # Arguments
/// * `rev_key_pub_json` - Reference that contains revocation key public json.
/// * `rev_key_pub_p` - Reference that will contain revocation key public instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_key_public_from_json(
rev_key_pub_json: *const c_char,
rev_key_pub_p: *mut *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_revocation_key_public_from_json: >>> rev_key_pub_json: {:?}, rev_key_pub_p: {:?}",
rev_key_pub_json,
rev_key_pub_p
);
check_useful_c_str!(rev_key_pub_json, ErrorCode::CommonInvalidParam1);
check_useful_c_ptr!(rev_key_pub_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_revocation_key_public_from_json: entity: rev_key_pub_json: {:?}",
rev_key_pub_json
);
let res = match serde_json::from_str::<RevocationKeyPublic>(&rev_key_pub_json) {
Ok(rev_key_pub) => {
trace!(
"ursa_cl_revocation_key_public_from_json: rev_key_pub: {:?}",
rev_key_pub
);
unsafe {
*rev_key_pub_p = Box::into_raw(Box::new(rev_key_pub)) as *const c_void;
trace!(
"ursa_cl_revocation_key_public_from_json: *rev_key_pub_p: {:?}",
*rev_key_pub_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize revocation key public from json",
)
.into(),
};
trace!(
"ursa_cl_revocation_key_public_from_json: <<< res: {:?}",
res
);
res
}
/// Deallocates revocation key public instance.
///
/// # Arguments
/// * `rev_key_pub` - Reference that contains revocation key public instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_key_public_free(rev_key_pub: *const c_void) -> ErrorCode {
trace!(
"ursa_cl_revocation_key_public_free: >>> rev_key_pub: {:?}",
rev_key_pub
);
check_useful_c_ptr!(rev_key_pub, ErrorCode::CommonInvalidParam1);
let rev_key_pub = unsafe { Box::from_raw(rev_key_pub as *mut RevocationKeyPublic) };
trace!(
"ursa_cl_revocation_key_public_free: entity: rev_key_pub: {:?}",
rev_key_pub
);
let res = ErrorCode::Success;
trace!("ursa_cl_revocation_key_public_free: <<< res: {:?}", res);
res
}
/// Returns json representation of revocation key private.
///
/// # Arguments
/// * `rev_key_priv` - Reference that contains issuer revocation key private pointer.
/// * `rev_key_priv_json_p` - Reference that will contain revocation key private json
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_key_private_to_json(
rev_key_priv: *const c_void,
rev_key_priv_json_p: *mut *const c_char,
) -> ErrorCode {
trace!(
"ursa_cl_revocation_key_private_to_json: >>> rev_key_priv: {:?}, rev_key_priv_json_p: {:?}",
rev_key_priv,
rev_key_priv_json_p
);
check_useful_c_reference!(
rev_key_priv,
RevocationKeyPrivate,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(rev_key_priv_json_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_revocation_key_private_to_json: entity >>> rev_key_priv: {:?}",
secret!(&rev_key_priv)
);
let res = match serde_json::to_string(rev_key_priv) {
Ok(rev_key_priv_json) => {
trace!(
"ursa_cl_revocation_key_private_to_json: rev_key_priv_json: {:?}",
secret!(&rev_key_priv_json)
);
unsafe {
let rev_reg_def_priv_json = string_to_cstring(rev_key_priv_json);
*rev_key_priv_json_p = rev_reg_def_priv_json.into_raw();
trace!(
"ursa_cl_revocation_key_private_to_json: rev_key_priv_json_p: {:?}",
*rev_key_priv_json_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize revocation key private as json",
)
.into(),
};
trace!("ursa_cl_revocation_key_private_to_json: <<< res: {:?}", res);
res
}
/// Creates and returns revocation key private from json.
///
/// Note: Revocation registry private instance deallocation must be performed
/// by calling ursa_cl_revocation_key_private_free
///
/// # Arguments
/// * `rev_key_priv_json` - Reference that contains revocation key private json.
/// * `rev_key_priv_p` - Reference that will contain revocation key private instance pointer
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_key_private_from_json(
rev_key_priv_json: *const c_char,
rev_key_priv_p: *mut *const c_void,
) -> ErrorCode {
trace!("ursa_cl_revocation_key_private_from_json: >>> rev_key_priv_json: {:?}, rev_key_priv_p: {:?}",
rev_key_priv_json, rev_key_priv_p);
check_useful_c_str!(rev_key_priv_json, ErrorCode::CommonInvalidParam1);
check_useful_c_ptr!(rev_key_priv_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_revocation_key_private_from_json: entity: rev_key_priv_json: {:?}",
secret!(&rev_key_priv_json)
);
let res = match serde_json::from_str::<RevocationKeyPrivate>(&rev_key_priv_json) {
Ok(rev_key_priv) => {
trace!(
"ursa_cl_revocation_key_private_from_json: rev_key_priv: {:?}",
secret!(&rev_key_priv)
);
unsafe {
*rev_key_priv_p = Box::into_raw(Box::new(rev_key_priv)) as *const c_void;
trace!(
"ursa_cl_revocation_key_private_from_json: *rev_key_priv_p: {:?}",
*rev_key_priv_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize revocation key private from json",
)
.into(),
};
trace!(
"ursa_cl_revocation_key_private_from_json: <<< res: {:?}",
res
);
res
}
/// Deallocates revocation key private instance.
///
/// # Arguments
/// * `rev_key_priv` - Reference that contains revocation key private instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_key_private_free(rev_key_priv: *const c_void) -> ErrorCode {
trace!(
"ursa_cl_revocation_key_private_free: >>> rev_key_priv: {:?}",
rev_key_priv
);
check_useful_c_ptr!(rev_key_priv, ErrorCode::CommonInvalidParam1);
let _rev_key_priv = unsafe { Box::from_raw(rev_key_priv as *mut RevocationKeyPrivate) };
trace!(
"ursa_cl_revocation_key_private_free: entity: rev_key_priv: {:?}",
secret!(_rev_key_priv)
);
let res = ErrorCode::Success;
trace!("ursa_cl_revocation_key_private_free: <<< res: {:?}", res);
res
}
/// Returns json representation of revocation registry.
///
/// # Arguments
/// * `rev_reg` - Reference that contains revocation registry pointer.
/// * `rev_reg_p` - Reference that will contain revocation registry json
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_registry_to_json(
rev_reg: *const c_void,
rev_reg_json_p: *mut *const c_char,
) -> ErrorCode {
trace!(
"ursa_cl_revocation_registry_to_json: >>> rev_reg: {:?}, rev_reg_json_p: {:?}",
rev_reg,
rev_reg_json_p
);
check_useful_c_reference!(rev_reg, RevocationRegistry, ErrorCode::CommonInvalidParam1);
check_useful_c_ptr!(rev_reg_json_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_revocation_registry_to_json: entity >>> rev_reg: {:?}",
rev_reg
);
let res = match serde_json::to_string(rev_reg) {
Ok(rev_reg_json) => {
trace!(
"ursa_cl_revocation_registry_to_json: rev_reg_json: {:?}",
rev_reg_json
);
unsafe {
let rev_reg_json = string_to_cstring(rev_reg_json);
*rev_reg_json_p = rev_reg_json.into_raw();
trace!(
"ursa_cl_revocation_registry_to_json: rev_reg_json_p: {:?}",
*rev_reg_json_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize revocation registry as json",
)
.into(),
};
trace!("ursa_cl_revocation_registry_to_json: <<< res: {:?}", res);
res
}
/// Creates and returns revocation registry from json.
///
/// Note: Revocation registry instance deallocation must be performed
/// by calling ursa_cl_revocation_registry_free
///
/// # Arguments
/// * `rev_reg_json` - Reference that contains revocation registry json.
/// * `rev_reg_p` - Reference that will contain revocation registry instance pointer
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_registry_from_json(
rev_reg_json: *const c_char,
rev_reg_p: *mut *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_revocation_registry_from_json: >>> rev_reg_json: {:?}, rev_reg_p: {:?}",
rev_reg_json,
rev_reg_p
);
check_useful_c_str!(rev_reg_json, ErrorCode::CommonInvalidParam1);
check_useful_c_ptr!(rev_reg_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_revocation_registry_from_json: entity: rev_reg_json: {:?}",
rev_reg_json
);
let res = match serde_json::from_str::<RevocationRegistry>(&rev_reg_json) {
Ok(rev_reg) => {
trace!(
"ursa_cl_revocation_registry_from_json: rev_reg: {:?}",
rev_reg
);
unsafe {
*rev_reg_p = Box::into_raw(Box::new(rev_reg)) as *const c_void;
trace!(
"ursa_cl_revocation_registry_from_json: *rev_reg_p: {:?}",
*rev_reg_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize revocation registry from json",
)
.into(),
};
trace!("ursa_cl_revocation_registry_from_json: <<< res: {:?}", res);
res
}
/// Deallocates revocation registry instance.
///
/// # Arguments
/// * `rev_reg` - Reference that contains revocation registry instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_revocation_registry_free(rev_reg: *const c_void) -> ErrorCode {
trace!(
"ursa_cl_revocation_registry_free: >>> rev_reg: {:?}",
rev_reg
);
check_useful_c_ptr!(rev_reg, ErrorCode::CommonInvalidParam1);
let rev_reg = unsafe { Box::from_raw(rev_reg as *mut RevocationRegistry) };
trace!(
"ursa_cl_revocation_registry_free: entity: rev_reg: {:?}",
rev_reg
);
let res = ErrorCode::Success;
trace!("ursa_cl_revocation_registry_free: <<< res: {:?}", res);
res
}
/// Returns json representation of revocation tails generator.
///
/// # Arguments
/// * `rev_tails_generator` - Reference that contains revocation tails generator pointer.