1 /*
2 * Copyright (c) 2023 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 #define LOG_TAG "DataChecker"
16
17 #include "data_checker.h"
18
19 #include "utils/anonymous.h"
20 #include "log_print.h"
21
22 namespace OHOS {
23 namespace UDMF {
24 __attribute__((used)) DataChecker DataChecker::instance_;
DataChecker()25 DataChecker::DataChecker() noexcept
26 {
27 CheckerManager::GetInstance().RegisterChecker(
28 "DataChecker", [this]() -> auto { return this; });
29 }
30
~DataChecker()31 DataChecker::~DataChecker()
32 {
33 }
34
IsValid(const std::vector<Privilege> & privileges,const CheckerManager::CheckInfo & info)35 bool DataChecker::IsValid(const std::vector<Privilege> &privileges, const CheckerManager::CheckInfo &info)
36 {
37 for (const auto &privilege : privileges) {
38 if (privilege.tokenId == info.tokenId) {
39 return true;
40 }
41 }
42 ZLOGE("Invalid parameters, %{public}s", DistributedData::Anonymous::Change(std::to_string(info.tokenId)).c_str());
43 return false;
44 }
45 } // namespace UDMF
46 } // namespace OHOS