YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

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