• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "cloud_report_utils.h"
16 
17 namespace OHOS::Media::CloudSync {
GetAnonyString(const std::string & value)18 std::string ReportUtils::GetAnonyString(const std::string &value)
19 {
20     constexpr size_t INT32_SHORT_ID_LENGTH = 20;
21     constexpr size_t INT32_PLAINTEXT_LENGTH = 4;
22     constexpr size_t INT32_MIN_ID_LENGTH = 3;
23     std::string res;
24     std::string anonyStr("********");
25     size_t valueLen = value.length();
26     if (valueLen < INT32_MIN_ID_LENGTH) {
27         return anonyStr;
28     }
29 
30     if (valueLen <= INT32_SHORT_ID_LENGTH) {
31         res += value[0];
32         res += anonyStr;
33         res += value[valueLen - 1];
34         return res;
35     }
36 
37     res.append(value, 0, INT32_PLAINTEXT_LENGTH);
38     res += anonyStr;
39     res.append(value, INT32_PLAINTEXT_LENGTH + anonyStr.length(),
40         valueLen - INT32_PLAINTEXT_LENGTH - anonyStr.length());
41     return res;
42 }
43 } // namespace OHOS::Media::CloudSync