• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_DISTRIBUTED_DATA_INTERFACE_GDB_STORE_CONFIG_H
17 #define OHOS_DISTRIBUTED_DATA_INTERFACE_GDB_STORE_CONFIG_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <vector>
22 
23 #include "rdb_store_config.h"
24 #include "rdb_visibility.h"
25 
26 namespace OHOS::DistributedDataAip {
27 enum SecurityLevel : int32_t {
28     S1 = 1,
29     S2,
30     S3,
31     S4,
32     LAST,
33 };
34 
35 enum class DBType : int {
36     /**
37      * The graph database.
38     */
39     DB_GRAPH,
40 
41     /**
42      * The vector database.
43     */
44     DB_VECTOR,
45     /**
46      * The BUTT of database.
47     */
48     DB_BUTT
49 };
50 
51 class StoreConfig {
52 public:
53     API_EXPORT StoreConfig() = default;
54     API_EXPORT ~StoreConfig();
55     API_EXPORT StoreConfig(std::string name, std::string path, DBType dbType = DBType::DB_GRAPH, bool isEncrypt = false,
56         const std::vector<uint8_t> &encryptKey = std::vector<uint8_t>());
57     API_EXPORT void SetName(std::string name);
58     API_EXPORT void SetPath(std::string path);
59     API_EXPORT void SetDbType(DBType dbType);
60     API_EXPORT void SetEncryptStatus(bool status);
61     API_EXPORT void SetSecurityLevel(int32_t securityLevel);
62     API_EXPORT bool IsEncrypt() const;
63     API_EXPORT std::string GetFullPath() const;
64     API_EXPORT std::string GetPath() const;
65     API_EXPORT std::string GetName() const;
66     API_EXPORT int32_t GetSecurityLevel() const;
67     API_EXPORT DBType GetDbType() const;
68     API_EXPORT void SetIter(int32_t iter) const;
69     API_EXPORT int32_t GetIter() const;
70     API_EXPORT int GetWriteTime() const;
71     API_EXPORT void SetWriteTime(int timeout);
72     API_EXPORT int GetReadTime() const;
73     API_EXPORT void SetReadTime(int timeout);
74     API_EXPORT int GetReadConSize() const;
75     API_EXPORT void SetReadConSize(int readConSize);
76     API_EXPORT std::vector<uint8_t> GetEncryptKey() const;
77     API_EXPORT int SetBundleName(const std::string &bundleName);
78     API_EXPORT std::string GetBundleName() const;
79     void GenerateEncryptedKey() const;
80     std::vector<uint8_t> GetNewEncryptKey() const;
81     void ChangeEncryptKey() const;
82 
83 private:
84     std::string name_;
85     std::string path_;
86     std::string bundleName_;
87     DBType dbType_ = DBType::DB_GRAPH;
88     bool isEncrypt_ = false;
89     mutable std::vector<uint8_t> encryptKey_{};
90     mutable std::vector<uint8_t> newEncryptKey_{};
91     mutable int32_t iter_ = 0;
92     int32_t writeTimeout_ = 2; // seconds
93     int32_t readTimeout_ = 1;  // seconds
94     int32_t readConSize_ = 4;
95     int32_t securityLevel_ = SecurityLevel::S1;
96 
97     static constexpr int MAX_TIMEOUT = 300; // seconds
98     static constexpr int MIN_TIMEOUT = 1;   // seconds
99     void ClearEncryptKey();
100 };
101 } // namespace OHOS::DistributedDataAip
102 #endif //OHOS_DISTRIBUTED_DATA_INTERFACE_GDB_STORE_CONFIG_H