/Users/deen/code/yugabyte-db/src/yb/encryption/header_manager_mock_impl.cc
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 | | #include "yb/encryption/header_manager_mock_impl.h" |
15 | | #include "yb/encryption/encryption_util.h" |
16 | | |
17 | | namespace yb { |
18 | | namespace encryption { |
19 | | |
20 | | constexpr uint32_t kDefaultHeaderSize = 32; |
21 | | constexpr uint32_t kEncryptionMetaStart = 16; |
22 | | |
23 | 2 | HeaderManagerMockImpl::HeaderManagerMockImpl() {} |
24 | | |
25 | 4 | void HeaderManagerMockImpl::SetFileEncryption(bool file_encrypted) { |
26 | 4 | file_encrypted_ = file_encrypted; |
27 | 4 | } |
28 | | |
29 | | Result<string> HeaderManagerMockImpl::SerializeEncryptionParams( |
30 | 2 | const EncryptionParams& encryption_info) { |
31 | 2 | string header; |
32 | 2 | header.resize(kDefaultHeaderSize, 0); |
33 | 2 | encryption_params_.reset(new EncryptionParams(encryption_info)); |
34 | 2 | return header; |
35 | 2 | } |
36 | | |
37 | | Result<EncryptionParamsPtr> |
38 | 3 | HeaderManagerMockImpl::DecodeEncryptionParamsFromEncryptionMetadata(const yb::Slice& s) { |
39 | 3 | auto encryption_params = std::make_unique<EncryptionParams>(); |
40 | 3 | memcpy(encryption_params.get(), encryption_params_.get(), sizeof(EncryptionParams)); |
41 | 3 | return encryption_params; |
42 | 3 | } |
43 | | |
44 | 12 | uint32_t HeaderManagerMockImpl::GetEncryptionMetadataStartIndex() { |
45 | 12 | return kEncryptionMetaStart; |
46 | 12 | } |
47 | | |
48 | | Result<FileEncryptionStatus> HeaderManagerMockImpl::GetFileEncryptionStatusFromPrefix( |
49 | 6 | const Slice& s) { |
50 | 6 | FileEncryptionStatus status; |
51 | 6 | status.is_encrypted = file_encrypted_; |
52 | 6 | status.header_size = kDefaultHeaderSize - GetEncryptionMetadataStartIndex(); |
53 | 6 | return status; |
54 | 6 | } |
55 | | |
56 | 2 | std::unique_ptr<HeaderManager> GetMockHeaderManager() { |
57 | 2 | return std::make_unique<HeaderManagerMockImpl>(); |
58 | 2 | } |
59 | | |
60 | 4 | bool HeaderManagerMockImpl::IsEncryptionEnabled() { |
61 | 4 | return file_encrypted_; |
62 | 4 | } |
63 | | |
64 | | } // namespace encryption |
65 | | } // namespace yb |