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
16 #include "kvdb_properties.h"
17
18 #include "db_constant.h"
19
20 namespace DistributedDB {
21 const std::string KvDBProperties::FILE_NAME = "fileName";
22 const std::string KvDBProperties::MEMORY_MODE = "memoryMode";
23 const std::string KvDBProperties::ENCRYPTED_MODE = "isEncryptedDb";
24 const std::string KvDBProperties::FIRST_OPEN_IS_READ_ONLY = "firstOpenIsReadOnly";
25 const std::string KvDBProperties::CREATE_DIR_BY_STORE_ID_ONLY = "createDirByStoreIdOnly";
26 const std::string KvDBProperties::SECURITY_LABEL = "securityLabel";
27 const std::string KvDBProperties::SECURITY_FLAG = "securityFlag";
28 const std::string KvDBProperties::CONFLICT_RESOLVE_POLICY = "conflictResolvePolicy";
29 const std::string KvDBProperties::CHECK_INTEGRITY = "checkIntegrity";
30 const std::string KvDBProperties::RM_CORRUPTED_DB = "rmCorruptedDb";
31 const std::string KvDBProperties::COMPRESS_ON_SYNC = "needCompressOnSync";
32 const std::string KvDBProperties::COMPRESSION_RATE = "compressionRate";
33 const std::string KvDBProperties::LOCAL_ONLY = "localOnly";
34
KvDBProperties()35 KvDBProperties::KvDBProperties()
36 : cipherType_(CipherType::AES_256_GCM)
37 {}
38
~KvDBProperties()39 KvDBProperties::~KvDBProperties() {}
40
GetStoreSubDirectory(int type)41 std::string KvDBProperties::GetStoreSubDirectory(int type)
42 {
43 switch (type) {
44 case LOCAL_TYPE:
45 return DBConstant::LOCAL_SUB_DIR;
46 case MULTI_VER_TYPE:
47 return DBConstant::MULTI_SUB_DIR;
48 case SINGLE_VER_TYPE:
49 return DBConstant::SINGLE_SUB_DIR;
50 default:
51 return "unknown";
52 }
53 }
54
GetPassword(CipherType & type,CipherPassword & password) const55 void KvDBProperties::GetPassword(CipherType &type, CipherPassword &password) const
56 {
57 type = cipherType_;
58 password = password_;
59 }
60
SetPassword(CipherType type,const CipherPassword & password)61 void KvDBProperties::SetPassword(CipherType type, const CipherPassword &password)
62 {
63 cipherType_ = type;
64 password_ = password;
65 }
66
IsSchemaExist() const67 bool KvDBProperties::IsSchemaExist() const
68 {
69 return schema_.IsSchemaValid();
70 }
71
SetSchema(const SchemaObject & schema)72 void KvDBProperties::SetSchema(const SchemaObject &schema)
73 {
74 schema_ = schema;
75 }
76
GetSchema() const77 SchemaObject KvDBProperties::GetSchema() const
78 {
79 return schema_;
80 }
81
GetSecLabel() const82 int KvDBProperties::GetSecLabel() const
83 {
84 return GetIntProp(KvDBProperties::SECURITY_LABEL, 0);
85 }
86
GetSecFlag() const87 int KvDBProperties::GetSecFlag() const
88 {
89 return GetIntProp(KvDBProperties::SECURITY_FLAG, 0);
90 }
91
GetSchemaConstRef() const92 const SchemaObject &KvDBProperties::GetSchemaConstRef() const
93 {
94 return schema_;
95 }
96 } // namespace DistributedDB
97