• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "metadata/secret_key_meta_data.h"
16 
17 #include "utils/constant.h"
18 namespace OHOS {
19 namespace DistributedData {
SecretKeyMetaData()20 SecretKeyMetaData::SecretKeyMetaData()
21 {
22 }
23 
~SecretKeyMetaData()24 SecretKeyMetaData::~SecretKeyMetaData()
25 {
26     sKey.assign(sKey.size(), 0);
27 }
28 
Marshal(json & node) const29 bool SecretKeyMetaData::Marshal(json &node) const
30 {
31     SetValue(node[GET_NAME(time)], time);
32     SetValue(node[GET_NAME(sKey)], sKey);
33     SetValue(node[GET_NAME(storeType)], storeType);
34     SetValue(node[GET_NAME(area)], area);
35     return true;
36 }
37 
Unmarshal(const json & node)38 bool SecretKeyMetaData::Unmarshal(const json &node)
39 {
40     GetValue(node, GET_NAME(time), time);
41     GetValue(node, GET_NAME(sKey), sKey);
42     GetValue(node, GET_NAME(storeType), storeType);
43     GetValue(node, GET_NAME(area), area);
44     return true;
45 }
46 
GetKey(const std::initializer_list<std::string> & fields)47 std::string SecretKeyMetaData::GetKey(const std::initializer_list<std::string> &fields)
48 {
49     std::string prefix = GetPrefix(fields);
50     prefix.append("SINGLE_KEY");
51     return prefix;
52 }
53 
GetBackupKey(const std::initializer_list<std::string> & fields)54 std::string SecretKeyMetaData::GetBackupKey(const std::initializer_list<std::string> &fields)
55 {
56     std::string prefix = GetBackupPrefix(fields);
57     return prefix;
58 }
59 
GetPrefix(const std::initializer_list<std::string> & fields)60 std::string SecretKeyMetaData::GetPrefix(const std::initializer_list<std::string> &fields)
61 {
62     std::string prefix = KEY_PREFIX;
63     for (const auto &field : fields) {
64         prefix.append(Constant::KEY_SEPARATOR).append(field);
65     }
66     prefix.append(Constant::KEY_SEPARATOR);
67     return prefix;
68 }
69 
GetBackupPrefix(const std::initializer_list<std::string> & fields)70 std::string SecretKeyMetaData::GetBackupPrefix(const std::initializer_list<std::string> &fields)
71 {
72     std::string prefix = BACKUP_KEY_PREFIX;
73     for (const auto &field : fields) {
74         prefix.append(Constant::KEY_SEPARATOR).append(field);
75     }
76     prefix.append(Constant::KEY_SEPARATOR);
77     return prefix;
78 }
79 
GetCloneKey(const std::initializer_list<std::string> & fields)80 std::string SecretKeyMetaData::GetCloneKey(const std::initializer_list<std::string> &fields)
81 {
82     std::string prefix = CLONE_KEY_PREFIX;
83     prefix.append(Constant::KEY_SEPARATOR).append(GetKey(fields));
84     return prefix;
85 }
86 } // namespace DistributedData
87 } // namespace OHOS
88