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 OHOS_MEDIALIBRARY_COMMON_UTILS_H 17 #define OHOS_MEDIALIBRARY_COMMON_UTILS_H 18 19 #include <cstddef> 20 #include <cstdint> 21 #include <string> 22 #include <vector> 23 24 namespace OHOS { 25 namespace Media { 26 #define COMPILE_HIDDEN __attribute__ ((visibility ("hidden"))) 27 class MediaLibraryCommonUtils { 28 public: 29 static int32_t GenKeySHA256(const std::vector<uint8_t> &input, std::string &key); 30 static int32_t GenKeySHA256(const std::string &input, std::string &key); 31 static bool CheckWhereClause(const std::string &whereClause); 32 static void AppendSelections(std::string &selections); 33 static bool CanConvertStrToInt32(const std::string &str); 34 private: 35 COMPILE_HIDDEN MediaLibraryCommonUtils() = delete; 36 COMPILE_HIDDEN ~MediaLibraryCommonUtils() = delete; 37 38 static void Char2Hex(const unsigned char *data, const size_t len, std::string &hexStr); 39 static int32_t GenKey(const unsigned char *data, const size_t len, std::string &key); 40 static bool CheckIllegalCharacter(const std::string &strCondition); 41 static bool CheckKeyWord(const std::string &strCondition); 42 static void SeprateSelection(std::string &strCondition, std::vector<std::string> &sepratedStr); 43 static bool CheckExpressValidation(std::vector<std::string> &sepratedStr); 44 static bool CheckWhiteList(const std::string &express); 45 static void ExtractKeyWord(std::string &str); 46 static void RemoveSpecialCondition(std::string &hacker, const std::string &pattern); 47 static void RemoveSpecialCondition(std::string &hacker); 48 }; 49 } // namespace Media 50 } // namespace OHOS 51 #endif // OHOS_MEDIALIBRARY_COMMON_UTILS_H 52