17418042dSoh_ci/* 27418042dSoh_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 37418042dSoh_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47418042dSoh_ci * you may not use this file except in compliance with the License. 57418042dSoh_ci * You may obtain a copy of the License at 67418042dSoh_ci * 77418042dSoh_ci * http://www.apache.org/licenses/LICENSE-2.0 87418042dSoh_ci * 97418042dSoh_ci * Unless required by applicable law or agreed to in writing, software 107418042dSoh_ci * distributed under the License is distributed on an "AS IS" BASIS, 117418042dSoh_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127418042dSoh_ci * See the License for the specific language governing permissions and 137418042dSoh_ci * limitations under the License. 147418042dSoh_ci */ 157418042dSoh_ci 167418042dSoh_ci#ifndef OHOS_OBJECTSTORE_ANONYMOUS_H 177418042dSoh_ci#define OHOS_OBJECTSTORE_ANONYMOUS_H 187418042dSoh_ci 197418042dSoh_ci#include <string> 207418042dSoh_ci 217418042dSoh_cinamespace OHOS { 227418042dSoh_cinamespace ObjectStore { 237418042dSoh_ciclass Anonymous { 247418042dSoh_cipublic: 257418042dSoh_ci static std::string Change(const std::string &data) 267418042dSoh_ci { 277418042dSoh_ci if (data.size() <= HEAD_SIZE) { 287418042dSoh_ci return DEFAULT_ANONYMOUS; 297418042dSoh_ci } 307418042dSoh_ci if (data.size() < MIN_SIZE) { 317418042dSoh_ci return (data.substr(0, HEAD_SIZE) + REPLACE_CHAIN); 327418042dSoh_ci } 337418042dSoh_ci return (data.substr(0, HEAD_SIZE) + REPLACE_CHAIN + data.substr(data.size() - END_SIZE, END_SIZE)); 347418042dSoh_ci } 357418042dSoh_ci 367418042dSoh_ciprivate: 377418042dSoh_ci static constexpr size_t HEAD_SIZE = 3; 387418042dSoh_ci static constexpr size_t END_SIZE = 3; 397418042dSoh_ci static constexpr size_t MIN_SIZE = HEAD_SIZE + END_SIZE + 3; 407418042dSoh_ci static constexpr const char *REPLACE_CHAIN = "***"; 417418042dSoh_ci static constexpr const char *DEFAULT_ANONYMOUS = "******"; 427418042dSoh_ci}; 437418042dSoh_ci} // namespace ObjectStore 447418042dSoh_ci} // namespace OHOS 457418042dSoh_ci#endif // OHOS_OBJECTSTORE_ANONYMOUS_H