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