/Users/deen/code/yugabyte-db/src/yb/encryption/universe_key_manager.h
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_ENCRYPTION_UNIVERSE_KEY_MANAGER_H |
15 | | #define YB_ENCRYPTION_UNIVERSE_KEY_MANAGER_H |
16 | | |
17 | | #include <shared_mutex> |
18 | | |
19 | | #include "yb/encryption/encryption.pb.h" |
20 | | #include "yb/encryption/encryption_util.h" |
21 | | |
22 | | namespace yb { |
23 | | namespace encryption { |
24 | | |
25 | | // Class is responsible for saving the universe key registry from master on heartbeat for use |
26 | | // in creating new files and reading exising files. |
27 | | class UniverseKeyManager { |
28 | | public: |
29 | | static Result<std::unique_ptr<UniverseKeyManager>> FromKey( |
30 | | const std::string& key_id, const Slice& key_data); |
31 | | void SetUniverseKeyRegistry(const UniverseKeyRegistryPB& universe_key_registry); |
32 | | void SetUniverseKeys(const UniverseKeysPB& universe_keys); |
33 | | // From an existing version id, generate encryption params. Used when creating readable files. |
34 | | Result<EncryptionParamsPtr> GetUniverseParamsWithVersion( |
35 | | const UniverseKeyId& version_id); |
36 | | // Get the latest universe key in the registry. Used when creating writable files. |
37 | | Result<UniverseKeyParams> GetLatestUniverseParams(); |
38 | | bool IsEncryptionEnabled(); |
39 | | bool ReceivedUniverseKeys(); |
40 | | |
41 | 5.81k | void SetGetUniverseKeysCallback(std::function<void()> get_universe_keys_callback) { |
42 | 5.81k | get_universe_keys_callback_ = get_universe_keys_callback; |
43 | 5.81k | } |
44 | | |
45 | | private: |
46 | | // Registry from master. |
47 | | encryption::UniverseKeyRegistryPB universe_key_registry_; |
48 | | |
49 | | mutable std::mutex mutex_; |
50 | | std::condition_variable cond_; |
51 | | |
52 | | // Set to true once the registry has been received from master. |
53 | | bool received_universe_keys_ = false; |
54 | | |
55 | | std::function<void()> get_universe_keys_callback_; |
56 | | }; |
57 | | |
58 | | } // namespace encryption |
59 | | } // namespace yb |
60 | | |
61 | | #endif // YB_ENCRYPTION_UNIVERSE_KEY_MANAGER_H |