14f7ff21fSopenharmony_ci/* 24f7ff21fSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 34f7ff21fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44f7ff21fSopenharmony_ci * you may not use this file except in compliance with the License. 54f7ff21fSopenharmony_ci * You may obtain a copy of the License at 64f7ff21fSopenharmony_ci * 74f7ff21fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84f7ff21fSopenharmony_ci * 94f7ff21fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104f7ff21fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114f7ff21fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124f7ff21fSopenharmony_ci * See the License for the specific language governing permissions and 134f7ff21fSopenharmony_ci * limitations under the License. 144f7ff21fSopenharmony_ci */ 154f7ff21fSopenharmony_ci 164f7ff21fSopenharmony_ci#ifndef IAM_PARA2STR_H 174f7ff21fSopenharmony_ci#define IAM_PARA2STR_H 184f7ff21fSopenharmony_ci 194f7ff21fSopenharmony_ci#include <iomanip> 204f7ff21fSopenharmony_ci#include <map> 214f7ff21fSopenharmony_ci#include <sstream> 224f7ff21fSopenharmony_ci#include <string> 234f7ff21fSopenharmony_ci 244f7ff21fSopenharmony_cinamespace OHOS { 254f7ff21fSopenharmony_cinamespace UserIam { 264f7ff21fSopenharmony_cinamespace Common { 274f7ff21fSopenharmony_ciusing namespace std; 284f7ff21fSopenharmony_ciconst int32_t MASK_WIDTH = 4; 294f7ff21fSopenharmony_cistatic inline std::string GetMaskedString(uint16_t val) 304f7ff21fSopenharmony_ci{ 314f7ff21fSopenharmony_ci std::ostringstream ss; 324f7ff21fSopenharmony_ci ss << "0xXXXX" << std::setfill('0') << std::setw(MASK_WIDTH) << std::hex << val; 334f7ff21fSopenharmony_ci return ss.str(); 344f7ff21fSopenharmony_ci} 354f7ff21fSopenharmony_ci 364f7ff21fSopenharmony_ci#define GET_MASKED_STRING(val) OHOS::UserIam::Common::GetMaskedString(static_cast<uint16_t>(val)) 374f7ff21fSopenharmony_ci 384f7ff21fSopenharmony_cistatic inline std::string GetPointerNullStateString(void *p) 394f7ff21fSopenharmony_ci{ 404f7ff21fSopenharmony_ci return p == nullptr ? "null" : "non-null"; 414f7ff21fSopenharmony_ci} 424f7ff21fSopenharmony_ci 434f7ff21fSopenharmony_cistatic inline const char *AuthTypeToStr(uint32_t authType) 444f7ff21fSopenharmony_ci{ 454f7ff21fSopenharmony_ci static std::map<uint32_t, std::string> typeNames = { { 0, "All" }, { 1, "Pin" }, { 2, "Face" }, 464f7ff21fSopenharmony_ci { 4, "Fingerprint" } }; 474f7ff21fSopenharmony_ci if (auto iter = typeNames.find(authType); iter != typeNames.end()) { 484f7ff21fSopenharmony_ci return iter->second.c_str(); 494f7ff21fSopenharmony_ci } 504f7ff21fSopenharmony_ci return "unknown"; 514f7ff21fSopenharmony_ci} 524f7ff21fSopenharmony_ci} // namespace Common 534f7ff21fSopenharmony_ci} // namespace UserIam 544f7ff21fSopenharmony_ci} // namespace OHOS 554f7ff21fSopenharmony_ci 564f7ff21fSopenharmony_ci#endif // IAM_PARA2STR_H 57