• 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     nonce.assign(nonce.size(), 0);
28 }
29 
Marshal(json & node) const30 bool SecretKeyMetaData::Marshal(json &node) const
31 {
32     SetValue(node[GET_NAME(time)], time);
33     SetValue(node[GET_NAME(sKey)], sKey);
34     SetValue(node[GET_NAME(nonce)], nonce);
35     SetValue(node[GET_NAME(storeType)], storeType);
36     SetValue(node[GET_NAME(area)], area);
37     return true;
38 }
39 
Unmarshal(const json & node)40 bool SecretKeyMetaData::Unmarshal(const json &node)
41 {
42     GetValue(node, GET_NAME(time), time);
43     GetValue(node, GET_NAME(sKey), sKey);
44     GetValue(node, GET_NAME(nonce), nonce);
45     GetValue(node, GET_NAME(storeType), storeType);
46     GetValue(node, GET_NAME(area), area);
47     return true;
48 }
49 
GetKey(const std::initializer_list<std::string> & fields)50 std::string SecretKeyMetaData::GetKey(const std::initializer_list<std::string> &fields)
51 {
52     std::string prefix = GetPrefix(fields);
53     prefix.append("SINGLE_KEY");
54     return prefix;
55 }
56 
GetBackupKey(const std::initializer_list<std::string> & fields)57 std::string SecretKeyMetaData::GetBackupKey(const std::initializer_list<std::string> &fields)
58 {
59     std::string prefix = GetBackupPrefix(fields);
60     return prefix;
61 }
62 
GetPrefix(const std::initializer_list<std::string> & fields)63 std::string SecretKeyMetaData::GetPrefix(const std::initializer_list<std::string> &fields)
64 {
65     std::string prefix = KEY_PREFIX;
66     for (const auto &field : fields) {
67         prefix.append(Constant::KEY_SEPARATOR).append(field);
68     }
69     prefix.append(Constant::KEY_SEPARATOR);
70     return prefix;
71 }
72 
GetBackupPrefix(const std::initializer_list<std::string> & fields)73 std::string SecretKeyMetaData::GetBackupPrefix(const std::initializer_list<std::string> &fields)
74 {
75     std::string prefix = BACKUP_KEY_PREFIX;
76     for (const auto &field : fields) {
77         prefix.append(Constant::KEY_SEPARATOR).append(field);
78     }
79     prefix.append(Constant::KEY_SEPARATOR);
80     return prefix;
81 }
82 
GetCloneKey(const std::initializer_list<std::string> & fields)83 std::string SecretKeyMetaData::GetCloneKey(const std::initializer_list<std::string> &fields)
84 {
85     std::string prefix = CLONE_KEY_PREFIX;
86     prefix.append(Constant::KEY_SEPARATOR).append(GetKey(fields));
87     return prefix;
88 }
89 } // namespace DistributedData
90 } // namespace OHOS
91