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 <string> 20 #include "access_token.h" 21 22 namespace OHOS { 23 namespace Security { 24 namespace AccessToken { 25 class DataValidator final { 26 public: 27 static bool IsBundleNameValid(const std::string& bundleName); 28 29 static bool IsPermissionNameValid(const std::string& permissionName); 30 31 static bool IsUserIdValid(const int userId); 32 33 static bool IsToggleStatusValid(const uint32_t status); 34 35 static bool IsAppIDDescValid(const std::string& appIDDesc); 36 37 static bool IsDomainValid(const std::string& domain); 38 39 static bool IsAplNumValid(const int apl); 40 41 static bool IsAvailableTypeValid(const int availableType); 42 43 static bool IsProcessNameValid(const std::string& processName); 44 45 static bool IsDeviceIdValid(const std::string& deviceId); 46 47 static bool IsLabelValid(const std::string& label); 48 49 static bool IsDescValid(const std::string& desc); 50 static bool IsPermissionFlagValid(uint32_t flag); 51 static bool IsDcapValid(const std::string& dcap); 52 static bool IsTokenIDValid(AccessTokenID id); 53 static bool IsDlpTypeValid(int dlpType); 54 static bool IsPermissionUsedFlagValid(uint32_t flag); 55 static bool IsPermissionUsedTypeValid(uint32_t type); 56 static bool IsPolicyTypeValid(uint32_t type); 57 static bool IsCallerTypeValid(uint32_t type); 58 static bool IsHapCaller(AccessTokenID id); 59 60 private: 61 const static int MAX_LENGTH = 256; 62 const static int MAX_APPIDDESC_LENGTH = 10240; 63 const static int MAX_DCAP_LENGTH = 1024; 64 }; 65 } // namespace AccessToken 66 } // namespace Security 67 } // namespace OHOS 68 #endif // DATA_VALIDATOR_H 69