• 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 
16 #include "sqlite_config.h"
17 #include "sqlite_global_config.h"
18 
19 namespace OHOS {
20 namespace NativeRdb {
SqliteConfig(const RdbStoreConfig & config)21 SqliteConfig::SqliteConfig(const RdbStoreConfig &config)
22 {
23     path = config.GetPath();
24     storageMode = config.GetStorageMode();
25     readOnly = config.IsReadOnly();
26     encryptKey = config.GetEncryptKey();
27     encrypted = !encryptKey.empty();
28     initEncrypted = !encryptKey.empty();
29     journalMode = config.GetJournalMode();
30     databaseFileType = config.GetDatabaseFileType();
31     syncMode = config.GetSyncMode();
32     if (journalMode.empty()) {
33         journalMode = SqliteGlobalConfig::GetDefaultJournalMode();
34     }
35 }
36 
~SqliteConfig()37 SqliteConfig::~SqliteConfig()
38 {
39     ClearEncryptKey();
40 }
41 
GetPath() const42 std::string SqliteConfig::GetPath() const
43 {
44     return path;
45 }
46 
SetPath(std::string newPath)47 void SqliteConfig::SetPath(std::string newPath)
48 {
49     this->path = newPath;
50 }
51 
52 
GetStorageMode() const53 StorageMode SqliteConfig::GetStorageMode() const
54 {
55     return storageMode;
56 }
57 
GetJournalMode() const58 std::string SqliteConfig::GetJournalMode() const
59 {
60     return journalMode;
61 }
62 
GetSyncMode() const63 std::string SqliteConfig::GetSyncMode() const
64 {
65     return syncMode;
66 }
67 
IsReadOnly() const68 bool SqliteConfig::IsReadOnly() const
69 {
70     return readOnly;
71 }
72 
IsEncrypted() const73 bool SqliteConfig::IsEncrypted() const
74 {
75     return encrypted;
76 }
77 
IsInitEncrypted() const78 bool SqliteConfig::IsInitEncrypted() const
79 {
80     return initEncrypted;
81 }
82 
GetEncryptKey() const83 std::vector<uint8_t> SqliteConfig::GetEncryptKey() const
84 {
85     return encryptKey;
86 }
87 
UpdateEncryptKey(const std::vector<uint8_t> & newKey)88 void SqliteConfig::UpdateEncryptKey(const std::vector<uint8_t> &newKey)
89 {
90     std::fill(encryptKey.begin(), encryptKey.end(), 0);
91     encryptKey = newKey;
92     encrypted = !encryptKey.empty();
93 }
94 
ClearEncryptKey()95 void SqliteConfig::ClearEncryptKey()
96 {
97     std::fill(encryptKey.begin(), encryptKey.end(), 0);
98     encryptKey.clear();
99 }
100 
GetDatabaseFileType() const101 std::string SqliteConfig::GetDatabaseFileType() const
102 {
103     return databaseFileType;
104 }
105 } // namespace NativeRdb
106 } // namespace OHOS