YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/encryption/encrypted_file.h
Line
Count
Source (jump to first uncovered line)
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_ENCRYPTED_FILE_H
15
#define YB_ENCRYPTION_ENCRYPTED_FILE_H
16
17
#include <string.h>
18
19
#include <atomic>
20
#include <cstdarg>
21
#include <memory>
22
23
#include "yb/encryption/cipher_stream_fwd.h"
24
25
#include "yb/util/env.h"
26
#include "yb/util/faststring.h"
27
28
namespace yb {
29
namespace encryption {
30
31
class HeaderManager;
32
33
// An encrypted fie implementation for random access of a file.
34
class EncryptedRandomAccessFile : public RandomAccessFileWrapper {
35
 public:
36
  static Status Create(std::unique_ptr<RandomAccessFile>* result,
37
                       HeaderManager* header_manager,
38
                       std::unique_ptr<RandomAccessFile> underlying);
39
40
  EncryptedRandomAccessFile(std::unique_ptr<RandomAccessFile> file,
41
                            std::unique_ptr<BlockAccessCipherStream> stream,
42
                            uint64_t header_size)
43
      : RandomAccessFileWrapper(std::move(file)), stream_(std::move(stream)),
44
17
        header_size_(header_size) {}
45
46
17
  ~EncryptedRandomAccessFile() {}
47
48
  CHECKED_STATUS Read(uint64_t offset, size_t n, Slice* result, uint8_t* scratch) const override;
49
50
0
  uint64_t GetEncryptionHeaderSize() const override {
51
0
    return header_size_;
52
0
  }
53
54
  Result<uint64_t> Size() const override;
55
56
11
  virtual bool IsEncrypted() const override {
57
11
    return true;
58
11
  }
59
60
  CHECKED_STATUS ReadAndValidate(
61
      uint64_t offset, size_t n, Slice* result, char* scratch,
62
      const ReadValidator& validator) override;
63
64
16
  int64_t TEST_GetNumOverflowWorkarounds() {
65
16
    return num_overflow_workarounds_.load(std::memory_order_relaxed);
66
16
  }
67
68
 private:
69
  Status ReadInternal(
70
      uint64_t offset, size_t n, Slice* result, char* scratch,
71
      EncryptionOverflowWorkaround counter_overflow_workaround) const;
72
73
  std::unique_ptr<BlockAccessCipherStream> stream_;
74
  uint64_t header_size_;
75
  std::atomic<int64_t> num_overflow_workarounds_{0};
76
};
77
78
} // namespace encryption
79
} // namespace yb
80
81
#endif // YB_ENCRYPTION_ENCRYPTED_FILE_H