@@ -22,6 +22,8 @@ mod ios {
22
22
pub struct AuthenticatorRequestResponse {
23
23
pub auth_data_bytes : Vec < u8 > ,
24
24
pub signature : Vec < u8 > ,
25
+ pub success : bool ,
26
+ pub error_message : String ,
25
27
}
26
28
27
29
#[ repr( C ) ]
@@ -129,25 +131,42 @@ mod ios {
129
131
130
132
let auth_data = WebauthnAuthenticator :: generate_authenticator_data ( rp_id_str. as_str ( ) , u8:: from_be ( attestation_flags) , None ) ;
131
133
132
- if auth_data. is_err ( ) {
133
- return null_mut ( ) ;
134
+ if let Err ( e) = auth_data {
135
+ return Box :: into_raw ( Box :: new ( AuthenticatorRequestResponse {
136
+ auth_data_bytes : Vec :: new ( ) ,
137
+ signature : Vec :: new ( ) ,
138
+ success : false ,
139
+ error_message : format ! ( "Error generating auth data: {e:?}" ) ,
140
+ } ) ) ;
134
141
}
135
142
136
143
let auth_data_bytes = auth_data. expect ( "Checked above" ) . to_vec ( ) ;
137
- if auth_data_bytes. is_err ( ) {
138
- return null_mut ( ) ;
144
+ if let Err ( e) = auth_data_bytes {
145
+ return Box :: into_raw ( Box :: new ( AuthenticatorRequestResponse {
146
+ auth_data_bytes : Vec :: new ( ) ,
147
+ signature : Vec :: new ( ) ,
148
+ success : false ,
149
+ error_message : format ! ( "Error converting auth data to bytes: {e:?}" ) ,
150
+ } ) ) ;
139
151
}
140
152
let auth_data_bytes = auth_data_bytes. expect ( "Checked above" ) ;
141
153
142
154
let signature = WebauthnAuthenticator :: generate_signature ( auth_data_bytes. as_slice ( ) , client_data_hash. as_slice ( ) , private_key) ;
143
155
144
- if signature. is_err ( ) {
145
- return null_mut ( ) ;
156
+ if let Err ( e) = signature {
157
+ return Box :: into_raw ( Box :: new ( AuthenticatorRequestResponse {
158
+ auth_data_bytes : Vec :: new ( ) ,
159
+ signature : Vec :: new ( ) ,
160
+ success : false ,
161
+ error_message : format ! ( "Error signing data: {e:?}" ) ,
162
+ } ) ) ;
146
163
}
147
164
148
165
Box :: into_raw ( Box :: new ( AuthenticatorRequestResponse {
149
166
auth_data_bytes,
150
167
signature : signature. expect ( "Checked above" ) ,
168
+ success : true ,
169
+ error_message : String :: new ( ) ,
151
170
} ) )
152
171
}
153
172
@@ -163,6 +182,28 @@ mod ios {
163
182
}
164
183
}
165
184
185
+ #[ no_mangle]
186
+ pub unsafe extern "C" fn is_success ( res : * mut AuthenticatorRequestResponse ) -> bool {
187
+ if res. is_null ( ) {
188
+ return false ;
189
+ }
190
+
191
+ ( * res) . success
192
+ }
193
+
194
+ #[ no_mangle]
195
+ pub unsafe extern "C" fn get_error_message ( res : * mut AuthenticatorRequestResponse ) -> * mut c_char {
196
+ if res. is_null ( ) {
197
+ return null_mut ( ) ;
198
+ }
199
+
200
+ let cstring = CString :: new ( ( * res) . error_message . clone ( ) ) ;
201
+ match cstring {
202
+ Ok ( cstring) => cstring. into_raw ( ) ,
203
+ Err ( _) => null_mut ( ) ,
204
+ }
205
+ }
206
+
166
207
#[ no_mangle]
167
208
pub unsafe extern "C" fn get_signature_from_response ( res : * mut AuthenticatorRequestResponse ) -> Buffer {
168
209
if res. is_null ( ) {
0 commit comments