16ea96550Sopenharmony_ci/* 26ea96550Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 36ea96550Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 46ea96550Sopenharmony_ci * you may not use this file except in compliance with the License. 56ea96550Sopenharmony_ci * You may obtain a copy of the License at 66ea96550Sopenharmony_ci * 76ea96550Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 86ea96550Sopenharmony_ci * 96ea96550Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 106ea96550Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 116ea96550Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 126ea96550Sopenharmony_ci * See the License for the specific language governing permissions and 136ea96550Sopenharmony_ci * limitations under the License. 146ea96550Sopenharmony_ci */ 156ea96550Sopenharmony_ci 166ea96550Sopenharmony_ci#include "base_config.h" 176ea96550Sopenharmony_ci 186ea96550Sopenharmony_ci#include "nlohmann/json.hpp" 196ea96550Sopenharmony_ci 206ea96550Sopenharmony_ci#include "security_guard_log.h" 216ea96550Sopenharmony_ci 226ea96550Sopenharmony_cinamespace OHOS::Security::SecurityGuard { 236ea96550Sopenharmony_cinamespace { 246ea96550Sopenharmony_ci constexpr int32_t CFG_FILE_MAX_SIZE = 1 * 1024 * 1024; // byte 256ea96550Sopenharmony_ci} 266ea96550Sopenharmony_ci 276ea96550Sopenharmony_cibool BaseConfig::Check() 286ea96550Sopenharmony_ci{ 296ea96550Sopenharmony_ci if (!stream_.is_open()) { 306ea96550Sopenharmony_ci SGLOGE("stream error"); 316ea96550Sopenharmony_ci return false; 326ea96550Sopenharmony_ci } 336ea96550Sopenharmony_ci 346ea96550Sopenharmony_ci stream_.seekg(0, std::ios::end); 356ea96550Sopenharmony_ci std::ios::pos_type len = stream_.tellg(); 366ea96550Sopenharmony_ci if (len == 0 || len > CFG_FILE_MAX_SIZE) { 376ea96550Sopenharmony_ci SGLOGE("stream is empty or too large"); 386ea96550Sopenharmony_ci stream_.close(); 396ea96550Sopenharmony_ci return false; 406ea96550Sopenharmony_ci } 416ea96550Sopenharmony_ci stream_.seekg(0, std::ios::beg); 426ea96550Sopenharmony_ci return true; 436ea96550Sopenharmony_ci} 446ea96550Sopenharmony_ci 456ea96550Sopenharmony_ciBaseConfig::~BaseConfig() 466ea96550Sopenharmony_ci{ 476ea96550Sopenharmony_ci if (stream_.is_open()) { 486ea96550Sopenharmony_ci stream_.close(); 496ea96550Sopenharmony_ci } 506ea96550Sopenharmony_ci} 516ea96550Sopenharmony_ci} // OHOS::Security::SecurityGuard 52