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 private:
34     COMPILE_HIDDEN MediaLibraryCommonUtils() = delete;
35     COMPILE_HIDDEN ~MediaLibraryCommonUtils() = delete;
36 
37     static void Char2Hex(const unsigned char *data, const size_t len, std::string &hexStr);
38     static int32_t GenKey(const unsigned char *data, const size_t len, std::string &key);
39     static bool CheckIllegalCharacter(const std::string &strCondition);
40     static bool CheckKeyWord(const std::string &strCondition);
41     static void SeprateSelection(std::string &strCondition, std::vector<std::string> &sepratedStr);
42     static bool CheckExpressValidation(std::vector<std::string> &sepratedStr);
43     static bool CheckWhiteList(const std::string &express);
44     static void ExtractKeyWord(std::string &str);
45     static void RemoveSpecialCondition(std::string &hacker, const std::string &pattern);
46     static void RemoveSpecialCondition(std::string &hacker);
47 };
48 } // namespace Media
49 } // namespace OHOS
50 #endif // OHOS_MEDIALIBRARY_COMMON_UTILS_H
51