File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed
wrappers/python/indy_credx Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,29 @@ pub extern "C" fn credx_create_credential(
151151 } )
152152}
153153
154+ #[ no_mangle]
155+ pub extern "C" fn credx_encode_credential_attributes (
156+ attr_raw_values : FfiStrList ,
157+ result_p : * mut * const c_char ,
158+ ) -> ErrorCode {
159+ catch_error ( || {
160+ let mut result = String :: new ( ) ;
161+ for raw_val in attr_raw_values. as_slice ( ) {
162+ let enc_val = encode_credential_attribute (
163+ raw_val
164+ . as_opt_str ( )
165+ . ok_or_else ( || err_msg ! ( "Missing attribute raw value" ) ) ?,
166+ ) ?;
167+ if !result. is_empty ( ) {
168+ result. push ( ',' ) ;
169+ }
170+ result. push_str ( enc_val. as_str ( ) ) ;
171+ }
172+ unsafe { * result_p = rust_string_to_c ( result) } ;
173+ Ok ( ( ) )
174+ } )
175+ }
176+
154177#[ no_mangle]
155178pub extern "C" fn credx_process_credential (
156179 cred : ObjectHandle ,
Original file line number Diff line number Diff line change 11"""Indy-Credx Python wrapper library"""
22
3- from .bindings import generate_nonce , library_version
3+ from .bindings import encode_credential_attributes , generate_nonce , library_version
44from .error import CredxError , CredxErrorCode
55from .types import (
66 Credential ,
2323)
2424
2525__all__ = (
26+ "encode_credential_attributes" ,
2627 "generate_nonce" ,
2728 "library_version" ,
2829 "CredxError" ,
Original file line number Diff line number Diff line change @@ -467,8 +467,9 @@ def create_credential(
467467 cred = ObjectHandle ()
468468 rev_reg = ObjectHandle ()
469469 rev_delta = ObjectHandle ()
470- names_list = str_list .create (attr_raw_values .keys ())
471- raw_values_list = str_list .create (attr_raw_values .values ())
470+ attr_keys = list (attr_raw_values .keys ())
471+ names_list = str_list .create (attr_keys )
472+ raw_values_list = str_list .create (str (attr_raw_values [k ]) for k in attr_keys )
472473 if attr_enc_values :
473474 enc_values_list = []
474475 for name in attr_raw_values :
@@ -495,6 +496,16 @@ def create_credential(
495496 return cred , rev_reg , rev_delta
496497
497498
499+ def encode_credential_attributes (
500+ attr_raw_values : Mapping [str , str ]
501+ ) -> Mapping [str , str ]:
502+ attr_keys = list (attr_raw_values .keys ())
503+ raw_values_list = str_list .create (str (attr_raw_values [k ]) for k in attr_keys )
504+ result = lib_string ()
505+ do_call ("credx_encode_credential_attributes" , raw_values_list , byref (result ))
506+ return dict (zip (attr_keys , str (result ).split ("," )))
507+
508+
498509def process_credential (
499510 cred : ObjectHandle ,
500511 cred_req_metadata : ObjectHandle ,
You can’t perform that action at this time.
0 commit comments