• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 DATA_VALIDATOR_H
17 #define DATA_VALIDATOR_H
18 
19 #include <map>
20 #include <string>
21 #include "access_token.h"
22 
23 namespace OHOS {
24 namespace Security {
25 namespace AccessToken {
26 class DataValidator final {
27 public:
28     static bool IsBundleNameValid(const std::string& bundleName);
29 
30     static bool IsPermissionNameValid(const std::string& permissionName);
31 
32     static bool IsUserIdValid(const int userId);
33 
34     static bool IsToggleStatusValid(const uint32_t status);
35 
36     static bool IsAppIDDescValid(const std::string& appIDDesc);
37 
38     static bool IsDomainValid(const std::string& domain);
39 
40     static bool IsAplNumValid(const int apl);
41 
42     static bool IsAvailableTypeValid(const int availableType);
43 
44     static bool IsProcessNameValid(const std::string& processName);
45 
46     static bool IsDeviceIdValid(const std::string& deviceId);
47 
48     static bool IsLabelValid(const std::string& label);
49 
50     static bool IsDescValid(const std::string& desc);
51     static bool IsPermissionFlagValid(uint32_t flag);
52     static bool IsPermissionFlagValidForAdmin(uint32_t flag);
53     static bool IsPermissionStatusValid(int32_t status);
54     static bool IsDcapValid(const std::string& dcap);
55     static bool IsTokenIDValid(AccessTokenID id);
56     static bool IsDlpTypeValid(int dlpType);
57     static bool IsPermissionUsedFlagValid(uint32_t flag);
58     static bool IsPermissionUsedTypeValid(uint32_t type);
59     static bool IsPolicyTypeValid(uint32_t type);
60     static bool IsCallerTypeValid(uint32_t type);
61     static bool IsNativeCaller(AccessTokenID id);
62     static bool IsHapCaller(AccessTokenID id);
63     static bool IsAclExtendedMapSizeValid(const std::map<std::string, std::string>& aclExtendedMap);
64     static bool IsAclExtendedMapContentValid(const std::string& permissionName, const std::string& value);
65     static bool IsPermissionListSizeValid(const std::vector<std::string>& permissionList);
66 
67 private:
68     const static int MAX_LENGTH = 256;
69     const static int MAX_APPIDDESC_LENGTH = 10240;
70     const static int MAX_DCAP_LENGTH = 1024;
71     const static int32_t MAX_EXTENDED_MAP_SIZE = 512;
72     const static int32_t MAX_VALUE_LENGTH = 1024;
73     const static int32_t MAX_PERMISSION_LIST_SIZE = 1024;
74 };
75 } // namespace AccessToken
76 } // namespace Security
77 } // namespace OHOS
78 #endif // DATA_VALIDATOR_H
79