@@ -7,35 +7,56 @@ use super::error::{catch_error, ErrorCode};
7
7
use super :: object:: { AnoncredsObject , ObjectHandle } ;
8
8
use super :: util:: FfiStrList ;
9
9
use crate :: data_types:: link_secret:: LinkSecret ;
10
- use crate :: data_types:: rev_reg:: RevocationRegistryId ;
11
10
use crate :: error:: Result ;
12
11
use crate :: services:: {
13
12
issuer:: create_credential,
14
13
prover:: process_credential,
15
14
types:: { Credential , CredentialRevocationConfig , MakeCredentialValues } ,
16
15
utils:: encode_credential_attribute,
17
16
} ;
17
+ use crate :: Error ;
18
18
19
19
#[ derive( Debug ) ]
20
20
#[ repr( C ) ]
21
21
pub struct FfiCredRevInfo {
22
22
reg_def : ObjectHandle ,
23
23
reg_def_private : ObjectHandle ,
24
+ status_list : ObjectHandle ,
24
25
reg_idx : i64 ,
25
26
}
26
27
27
28
struct RevocationConfig {
28
29
reg_def : AnoncredsObject ,
29
30
reg_def_private : AnoncredsObject ,
31
+ status_list : AnoncredsObject ,
30
32
reg_idx : u32 ,
31
33
}
32
34
33
- impl RevocationConfig {
34
- pub fn as_ref_config ( & self ) -> Result < CredentialRevocationConfig > {
35
+ impl TryFrom < & FfiCredRevInfo > for RevocationConfig {
36
+ type Error = Error ;
37
+
38
+ fn try_from ( value : & FfiCredRevInfo ) -> Result < Self > {
39
+ Ok ( Self {
40
+ reg_def : value. reg_def . load ( ) ?,
41
+ reg_def_private : value. reg_def_private . load ( ) ?,
42
+ reg_idx : value
43
+ . reg_idx
44
+ . try_into ( )
45
+ . map_err ( |_| err_msg ! ( "Invalid revocation index" ) ) ?,
46
+ status_list : value. status_list . load ( ) ?,
47
+ } )
48
+ }
49
+ }
50
+
51
+ impl < ' a > TryFrom < & ' a RevocationConfig > for CredentialRevocationConfig < ' a > {
52
+ type Error = Error ;
53
+
54
+ fn try_from ( value : & ' a RevocationConfig ) -> Result < Self > {
35
55
Ok ( CredentialRevocationConfig {
36
- reg_def : self . reg_def . cast_ref ( ) ?,
37
- reg_def_private : self . reg_def_private . cast_ref ( ) ?,
38
- registry_idx : self . reg_idx ,
56
+ reg_def : value. reg_def . cast_ref ( ) ?,
57
+ reg_def_private : value. reg_def_private . cast_ref ( ) ?,
58
+ registry_idx : value. reg_idx ,
59
+ status_list : value. status_list . cast_ref ( ) ?,
39
60
} )
40
61
}
41
62
}
@@ -49,8 +70,6 @@ pub extern "C" fn anoncreds_create_credential(
49
70
attr_names : FfiStrList ,
50
71
attr_raw_values : FfiStrList ,
51
72
attr_enc_values : FfiStrList ,
52
- rev_reg_id : FfiStr ,
53
- rev_status_list : ObjectHandle ,
54
73
revocation : * const FfiCredRevInfo ,
55
74
cred_p : * mut ObjectHandle ,
56
75
) -> ErrorCode {
@@ -64,10 +83,6 @@ pub extern "C" fn anoncreds_create_credential(
64
83
"Mismatch between length of attribute names and raw values"
65
84
) ) ;
66
85
}
67
- let rev_reg_id = rev_reg_id
68
- . as_opt_str ( )
69
- . map ( RevocationRegistryId :: new)
70
- . transpose ( ) ?;
71
86
let enc_values = attr_enc_values. as_slice ( ) ;
72
87
let mut cred_values = MakeCredentialValues :: default ( ) ;
73
88
for ( attr_idx, ( name, raw) ) in attr_names
@@ -99,14 +114,7 @@ pub extern "C" fn anoncreds_create_credential(
99
114
None
100
115
} else {
101
116
let revocation = unsafe { & * revocation } ;
102
- Some ( RevocationConfig {
103
- reg_def : revocation. reg_def . load ( ) ?,
104
- reg_def_private : revocation. reg_def_private . load ( ) ?,
105
- reg_idx : revocation
106
- . reg_idx
107
- . try_into ( )
108
- . map_err ( |_| err_msg ! ( "Invalid revocation index" ) ) ?,
109
- } )
117
+ Some ( RevocationConfig :: try_from ( revocation) ?)
110
118
} ;
111
119
112
120
let cred = create_credential (
@@ -115,15 +123,9 @@ pub extern "C" fn anoncreds_create_credential(
115
123
cred_offer. load ( ) ?. cast_ref ( ) ?,
116
124
cred_request. load ( ) ?. cast_ref ( ) ?,
117
125
cred_values. into ( ) ,
118
- rev_reg_id,
119
- rev_status_list
120
- . opt_load ( ) ?
121
- . as_ref ( )
122
- . map ( AnoncredsObject :: cast_ref)
123
- . transpose ( ) ?,
124
126
revocation_config
125
127
. as_ref ( )
126
- . map ( RevocationConfig :: as_ref_config )
128
+ . map ( TryInto :: try_into )
127
129
. transpose ( ) ?,
128
130
) ?;
129
131
let cred = ObjectHandle :: create ( cred) ?;
0 commit comments