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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_MOCK_ACCESS_TOKEN_KIT_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_MOCK_ACCESS_TOKEN_KIT_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "access_token.h"
23 
24 namespace OHOS {
25 namespace Security {
26 namespace AccessToken {
27 class AccessTokenKit {
28 public:
29     static AccessTokenIDEx AllocHapToken(const HapInfoParams& info, const HapPolicyParams& policy);
30     static int DeleteToken(AccessTokenID tokenID);
31     /* Get token type by ATM service */
32     static ATokenTypeEnum GetTokenType(AccessTokenID tokenID);
33     /* Get token type from flag in tokenId, which doesn't depend on ATM service */
34     static ATokenTypeEnum GetTokenTypeFlag(AccessTokenID tokenID);
35     static int VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName);
36     static int VerifyAccessToken(
37         AccessTokenID callerTokenID, AccessTokenID firstTokenID, const std::string& permissionName);
38     static int GetDefPermission(const std::string& permissionName, PermissionDef& permissionDefResult);
39     static int GetDefPermissions(AccessTokenID tokenID, std::vector<PermissionDef>& permList);
40     static int GetReqPermissions(
41         AccessTokenID tokenID, std::vector<PermissionStateFull>& reqPermList, bool isSystemGrant);
42     static int GrantPermission(AccessTokenID tokenID, const std::string& permissionName, uint32_t flag);
43     static int ClearUserGrantedPermissionState(AccessTokenID tokenID);
44     static AccessTokenID GetHapTokenID(int userID, const std::string& bundleName, int instIndex);
45     static AccessTokenIDEx GetHapTokenIDEx(int userID, const std::string& bundleName, int instIndex);
46     static int GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfo &nativeTokenInfo);
47     static int32_t InitHapToken(const HapInfoParams& info, HapPolicyParams& policy, AccessTokenIDEx& fullTokenId);
48     static int32_t UpdateHapToken(
49         AccessTokenIDEx& tokenIdEx, const UpdateHapInfoParams& info, const HapPolicyParams& policy);
50 };
51 } // namespace AccessToken
52 } // namespace Security
53 } // namespace OHOS
54 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_KIT_H