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