1794c9f46Sopenharmony_ci/* 2794c9f46Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3794c9f46Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4794c9f46Sopenharmony_ci * you may not use this file except in compliance with the License. 5794c9f46Sopenharmony_ci * You may obtain a copy of the License at 6794c9f46Sopenharmony_ci * 7794c9f46Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8794c9f46Sopenharmony_ci * 9794c9f46Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10794c9f46Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11794c9f46Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12794c9f46Sopenharmony_ci * See the License for the specific language governing permissions and 13794c9f46Sopenharmony_ci * limitations under the License. 14794c9f46Sopenharmony_ci */ 15794c9f46Sopenharmony_ci 16794c9f46Sopenharmony_ci#ifndef OHOS_DISTRIBUTED_HARDWARE_DHUTILS_TOOL_H 17794c9f46Sopenharmony_ci#define OHOS_DISTRIBUTED_HARDWARE_DHUTILS_TOOL_H 18794c9f46Sopenharmony_ci 19794c9f46Sopenharmony_ci#include <cstdint> 20794c9f46Sopenharmony_ci 21794c9f46Sopenharmony_ci#include "cJSON.h" 22794c9f46Sopenharmony_ci 23794c9f46Sopenharmony_ci#include "device_type.h" 24794c9f46Sopenharmony_ci 25794c9f46Sopenharmony_cinamespace OHOS { 26794c9f46Sopenharmony_cinamespace DistributedHardware { 27794c9f46Sopenharmony_ci/** 28794c9f46Sopenharmony_ci * return current time in millisecond. 29794c9f46Sopenharmony_ci */ 30794c9f46Sopenharmony_ciint64_t GetCurrentTime(); 31794c9f46Sopenharmony_ci 32794c9f46Sopenharmony_ci/** 33794c9f46Sopenharmony_ci * return a random string id. 34794c9f46Sopenharmony_ci */ 35794c9f46Sopenharmony_cistd::string GetRandomID(); 36794c9f46Sopenharmony_ci 37794c9f46Sopenharmony_cistd::string GetUUIDByDm(const std::string &networkId); 38794c9f46Sopenharmony_ci 39794c9f46Sopenharmony_cistd::string GetUDIDByDm(const std::string &networkId); 40794c9f46Sopenharmony_ci 41794c9f46Sopenharmony_ciDeviceInfo GetLocalDeviceInfo(); 42794c9f46Sopenharmony_ci 43794c9f46Sopenharmony_cistd::string GetLocalNetworkId(); 44794c9f46Sopenharmony_ci 45794c9f46Sopenharmony_ci/* Convert uuid to deviceId by sha256 encode */ 46794c9f46Sopenharmony_cistd::string GetDeviceIdByUUID(const std::string &uuid); 47794c9f46Sopenharmony_ci 48794c9f46Sopenharmony_cistd::string Sha256(const std::string& string); 49794c9f46Sopenharmony_ci 50794c9f46Sopenharmony_cibool IsUInt8(const cJSON* jsonObj, const std::string& key); 51794c9f46Sopenharmony_ci 52794c9f46Sopenharmony_cibool IsUInt16(const cJSON* jsonObj, const std::string& key); 53794c9f46Sopenharmony_ci 54794c9f46Sopenharmony_cibool IsInt32(const cJSON* jsonObj, const std::string& key); 55794c9f46Sopenharmony_ci 56794c9f46Sopenharmony_cibool IsUInt32(const cJSON* jsonObj, const std::string& key); 57794c9f46Sopenharmony_ci 58794c9f46Sopenharmony_cibool IsBool(const cJSON* jsonObj, const std::string& key); 59794c9f46Sopenharmony_ci 60794c9f46Sopenharmony_cibool IsString(const cJSON* jsonObj, const std::string& key); 61794c9f46Sopenharmony_ci 62794c9f46Sopenharmony_cibool IsArray(const cJSON* jsonObj, const std::string& key); 63794c9f46Sopenharmony_ci 64794c9f46Sopenharmony_cistd::string Compress(const std::string& data); 65794c9f46Sopenharmony_cistd::string Decompress(const std::string& data); 66794c9f46Sopenharmony_ci 67794c9f46Sopenharmony_cibool GetSysPara(const char *key, bool &value); 68794c9f46Sopenharmony_ci 69794c9f46Sopenharmony_cibool IsIdLengthValid(const std::string &input); 70794c9f46Sopenharmony_ci 71794c9f46Sopenharmony_cibool IsMessageLengthValid(const std::string &input); 72794c9f46Sopenharmony_ci 73794c9f46Sopenharmony_cibool IsJsonLengthValid(const std::string &jsonStr); 74794c9f46Sopenharmony_ci 75794c9f46Sopenharmony_cibool IsArrayLengthValid(const std::vector<std::string> &array); 76794c9f46Sopenharmony_ci 77794c9f46Sopenharmony_cibool IsKeySizeValid(const std::string &key); 78794c9f46Sopenharmony_ci 79794c9f46Sopenharmony_cibool IsHashSizeValid(const std::string &hashValue); 80794c9f46Sopenharmony_ci 81794c9f46Sopenharmony_ciint32_t GetDeviceSystemType(const std::string &extraData); 82794c9f46Sopenharmony_ci} // namespace DistributedHardware 83794c9f46Sopenharmony_ci} // namespace OHOS 84794c9f46Sopenharmony_ci#endif 85