1 /*
2  * Copyright (c) 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 #include "dlp_utils.h"
17 #include <cctype>
18 #include <unistd.h>
19 #include "dlp_permission.h"
20 #include "dlp_permission_log.h"
21 
22 namespace OHOS {
23 namespace Security {
24 namespace DlpPermission {
25 
26 namespace {
27 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "DlpUtils"};
28 static const std::string DLP_FILE_SUFFIXS = ".dlp";
29 static const std::string DEFAULT_STRINGS = "";
30 }
31 
GetBundleMgrProxy(void)32 sptr<AppExecFwk::IBundleMgr> DlpUtils::GetBundleMgrProxy(void)
33 {
34     return nullptr;
35 }
36 
ToLowerString(const std::string & str)37 std::string DlpUtils::ToLowerString(const std::string& str)
38 {
39     std::string lower;
40     for (char c : str) {
41         lower += std::tolower(c);
42     }
43     return lower;
44 }
45 
GetWhitelistWithType(const std::string & cfgFile,const std::string & type,std::vector<std::string> & whitelist)46 bool DlpUtils::GetWhitelistWithType(const std::string &cfgFile, const std::string &type,
47     std::vector<std::string> &whitelist)
48 {
49     return false;
50 }
51 
GetFileTypeBySuffix(const std::string & suffix)52 std::string DlpUtils::GetFileTypeBySuffix(const std::string& suffix)
53 {
54     return "test.txt.dlp";
55 }
56 
GetDlpFileRealSuffix(const std::string & dlpFileName)57 std::string DlpUtils::GetDlpFileRealSuffix(const std::string& dlpFileName)
58 {
59     uint32_t dlpSuffixLen = DLP_FILE_SUFFIXS.size();
60     std::string realFileName = dlpFileName.substr(0, dlpFileName.size() - dlpSuffixLen);
61     char escape = '.';
62     std::size_t escapeLocate = realFileName.find_last_of(escape);
63     if (escapeLocate >= realFileName.size()) {
64         DLP_LOG_ERROR(LABEL, "Get file suffix fail, no '.' in file name");
65         return DEFAULT_STRINGS;
66     }
67 
68     return realFileName.substr(escapeLocate + 1);
69 }
70 
GetFileNameWithFd(const int32_t & fd,std::string & srcFileName)71 int32_t DlpUtils::GetFileNameWithFd(const int32_t &fd, std::string &srcFileName)
72 {
73     srcFileName = "test.txt.dlp";
74     return DLP_OK;
75 }
76 }  // namespace DlpPermission
77 }  // namespace Security
78 }  // namespace OHOS
79