1fc0b0055Sopenharmony_ci/* 2fc0b0055Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3fc0b0055Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fc0b0055Sopenharmony_ci * you may not use this file except in compliance with the License. 5fc0b0055Sopenharmony_ci * You may obtain a copy of the License at 6fc0b0055Sopenharmony_ci * 7fc0b0055Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fc0b0055Sopenharmony_ci * 9fc0b0055Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fc0b0055Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fc0b0055Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fc0b0055Sopenharmony_ci * See the License for the specific language governing permissions and 13fc0b0055Sopenharmony_ci * limitations under the License. 14fc0b0055Sopenharmony_ci */ 15fc0b0055Sopenharmony_ci 16fc0b0055Sopenharmony_ci#include "constant_common.h" 17fc0b0055Sopenharmony_ci#include <string> 18fc0b0055Sopenharmony_ci#include "parameter.h" 19fc0b0055Sopenharmony_ci 20fc0b0055Sopenharmony_cinamespace OHOS { 21fc0b0055Sopenharmony_cinamespace Security { 22fc0b0055Sopenharmony_cinamespace AccessToken { 23fc0b0055Sopenharmony_cinamespace { 24fc0b0055Sopenharmony_ciconstexpr const char* REPLACE_TARGET = "****"; 25fc0b0055Sopenharmony_ciconstexpr const char* REPLACE_TARGET_LESS_THAN_MINLEN = "*******"; 26fc0b0055Sopenharmony_ci} // namespace 27fc0b0055Sopenharmony_cistd::string ConstantCommon::EncryptDevId(std::string deviceId) 28fc0b0055Sopenharmony_ci{ 29fc0b0055Sopenharmony_ci std::string result = deviceId; 30fc0b0055Sopenharmony_ci if (deviceId.empty()) { 31fc0b0055Sopenharmony_ci return result; 32fc0b0055Sopenharmony_ci } 33fc0b0055Sopenharmony_ci if (deviceId.size() > MINDEVICEIDLEN) { 34fc0b0055Sopenharmony_ci result.replace(ENCRYPTBEGIN + ENCRYPTLEN, deviceId.size() - MINDEVICEIDLEN, REPLACE_TARGET); 35fc0b0055Sopenharmony_ci } else { 36fc0b0055Sopenharmony_ci result.replace(ENCRYPTBEGIN + 1, deviceId.size()-1, REPLACE_TARGET_LESS_THAN_MINLEN); 37fc0b0055Sopenharmony_ci } 38fc0b0055Sopenharmony_ci return result; 39fc0b0055Sopenharmony_ci} 40fc0b0055Sopenharmony_ci 41fc0b0055Sopenharmony_cistd::string ConstantCommon::GetLocalDeviceId() 42fc0b0055Sopenharmony_ci{ 43fc0b0055Sopenharmony_ci static std::string localDeviceId; 44fc0b0055Sopenharmony_ci if (!localDeviceId.empty()) { 45fc0b0055Sopenharmony_ci return localDeviceId; 46fc0b0055Sopenharmony_ci } 47fc0b0055Sopenharmony_ci const int32_t DEVICE_UUID_LENGTH = 65; 48fc0b0055Sopenharmony_ci char udid[DEVICE_UUID_LENGTH] = {0}; 49fc0b0055Sopenharmony_ci if (GetDevUdid(udid, DEVICE_UUID_LENGTH) == 0) { 50fc0b0055Sopenharmony_ci localDeviceId = udid; 51fc0b0055Sopenharmony_ci } 52fc0b0055Sopenharmony_ci return localDeviceId; 53fc0b0055Sopenharmony_ci} 54fc0b0055Sopenharmony_ci} // namespace AccessToken 55fc0b0055Sopenharmony_ci} // namespace Security 56fc0b0055Sopenharmony_ci} // namespace OHOS