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 IsDcapValid(const std::string& dcap); 53 static bool IsTokenIDValid(AccessTokenID id); 54 static bool IsDlpTypeValid(int dlpType); 55 static bool IsPermissionUsedFlagValid(uint32_t flag); 56 static bool IsPermissionUsedTypeValid(uint32_t type); 57 static bool IsPolicyTypeValid(uint32_t type); 58 static bool IsCallerTypeValid(uint32_t type); 59 static bool IsHapCaller(AccessTokenID id); 60 static bool IsAclExtendedMapSizeValid(const std::map<std::string, std::string>& aclExtendedMap); 61 static bool IsAclExtendedMapContentValid(const std::string& permissionName, const std::string& value); 62 63 private: 64 const static int MAX_LENGTH = 256; 65 const static int MAX_APPIDDESC_LENGTH = 10240; 66 const static int MAX_DCAP_LENGTH = 1024; 67 const static int32_t MAX_EXTENDED_MAP_SIZE = 512; 68 const static int32_t MAX_VALUE_LENGTH = 1024; 69 }; 70 } // namespace AccessToken 71 } // namespace Security 72 } // namespace OHOS 73 #endif // DATA_VALIDATOR_H 74