File indexing completed on 2026-04-17 08:28:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #pragma once
0023
0024 #include <memory>
0025 #include <string>
0026 #include <unordered_map>
0027
0028 #include <gtest/gtest.h>
0029
0030 #include "arrow/filesystem/filesystem.h"
0031 #include "arrow/filesystem/localfs.h"
0032 #include "arrow/status.h"
0033 #include "arrow/util/io_util.h"
0034 #include "arrow/util/secure_string.h"
0035
0036 #include "parquet/encryption/encryption.h"
0037 #include "parquet/test_util.h"
0038
0039 namespace parquet {
0040 class ParquetFileReader;
0041 namespace encryption::test {
0042
0043 using ::arrow::internal::TemporaryDir;
0044 using ::arrow::util::SecureString;
0045
0046 constexpr int kFixedLength = 10;
0047
0048 const SecureString kFooterEncryptionKey("0123456789012345");
0049 const SecureString kColumnEncryptionKey1("1234567890123450");
0050 const SecureString kColumnEncryptionKey2("1234567890123451");
0051 const char kFileName[] = "tester";
0052
0053
0054 std::string data_file(const char* file);
0055
0056
0057 extern std::unique_ptr<TemporaryDir> temp_dir;
0058
0059 inline ::arrow::Result<std::unique_ptr<TemporaryDir>> temp_data_dir() {
0060 return TemporaryDir::Make("parquet-encryption-test-");
0061 }
0062
0063 const char kDoubleFieldName[] = "double_field";
0064 const char kFloatFieldName[] = "float_field";
0065 const char kBooleanFieldName[] = "boolean_field";
0066 const char kInt32FieldName[] = "int32_field";
0067 const char kInt64FieldName[] = "int64_field";
0068 const char kInt96FieldName[] = "int96_field";
0069 const char kByteArrayFieldName[] = "ba_field";
0070 const char kFixedLenByteArrayFieldName[] = "flba_field";
0071
0072 const char kFooterMasterKey[] = "0123456789012345";
0073 const char kFooterMasterKeyId[] = "kf";
0074 const char* const kColumnMasterKeys[] = {"1234567890123450", "1234567890123451",
0075 "1234567890123452", "1234567890123453",
0076 "1234567890123454", "1234567890123455"};
0077 const char* const kColumnMasterKeyIds[] = {"kc1", "kc2", "kc3", "kc4", "kc5", "kc6"};
0078
0079
0080 const char kNewFooterMasterKey[] = "9123456789012345";
0081 const char* const kNewColumnMasterKeys[] = {"9234567890123450", "9234567890123451",
0082 "9234567890123452", "9234567890123453",
0083 "9234567890123454", "9234567890123455"};
0084
0085
0086
0087 std::unordered_map<std::string, SecureString> BuildKeyMap(const char* const* column_ids,
0088 const char* const* column_keys,
0089 const char* footer_id,
0090 const char* footer_key);
0091
0092
0093
0094 std::string BuildColumnKeyMapping();
0095
0096
0097
0098
0099
0100 class FileEncryptor {
0101 public:
0102 FileEncryptor();
0103
0104 void EncryptFile(
0105 std::string file,
0106 std::shared_ptr<parquet::FileEncryptionProperties> encryption_configurations);
0107
0108 private:
0109 std::shared_ptr<schema::GroupNode> SetupEncryptionSchema();
0110
0111 int num_rowgroups_ = 5;
0112 int rows_per_rowgroup_ = 50;
0113 std::shared_ptr<schema::GroupNode> schema_;
0114 };
0115
0116 class FileDecryptor {
0117 public:
0118 void DecryptFile(
0119 const std::string& file_name,
0120 const std::shared_ptr<FileDecryptionProperties>& file_decryption_properties);
0121 void DecryptPageIndex(
0122 const std::string& file_name,
0123 const std::shared_ptr<FileDecryptionProperties>& file_decryption_properties);
0124
0125 private:
0126 void CheckFile(
0127 parquet::ParquetFileReader* file_reader,
0128 const std::shared_ptr<FileDecryptionProperties>& file_decryption_properties);
0129 void CheckPageIndex(
0130 parquet::ParquetFileReader* file_reader,
0131 const std::shared_ptr<FileDecryptionProperties>& file_decryption_properties);
0132 };
0133
0134 }
0135 }