1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hks_errcode_adapter.h"
17
18 #include <stddef.h>
19
20 #include "hks_log.h"
21 #include "hks_type.h"
22
23 static const char *g_convertErrMsg = "HUKS operation failed.";
24
25 static struct HksError g_errCodeTable[] = {
26 {
27 .innerErrCode = HKS_SUCCESS,
28 .hksResult = {
29 .errorCode = HKS_SUCCESS,
30 .errorMsg = "Success.",
31 .data = NULL
32 }
33 }, {
34 .innerErrCode = HKS_ERROR_NO_PERMISSION,
35 .hksResult = {
36 .errorCode = HUKS_ERR_CODE_PERMISSION_FAIL,
37 .errorMsg = "Permission check failed. Apply for the required permissions first.",
38 .data = NULL
39 }
40 }, {
41 .innerErrCode = HKS_ERROR_INVALID_ARGUMENT,
42 .hksResult = {
43 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
44 .errorMsg = "Invalid parameters.",
45 .data = NULL
46 }
47 }, {
48 .innerErrCode = HKS_ERROR_INSUFFICIENT_DATA,
49 .hksResult = {
50 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
51 .errorMsg = "Some input parameters are not set.",
52 .data = NULL
53 }
54 }, {
55 .innerErrCode = HKS_ERROR_BUFFER_TOO_SMALL,
56 .hksResult = {
57 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
58 .errorMsg = "Insufficient buffer size.",
59 .data = NULL
60 }
61 }, {
62 .innerErrCode = HKS_ERROR_NULL_POINTER,
63 .hksResult = {
64 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
65 .errorMsg = "The parameter value cannot be null.",
66 .data = NULL
67 }
68 }, {
69 .innerErrCode = HKS_ERROR_INVALID_PUBLIC_KEY,
70 .hksResult = {
71 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
72 .errorMsg = "Invalid public key.",
73 .data = NULL
74 }
75 }, {
76 .innerErrCode = HKS_ERROR_INVALID_KEY_INFO,
77 .hksResult = {
78 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
79 .errorMsg = "Invalid key information.",
80 .data = NULL
81 }
82 }, {
83 .innerErrCode = HKS_ERROR_PARAM_NOT_EXIST,
84 .hksResult = {
85 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
86 .errorMsg = "The parameter does not exist.",
87 .data = NULL
88 }
89 }, {
90 .innerErrCode = HKS_ERROR_NEW_ROOT_KEY_MATERIAL_EXIST,
91 .hksResult = {
92 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
93 .errorMsg = "The root key material already exists.",
94 .data = NULL
95 }
96 }, {
97 .innerErrCode = HKS_ERROR_INVALID_WRAPPED_FORMAT,
98 .hksResult = {
99 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
100 .errorMsg = "The wrapped key data is in invalid format.",
101 .data = NULL
102 }
103 }, {
104 .innerErrCode = HKS_ERROR_CHECK_GET_AUTH_TYP_FAILED,
105 .hksResult = {
106 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
107 .errorMsg = "Failed to obtain the authentication type. It is not set in ParamSet.",
108 .data = NULL
109 }
110 }, {
111 .innerErrCode = HKS_ERROR_CHECK_GET_CHALLENGE_TYPE_FAILED,
112 .hksResult = {
113 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
114 .errorMsg = "Failed to obtain the challenge type. It is not set in ParamSet.",
115 .data = NULL
116 }
117 }, {
118 .innerErrCode = HKS_ERROR_CHECK_GET_ACCESS_TYPE_FAILED,
119 .hksResult = {
120 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
121 .errorMsg = "Failed to obtain the access type. It is not set in ParamSet.",
122 .data = NULL
123 }
124 }, {
125 .innerErrCode = HKS_ERROR_CHECK_GET_AUTH_TOKEN_FAILED,
126 .hksResult = {
127 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
128 .errorMsg = "Failed to obtain the authentication token. It is not set in ParamSet.",
129 .data = NULL
130 }
131 }, {
132 .innerErrCode = HKS_ERROR_INVALID_TIME_OUT,
133 .hksResult = {
134 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
135 .errorMsg = "Invalid timeout parameter.",
136 .data = NULL
137 }
138 }, {
139 .innerErrCode = HKS_ERROR_INVALID_AUTH_TYPE,
140 .hksResult = {
141 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
142 .errorMsg = "Invalid authentication type.",
143 .data = NULL
144 }
145 }, {
146 .innerErrCode = HKS_ERROR_INVALID_CHALLENGE_TYPE,
147 .hksResult = {
148 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
149 .errorMsg = "Invalid challenge type.",
150 .data = NULL
151 }
152 }, {
153 .innerErrCode = HKS_ERROR_INVALID_ACCESS_TYPE,
154 .hksResult = {
155 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
156 .errorMsg = "Invalid access type.",
157 .data = NULL
158 }
159 }, {
160 .innerErrCode = HKS_ERROR_INVALID_AUTH_TOKEN,
161 .hksResult = {
162 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
163 .errorMsg = "Invalid authentication token.",
164 .data = NULL
165 }
166 }, {
167 .innerErrCode = HKS_ERROR_INVALID_SECURE_SIGN_TYPE,
168 .hksResult = {
169 .errorCode = HUKS_ERR_CODE_ILLEGAL_ARGUMENT,
170 .errorMsg = "Invalid secure sign type.",
171 .data = NULL
172 }
173 }, {
174 .innerErrCode = HKS_ERROR_API_NOT_SUPPORTED,
175 .hksResult = {
176 .errorCode = HUKS_ERR_CODE_NOT_SUPPORTED_API,
177 .errorMsg = "This API is not supported.",
178 .data = NULL
179 }
180 }, {
181 .innerErrCode = HKS_ERROR_NOT_SUPPORTED,
182 .hksResult = {
183 .errorCode = HUKS_ERR_CODE_FEATURE_NOT_SUPPORTED,
184 .errorMsg = "The feature is not support.",
185 .data = NULL
186 }
187 }, {
188 .innerErrCode = HKS_ERROR_USER_AUTH_TYPE_NOT_SUPPORT,
189 .hksResult = {
190 .errorCode = HUKS_ERR_CODE_FEATURE_NOT_SUPPORTED,
191 .errorMsg = "The user authentication type is not supported.",
192 .data = NULL
193 }
194 }, {
195 .innerErrCode = HKS_ERROR_CHECK_GET_ALG_FAIL,
196 .hksResult = {
197 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
198 .errorMsg = "Failed to obtain the algorithm. It is not set in ParamSet.",
199 .data = NULL
200 }
201 }, {
202 .innerErrCode = HKS_ERROR_CHECK_GET_KEY_SIZE_FAIL,
203 .hksResult = {
204 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
205 .errorMsg = "Failed to obtain the key size. It is not set in ParamSet.",
206 .data = NULL
207 }
208 }, {
209 .innerErrCode = HKS_ERROR_CHECK_GET_PADDING_FAIL,
210 .hksResult = {
211 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
212 .errorMsg = "Failed to obtain the padding algorithm. It is not set in ParamSet.",
213 .data = NULL
214 }
215 }, {
216 .innerErrCode = HKS_ERROR_CHECK_GET_PURPOSE_FAIL,
217 .hksResult = {
218 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
219 .errorMsg = "Failed to obtain the key purpose. It is not set in ParamSet.",
220 .data = NULL
221 }
222 }, {
223 .innerErrCode = HKS_ERROR_CHECK_GET_DIGEST_FAIL,
224 .hksResult = {
225 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
226 .errorMsg = "Failed to obtain the digest algorithm. It is not set in ParamSet.",
227 .data = NULL
228 }
229 }, {
230 .innerErrCode = HKS_ERROR_CHECK_GET_MODE_FAIL,
231 .hksResult = {
232 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
233 .errorMsg = "Failed to obtain the cipher mode. It is not set in ParamSet.",
234 .data = NULL
235 }
236 }, {
237 .innerErrCode = HKS_ERROR_CHECK_GET_NONCE_FAIL,
238 .hksResult = {
239 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
240 .errorMsg = "Failed to obtain the nonce. It is not set in ParamSet.",
241 .data = NULL
242 }
243 }, {
244 .innerErrCode = HKS_ERROR_CHECK_GET_AAD_FAIL,
245 .hksResult = {
246 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
247 .errorMsg = "Failed to obtain the AAD. It is not set in ParamSet.",
248 .data = NULL
249 }
250 }, {
251 .innerErrCode = HKS_ERROR_CHECK_GET_IV_FAIL,
252 .hksResult = {
253 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
254 .errorMsg = "Failed to obtain the IV. It is not set in ParamSet.",
255 .data = NULL
256 }
257 }, {
258 .innerErrCode = HKS_ERROR_CHECK_GET_AE_TAG_FAIL,
259 .hksResult = {
260 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
261 .errorMsg = "Failed to obtain the AEAD. It is not set in ParamSet.",
262 .data = NULL
263 }
264 }, {
265 .innerErrCode = HKS_ERROR_CHECK_GET_SALT_FAIL,
266 .hksResult = {
267 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
268 .errorMsg = "Failed to obtain the salt value. It is not set in ParamSet.",
269 .data = NULL
270 }
271 }, {
272 .innerErrCode = HKS_ERROR_CHECK_GET_ITERATION_FAIL,
273 .hksResult = {
274 .errorCode = HUKS_ERR_CODE_MISSING_CRYPTO_ALG_ARGUMENT,
275 .errorMsg = "Failed to obtain the number of iterations. It is not set in ParamSet.",
276 .data = NULL
277 }
278 }, {
279 .innerErrCode = HKS_ERROR_INVALID_ALGORITHM,
280 .hksResult = {
281 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
282 .errorMsg = "Invalid algorithm.",
283 .data = NULL
284 }
285 }, {
286 .innerErrCode = HKS_ERROR_INVALID_KEY_SIZE,
287 .hksResult = {
288 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
289 .errorMsg = "Invalid key size.",
290 .data = NULL
291 }
292 }, {
293 .innerErrCode = HKS_ERROR_INVALID_PADDING,
294 .hksResult = {
295 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
296 .errorMsg = "Invalid padding algorithm.",
297 .data = NULL
298 }
299 }, {
300 .innerErrCode = HKS_ERROR_INVALID_PURPOSE,
301 .hksResult = {
302 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
303 .errorMsg = "Invalid key purpose.",
304 .data = NULL
305 }
306 }, {
307 .innerErrCode = HKS_ERROR_INVALID_MODE,
308 .hksResult = {
309 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
310 .errorMsg = "Invalid cipher mode.",
311 .data = NULL
312 }
313 }, {
314 .innerErrCode = HKS_ERROR_INVALID_DIGEST,
315 .hksResult = {
316 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
317 .errorMsg = "Invalid digest algorithm.",
318 .data = NULL
319 }
320 }, {
321 .innerErrCode = HKS_ERROR_INVALID_SIGNATURE_SIZE,
322 .hksResult = {
323 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
324 .errorMsg = "Invalid signature size.",
325 .data = NULL
326 }
327 }, {
328 .innerErrCode = HKS_ERROR_INVALID_IV,
329 .hksResult = {
330 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
331 .errorMsg = "Invalid IV.",
332 .data = NULL
333 }
334 }, {
335 .innerErrCode = HKS_ERROR_INVALID_AAD,
336 .hksResult = {
337 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
338 .errorMsg = "Invalid AAD.",
339 .data = NULL
340 }
341 }, {
342 .innerErrCode = HKS_ERROR_INVALID_NONCE,
343 .hksResult = {
344 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
345 .errorMsg = "Invalid nonce.",
346 .data = NULL
347 }
348 }, {
349 .innerErrCode = HKS_ERROR_INVALID_AE_TAG,
350 .hksResult = {
351 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
352 .errorMsg = "Invalid AE.",
353 .data = NULL
354 }
355 }, {
356 .innerErrCode = HKS_ERROR_INVALID_SALT,
357 .hksResult = {
358 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
359 .errorMsg = "Invalid salt value.",
360 .data = NULL
361 }
362 }, {
363 .innerErrCode = HKS_ERROR_INVALID_ITERATION,
364 .hksResult = {
365 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
366 .errorMsg = "Invalid iteration count.",
367 .data = NULL
368 }
369 }, {
370 .innerErrCode = HKS_ERROR_INVALID_USAGE_OF_KEY,
371 .hksResult = {
372 .errorCode = HUKS_ERR_CODE_INVALID_CRYPTO_ALG_ARGUMENT,
373 .errorMsg = "Invalid key purpose.",
374 .data = NULL
375 }
376 }, {
377 .innerErrCode = HKS_ERROR_STORAGE_FAILURE,
378 .hksResult = {
379 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
380 .errorMsg = "Insufficient storage space.",
381 .data = NULL
382 }
383 }, {
384 .innerErrCode = HKS_ERROR_FILE_SIZE_FAIL,
385 .hksResult = {
386 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
387 .errorMsg = "Invalid file size.",
388 .data = NULL
389 }
390 }, {
391 .innerErrCode = HKS_ERROR_READ_FILE_FAIL,
392 .hksResult = {
393 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
394 .errorMsg = "Failed to read the file.",
395 .data = NULL
396 }
397 }, {
398 .innerErrCode = HKS_ERROR_WRITE_FILE_FAIL,
399 .hksResult = {
400 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
401 .errorMsg = "Failed to write the file.",
402 .data = NULL
403 }
404 }, {
405 .innerErrCode = HKS_ERROR_REMOVE_FILE_FAIL,
406 .hksResult = {
407 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
408 .errorMsg = "Failed to remove the file.",
409 .data = NULL
410 }
411 }, {
412 .innerErrCode = HKS_ERROR_OPEN_FILE_FAIL,
413 .hksResult = {
414 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
415 .errorMsg = "Failed to open the file.",
416 .data = NULL
417 }
418 }, {
419 .innerErrCode = HKS_ERROR_CLOSE_FILE_FAIL,
420 .hksResult = {
421 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
422 .errorMsg = "Failed to close the file.",
423 .data = NULL
424 }
425 }, {
426 .innerErrCode = HKS_ERROR_MAKE_DIR_FAIL,
427 .hksResult = {
428 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
429 .errorMsg = "Failed to create the directory.",
430 .data = NULL
431 }
432 }, {
433 .innerErrCode = HKS_ERROR_INVALID_KEY_FILE,
434 .hksResult = {
435 .errorCode = HUKS_ERR_CODE_FILE_OPERATION_FAIL,
436 .errorMsg = "Failed to read the key from an invalid key file.",
437 .data = NULL
438 }
439 }, {
440 .innerErrCode = HKS_ERROR_IPC_MSG_FAIL,
441 .hksResult = {
442 .errorCode = HUKS_ERR_CODE_COMMUNICATION_FAIL,
443 .errorMsg = "Failed to get message from IPC.",
444 .data = NULL
445 }
446 }, {
447 .innerErrCode = HKS_ERROR_COMMUNICATION_TIMEOUT,
448 .hksResult = {
449 .errorCode = HUKS_ERR_CODE_COMMUNICATION_FAIL,
450 .errorMsg = "IPC timed out.",
451 .data = NULL
452 }
453 }, {
454 .innerErrCode = HKS_ERROR_IPC_INIT_FAIL,
455 .hksResult = {
456 .errorCode = HUKS_ERR_CODE_COMMUNICATION_FAIL,
457 .errorMsg = "IPC initialization failed.",
458 .data = NULL
459 }
460 }, {
461 .innerErrCode = HKS_ERROR_UNKNOWN_ERROR,
462 .hksResult = {
463 .errorCode = HUKS_ERR_CODE_COMMUNICATION_FAIL,
464 .errorMsg = "IPC async call failed.",
465 .data = NULL
466 }
467 }, {
468 .innerErrCode = HKS_ERROR_CRYPTO_ENGINE_ERROR,
469 .hksResult = {
470 .errorCode = HUKS_ERR_CODE_CRYPTO_FAIL,
471 .errorMsg = "Crypto engine error.",
472 .data = NULL
473 }
474 }, {
475 .innerErrCode = HKS_ERROR_KEY_AUTH_PERMANENTLY_INVALIDATED,
476 .hksResult = {
477 .errorCode = HUKS_ERR_CODE_KEY_AUTH_PERMANENTLY_INVALIDATED,
478 .errorMsg = "This credential is invalidated permanently.",
479 .data = NULL
480 }
481 }, {
482 .innerErrCode = HKS_ERROR_KEY_AUTH_VERIFY_FAILED,
483 .hksResult = {
484 .errorCode = HUKS_ERR_CODE_KEY_AUTH_VERIFY_FAILED,
485 .errorMsg = "The authentication token verification failed.",
486 .data = NULL
487 }
488 }, {
489 .innerErrCode = HKS_ERROR_KEY_AUTH_TIME_OUT,
490 .hksResult = {
491 .errorCode = HUKS_ERR_CODE_KEY_AUTH_TIME_OUT,
492 .errorMsg = "This authentication token timed out.",
493 .data = NULL
494 }
495 }, {
496 .innerErrCode = HKS_ERROR_SESSION_REACHED_LIMIT,
497 .hksResult = {
498 .errorCode = HUKS_ERR_CODE_SESSION_LIMIT,
499 .errorMsg = "The number of key operation sessions has reached the limit.",
500 .data = NULL
501 }
502 }, {
503 .innerErrCode = HKS_ERROR_NOT_EXIST,
504 .hksResult = {
505 .errorCode = HUKS_ERR_CODE_ITEM_NOT_EXIST,
506 .errorMsg = "The entity does not exist.",
507 .data = NULL
508 }
509 }, {
510 .innerErrCode = HKS_FAILURE,
511 .hksResult = {
512 .errorCode = HUKS_ERR_CODE_EXTERNAL_ERROR,
513 .errorMsg = "System external error.",
514 .data = NULL
515 }
516 }, {
517 .innerErrCode = HKS_ERROR_BAD_STATE,
518 .hksResult = {
519 .errorCode = HUKS_ERR_CODE_EXTERNAL_ERROR,
520 .errorMsg = "System external error.",
521 .data = NULL
522 }
523 }, {
524 .innerErrCode = HKS_ERROR_INTERNAL_ERROR,
525 .hksResult = {
526 .errorCode = HUKS_ERR_CODE_EXTERNAL_ERROR,
527 .errorMsg = "System external error.",
528 .data = NULL
529 }
530 }, {
531 .innerErrCode = HKS_ERROR_CREDENTIAL_NOT_EXIST,
532 .hksResult = {
533 .errorCode = HUKS_ERR_CODE_CREDENTIAL_NOT_EXIST,
534 .errorMsg = "The credential does not exist.",
535 .data = NULL
536 }
537 }, {
538 .innerErrCode = HKS_ERROR_INSUFFICIENT_MEMORY,
539 .hksResult = {
540 .errorCode = HUKS_ERR_CODE_INSUFFICIENT_MEMORY,
541 .errorMsg = "Insufficient memory.",
542 .data = NULL
543 }
544 }, {
545 .innerErrCode = HKS_ERROR_MALLOC_FAIL,
546 .hksResult = {
547 .errorCode = HUKS_ERR_CODE_INSUFFICIENT_MEMORY,
548 .errorMsg = "Malloc failed.",
549 .data = NULL
550 }
551 }, {
552 .innerErrCode = HKS_ERROR_GET_USERIAM_SECINFO_FAILED,
553 .hksResult = {
554 .errorCode = HUKS_ERR_CODE_CALL_SERVICE_FAILED,
555 .errorMsg = "Failed to obtain the security information via UserIAM.",
556 .data = NULL
557 }
558 }, {
559 .innerErrCode = HKS_ERROR_GET_USERIAM_AUTHINFO_FAILED,
560 .hksResult = {
561 .errorCode = HUKS_ERR_CODE_CALL_SERVICE_FAILED,
562 .errorMsg = "Failed to obtain the authentication information via UserIAM.",
563 .data = NULL
564 }
565 }
566 };
567
568 /**
569 * Convert ErrCode.
570 * Convert internal error code to formal error code and return.
571 * Return HUKS_ERR_CODE_EXTERNAL_ERROR in case of converting failed.
572 */
HksConvertErrCode(int32_t ret)573 struct HksResult HksConvertErrCode(int32_t ret)
574 {
575 struct HksResult result = {HUKS_ERR_CODE_EXTERNAL_ERROR, g_convertErrMsg, NULL};
576 uint32_t i = 0;
577 uint32_t uErrCodeCount = sizeof(g_errCodeTable) / sizeof(g_errCodeTable[0]);
578 for (; i < uErrCodeCount; ++i) {
579 if (ret == g_errCodeTable[i].innerErrCode) {
580 return g_errCodeTable[i].hksResult;
581 }
582 }
583 HKS_LOG_E("convert error code form %" LOG_PUBLIC "d failed!", ret);
584 return result;
585 }
586
587