1 /*
2  * Copyright (c) 2023 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 #ifndef SOFTBUS_SESSION_UTILS_H
17 #define SOFTBUS_SESSION_UTILS_H
18 
19 #include <string>
20 
21 namespace OHOS::AVSession {
22 class SoftbusSessionUtils {
23 public:
AnonymizeDeviceId(const std::string & deviceId)24     static std::string AnonymizeDeviceId(const std::string &deviceId)
25     {
26         if (deviceId == "") {
27             return "";
28         }
29         if (deviceId.length() <= DEVICE_ANONYMIZE_LENGTH) {
30             return std::string(DEVICE_ANONYMIZE_ID);
31         } else {
32             unsigned long index =
33                 std::min<unsigned long>(deviceId.length() - DEVICE_ANONYMIZE_LENGTH, DEVICE_ANONYMIZE_LENGTH);
34             std::string prefix = deviceId.substr(0, index);
35             std::string suffix = deviceId.substr(deviceId.length() - index, deviceId.length());
36             return prefix + std::string(DEVICE_ANONYMIZE_ID) + suffix;
37         }
38     }
39 
40 private:
41     static constexpr const char *DEVICE_ANONYMIZE_ID = "******";
42     static constexpr const int DEVICE_ANONYMIZE_LENGTH = 6;
43 };
44 } // namespace OHOS::AVSession
45 
46 #endif // SOFTBUS_SESSION_UTILS_H