• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 #ifndef ASSET_NAPI_ERROR_CODE_H
17 #define ASSET_NAPI_ERROR_CODE_H
18 
19 #include <cstdint>
20 #include <unordered_map>
21 
22 #include "asset_system_type.h"
23 
24 namespace OHOS {
25 namespace Security {
26 namespace Asset {
27 
28 const std::unordered_map<int32_t, const char *> ERR_MSGS = {
29     { SEC_ASSET_SUCCESS, "The operation is successful." },
30     { SEC_ASSET_PERMISSION_DENIED, "The caller doesn't have the permission." },
31     { SEC_ASSET_NOT_SYSTEM_APPLICATION, "Non-system applications use system APIs." },
32     { SEC_ASSET_INVALID_ARGUMENT, "The argument is invalid." },
33     { SEC_ASSET_SERVICE_UNAVAILABLE, "The ASSET service is unavailable." },
34     { SEC_ASSET_NOT_FOUND, "The asset is not found." },
35     { SEC_ASSET_DUPLICATED, "The asset already exists." },
36     { SEC_ASSET_ACCESS_DENIED, "Access to the asset is denied." },
37     { SEC_ASSET_STATUS_MISMATCH, "The screen lock status does not match." },
38     { SEC_ASSET_OUT_OF_MEMORY, "Insufficient memory." },
39     { SEC_ASSET_DATA_CORRUPTED, "The asset is corrupted." },
40     { SEC_ASSET_DATABASE_ERROR, "The database operation failed." },
41     { SEC_ASSET_CRYPTO_ERROR, "The cryptography operation failed." },
42     { SEC_ASSET_IPC_ERROR, "IPC failed." },
43     { SEC_ASSET_BMS_ERROR, "Calling the Bundle Manager service failed." },
44     { SEC_ASSET_ACCOUNT_ERROR, "Calling the OS Account service failed." },
45     { SEC_ASSET_ACCESS_TOKEN_ERROR, "Calling the Access Token service failed." },
46     { SEC_ASSET_FILE_OPERATION_ERROR, "The file operation failed." },
47     { SEC_ASSET_GET_SYSTEM_TIME_ERROR, "Getting the system time failed." },
48     { SEC_ASSET_LIMIT_EXCEEDED, "The cache exceeds the limit." },
49     { SEC_ASSET_UNSUPPORTED, "The capability is not supported." },
50     { SEC_ASSET_PARAM_VERIFICATION_FAILED, "Parameter verification failed." },
51 };
52 
GetErrorMessage(int32_t errCode)53 inline const char *GetErrorMessage(int32_t errCode)
54 {
55     auto iter = ERR_MSGS.find(errCode);
56     if (iter == ERR_MSGS.end()) {
57         return "";
58     }
59     return ERR_MSGS.at(errCode);
60 }
61 
62 } // Asset
63 } // Security
64 } // OHOS
65 
66 #endif // ASSET_NAPI_ERROR_CODE_H