1 /*
2 * Copyright (c) 2022 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
16 #include "constant_common.h"
17 #include <string>
18 #include "parameter.h"
19
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
23 namespace {
24 static const std::string REPLACE_TARGET = "****";
25 static const std::string REPLACE_TARGET_LESS_THAN_MINLEN = "*******";
26 } // namespace
EncryptDevId(std::string deviceId)27 std::string ConstantCommon::EncryptDevId(std::string deviceId)
28 {
29 std::string result = deviceId;
30 if (deviceId.empty()) {
31 return result;
32 }
33 if (deviceId.size() > MINDEVICEIDLEN) {
34 result.replace(ENCRYPTBEGIN + ENCRYPTLEN, deviceId.size() - MINDEVICEIDLEN, REPLACE_TARGET);
35 } else {
36 result.replace(ENCRYPTBEGIN + 1, deviceId.size()-1, REPLACE_TARGET_LESS_THAN_MINLEN);
37 }
38 return result;
39 }
40
GetLocalDeviceId()41 std::string ConstantCommon::GetLocalDeviceId()
42 {
43 static std::string localDeviceId;
44 if (!localDeviceId.empty()) {
45 return localDeviceId;
46 }
47 const int32_t DEVICE_UUID_LENGTH = 65;
48 char udid[DEVICE_UUID_LENGTH] = {0};
49 if (GetDevUdid(udid, DEVICE_UUID_LENGTH) == 0) {
50 localDeviceId = udid;
51 }
52 return localDeviceId;
53 }
54 } // namespace AccessToken
55 } // namespace Security
56 } // namespace OHOS