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 #ifndef SINGLE_VER_DATABASE_OPER_H 17 #define SINGLE_VER_DATABASE_OPER_H 18 19 #include "database_oper.h" 20 #include "sqlite_single_ver_natural_store.h" 21 22 namespace DistributedDB { 23 class SingleVerDatabaseOper : public DatabaseOper { 24 public: 25 SingleVerDatabaseOper(SQLiteSingleVerNaturalStore *naturalStore, SQLiteStorageEngine *storageEngine); ~SingleVerDatabaseOper()26 ~SingleVerDatabaseOper() override {}; 27 28 int Rekey(const CipherPassword &passwd) override; 29 30 int Import(const std::string &filePath, const CipherPassword &passwd, bool isNeedIntegrityCheck = false) override; 31 32 int Export(const std::string &filePath, const CipherPassword &passwd) const override; 33 34 protected: 35 bool RekeyPreHandle(const CipherPassword &passwd, int &errCode) override; 36 37 int BackupDb(const CipherPassword &passwd) const override; 38 39 int CloseStorages() override; 40 41 int RekeyPostHandle(const CipherPassword &passwd) override; 42 43 int ExportAllDatabases(const std::string ¤tDir, const CipherPassword &passwd, 44 const std::string &dbDir) const override; 45 46 int BackupCurrentDatabase(const ImportFileInfo &info) const override; 47 48 int ImportUnpackedDatabase(const ImportFileInfo &info, const CipherPassword &srcPasswd, 49 bool isNeedIntegrityCheck = false) const override; 50 51 int ImportPostHandle() const override; 52 53 private: 54 int InitStorageEngine(); 55 56 void InitDataBaseOption(OpenDbProperties &option) const; 57 58 int RunExportLogic(const CipherPassword &passwd, const std::string &filePrefix) const; 59 60 int RunRekeyLogic(CipherType type, const CipherPassword &passwd); 61 62 int ExportMainDB(const std::string ¤tDir, const CipherPassword &passwd, const std::string &dbDir) const; 63 64 int ExportMetaDB(const std::string ¤tDir, const CipherPassword &passwd, const std::string &dbDir) const; 65 66 int ClearCurrentDatabase(const ImportFileInfo &info) const; 67 68 int ImportUnpackedMainDatabase(const ImportFileInfo &info, const CipherPassword &srcPasswd, 69 bool isNeedIntegrityCheck = false) const; 70 71 int ImportUnpackedMetaDatabase(const ImportFileInfo &info) const; 72 73 int SetSecOpt(const std::string &path, bool isDir = true) const; 74 75 int BackupDatabase(const ImportFileInfo &info) const; 76 77 int RunRekeyLogicInner(CipherType type, sqlite3 *db, const CipherPassword &passwd); 78 79 SQLiteSingleVerNaturalStore *singleVerNaturalStore_; 80 SQLiteStorageEngine *storageEngine_; 81 }; 82 } // namespace DistributedDB 83 #endif // SINGLE_VER_DATABASE_OPER_H