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)21SqliteConfig::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()37SqliteConfig::~SqliteConfig() 38 { 39 ClearEncryptKey(); 40 } 41 GetPath() const42std::string SqliteConfig::GetPath() const 43 { 44 return path; 45 } 46 SetPath(std::string newPath)47void SqliteConfig::SetPath(std::string newPath) 48 { 49 this->path = newPath; 50 } 51 52 GetStorageMode() const53StorageMode SqliteConfig::GetStorageMode() const 54 { 55 return storageMode; 56 } 57 GetJournalMode() const58std::string SqliteConfig::GetJournalMode() const 59 { 60 return journalMode; 61 } 62 GetSyncMode() const63std::string SqliteConfig::GetSyncMode() const 64 { 65 return syncMode; 66 } 67 IsReadOnly() const68bool SqliteConfig::IsReadOnly() const 69 { 70 return readOnly; 71 } 72 IsEncrypted() const73bool SqliteConfig::IsEncrypted() const 74 { 75 return encrypted; 76 } 77 IsInitEncrypted() const78bool SqliteConfig::IsInitEncrypted() const 79 { 80 return initEncrypted; 81 } 82 GetEncryptKey() const83std::vector<uint8_t> SqliteConfig::GetEncryptKey() const 84 { 85 return encryptKey; 86 } 87 UpdateEncryptKey(const std::vector<uint8_t> & newKey)88void 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()95void SqliteConfig::ClearEncryptKey() 96 { 97 std::fill(encryptKey.begin(), encryptKey.end(), 0); 98 encryptKey.clear(); 99 } 100 GetDatabaseFileType() const101std::string SqliteConfig::GetDatabaseFileType() const 102 { 103 return databaseFileType; 104 } 105 } // namespace NativeRdb 106 } // namespace OHOS