iceberg-cpp
Loading...
Searching...
No Matches
aes_gcm_stream.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <array>
26#include <cstdint>
27#include <memory>
28#include <span>
29#include <vector>
30
31#include "iceberg/file_io.h"
33#include "iceberg/result.h"
34
35namespace iceberg {
36
46 static constexpr int32_t kPlainBlockSize = 1024 * 1024;
47 static constexpr int32_t kNonceLength = 12;
48 static constexpr int32_t kGcmTagLength = 16;
49 static constexpr int32_t kCipherBlockSize =
50 kPlainBlockSize + kNonceLength + kGcmTagLength;
51 static constexpr std::array<char, 4> kMagic = {'A', 'G', 'S', '1'};
52 static constexpr int32_t kHeaderLength = 8; // magic + plain block size (LE int32)
53 static constexpr int64_t kMinStreamLength =
54 kHeaderLength + kNonceLength + kGcmTagLength;
55
60 ICEBERG_BUNDLE_EXPORT static Result<int64_t> PlaintextLength(int64_t encrypted_length);
61};
62
67class ICEBERG_BUNDLE_EXPORT AesGcmInputFile : public InputFile {
68 public:
69 AesGcmInputFile(std::unique_ptr<InputFile> source, std::vector<uint8_t> key,
70 std::vector<uint8_t> aad_prefix, int64_t encrypted_length);
71
72 std::string_view location() const override { return source_->location(); }
73 Result<int64_t> Size() const override;
75
76 private:
77 std::unique_ptr<InputFile> source_;
78 std::vector<uint8_t> key_;
79 std::vector<uint8_t> aad_prefix_;
80 int64_t encrypted_length_;
81};
82
84class ICEBERG_BUNDLE_EXPORT AesGcmOutputFile : public OutputFile {
85 public:
86 AesGcmOutputFile(std::unique_ptr<OutputFile> target, std::vector<uint8_t> key,
87 std::vector<uint8_t> aad_prefix);
88
89 std::string_view location() const override { return target_->location(); }
92
93 private:
94 std::unique_ptr<OutputFile> target_;
95 std::vector<uint8_t> key_;
96 std::vector<uint8_t> aad_prefix_;
97};
98
99} // namespace iceberg
An InputFile that decrypts an AGS1 file.
Definition aes_gcm_stream.h:67
Result< std::unique_ptr< SeekableInputStream > > Open() override
Open a new independent input stream.
std::string_view location() const override
File location represented by this handle.
Definition aes_gcm_stream.h:72
Result< int64_t > Size() const override
Return the total file size in bytes.
An OutputFile that writes an AGS1 file.
Definition aes_gcm_stream.h:84
std::string_view location() const override
File location represented by this handle.
Definition aes_gcm_stream.h:89
Result< std::unique_ptr< PositionOutputStream > > CreateOrOverwrite() override
Create a new output stream, replacing any existing file.
Result< std::unique_ptr< PositionOutputStream > > Create() override
Create a new output stream and fail if the file already exists.
Handle for opening a readable file.
Definition file_io.h:94
Handle for creating a writable file.
Definition file_io.h:109
Definition expected.h:1199
Define the FileIO abstraction and file stream interfaces.
Define symbol visibility macros for bundled format integrations.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
Define Result, Status, and error helpers.
AES GCM Stream format constants.
Definition aes_gcm_stream.h:45
static ICEBERG_BUNDLE_EXPORT Result< int64_t > PlaintextLength(int64_t encrypted_length)
Plaintext length of a stream with the given encrypted length.