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 #pragma once
0019
0020 #include <unordered_map>
0021
0022 #include "arrow/util/base64.h"
0023
0024 #include "parquet/encryption/kms_client_factory.h"
0025 #include "parquet/encryption/local_wrap_kms_client.h"
0026 #include "parquet/platform.h"
0027
0028 namespace parquet::encryption {
0029
0030
0031
0032 class TestOnlyLocalWrapInMemoryKms : public LocalWrapKmsClient {
0033 public:
0034 explicit TestOnlyLocalWrapInMemoryKms(const KmsConnectionConfig& kms_connection_config);
0035
0036 static void InitializeMasterKeys(
0037 const std::unordered_map<std::string, ::arrow::util::SecureString>&
0038 master_keys_map);
0039
0040 protected:
0041 const ::arrow::util::SecureString& GetMasterKeyFromServer(
0042 const std::string& master_key_identifier) override;
0043
0044 private:
0045 static std::unordered_map<std::string, ::arrow::util::SecureString> master_key_map_;
0046 };
0047
0048
0049
0050 class TestOnlyInServerWrapKms : public KmsClient {
0051 public:
0052 static void InitializeMasterKeys(
0053 const std::unordered_map<std::string, ::arrow::util::SecureString>&
0054 master_keys_map);
0055
0056 std::string WrapKey(const ::arrow::util::SecureString& key_bytes,
0057 const std::string& master_key_identifier) override;
0058
0059 ::arrow::util::SecureString UnwrapKey(
0060 const std::string& wrapped_key, const std::string& master_key_identifier) override;
0061
0062 static void StartKeyRotation(
0063 const std::unordered_map<std::string, ::arrow::util::SecureString>&
0064 new_master_keys_map);
0065 static void FinishKeyRotation();
0066
0067 private:
0068 ::arrow::util::SecureString GetMasterKeyFromServer(
0069 const std::string& master_key_identifier);
0070
0071
0072
0073 static std::unordered_map<std::string, ::arrow::util::SecureString>
0074 unwrapping_master_key_map_;
0075 static std::unordered_map<std::string, ::arrow::util::SecureString>
0076 wrapping_master_key_map_;
0077 };
0078
0079
0080
0081 class TestOnlyInMemoryKmsClientFactory : public KmsClientFactory {
0082 public:
0083 TestOnlyInMemoryKmsClientFactory(
0084 bool wrap_locally,
0085 const std::unordered_map<std::string, ::arrow::util::SecureString>& master_keys_map)
0086 : KmsClientFactory(wrap_locally) {
0087 TestOnlyLocalWrapInMemoryKms::InitializeMasterKeys(master_keys_map);
0088 TestOnlyInServerWrapKms::InitializeMasterKeys(master_keys_map);
0089 }
0090
0091 std::shared_ptr<KmsClient> CreateKmsClient(
0092 const KmsConnectionConfig& kms_connection_config) {
0093 if (wrap_locally_) {
0094 return std::make_shared<TestOnlyLocalWrapInMemoryKms>(kms_connection_config);
0095 } else {
0096 return std::make_shared<TestOnlyInServerWrapKms>();
0097 }
0098 }
0099 };
0100
0101 }