1 /*
2  * Copyright (c) 2023 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_UNSUPPORTED, "The capability is not supported." },
34     { SEC_ASSET_SERVICE_UNAVAILABLE, "The ASSET service is unavailable." },
35     { SEC_ASSET_NOT_FOUND, "The asset is not found." },
36     { SEC_ASSET_DUPLICATED, "The asset already exists." },
37     { SEC_ASSET_ACCESS_DENIED, "Access to the asset is denied." },
38     { SEC_ASSET_STATUS_MISMATCH, "The screen lock status does not match." },
39     { SEC_ASSET_OUT_OF_MEMORY, "Insufficient memory." },
40     { SEC_ASSET_DATA_CORRUPTED, "The asset is corrupted." },
41     { SEC_ASSET_DATABASE_ERROR, "The database operation failed." },
42     { SEC_ASSET_CRYPTO_ERROR, "The cryptography operation failed." },
43     { SEC_ASSET_IPC_ERROR, "IPC failed." },
44     { SEC_ASSET_BMS_ERROR, "Calling the Bundle Manager service failed." },
45     { SEC_ASSET_ACCOUNT_ERROR, "Calling the OS Account service failed." },
46     { SEC_ASSET_ACCESS_TOKEN_ERROR, "Calling the Access Token service failed." },
47     { SEC_ASSET_FILE_OPERATION_ERROR, "The file operation failed." },
48     { SEC_ASSET_GET_SYSTEM_TIME_ERROR, "Getting the system time failed." },
49     { SEC_ASSET_LIMIT_EXCEEDED, "The cache exceeds the limit." },
50 };
51 
GetErrorMessage(int32_t errCode)52 inline const char *GetErrorMessage(int32_t errCode)
53 {
54     auto iter = ERR_MSGS.find(errCode);
55     if (iter == ERR_MSGS.end()) {
56         return "";
57     }
58     return ERR_MSGS.at(errCode);
59 }
60 
61 } // Asset
62 } // Security
63 } // OHOS
64 
65 #endif // ASSET_NAPI_ERROR_CODE_H