Skip to content

Commit 145c4d3

Browse files
authored
GH-40731: [C++][Parquet] Minor enhancement code of encryption (#40732)
### Rationale for this change * Applying more `std::move` in encryption * Trying to use `NULLPTR` rather than `NULL`. ### What changes are included in this PR? Applying more `std::move` in encryption ### Are these changes tested? No need ### Are there any user-facing changes? No * GitHub Issue: #40731 Authored-by: mwish <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent fc87fd7 commit 145c4d3

9 files changed

Lines changed: 23 additions & 16 deletions

File tree

‎cpp/src/parquet/encryption/crypto_factory.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace parquet::encryption {
3030

3131
void CryptoFactory::RegisterKmsClientFactory(
3232
std::shared_ptr<KmsClientFactory> kms_client_factory) {
33-
key_toolkit_->RegisterKmsClientFactory(kms_client_factory);
33+
key_toolkit_->RegisterKmsClientFactory(std::move(kms_client_factory));
3434
}
3535

3636
std::shared_ptr<FileEncryptionProperties> CryptoFactory::GetFileEncryptionProperties(

‎cpp/src/parquet/encryption/file_key_unwrapper.cc‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,37 @@ FileKeyUnwrapper::FileKeyUnwrapper(
3030
const std::string& file_path,
3131
const std::shared_ptr<::arrow::fs::FileSystem>& file_system)
3232
: FileKeyUnwrapper(std::move(key_toolkit), /*key_toolkit=*/nullptr,
33-
kms_connection_config, cache_lifetime_seconds, file_path,
34-
file_system) {}
33+
kms_connection_config, cache_lifetime_seconds,
34+
/*key_material_store=*/nullptr, file_path, file_system) {}
3535

3636
FileKeyUnwrapper::FileKeyUnwrapper(
3737
KeyToolkit* key_toolkit, const KmsConnectionConfig& kms_connection_config,
3838
double cache_lifetime_seconds, const std::string& file_path,
3939
const std::shared_ptr<::arrow::fs::FileSystem>& file_system)
4040
: FileKeyUnwrapper(/*key_toolkit_owner=*/nullptr, key_toolkit, kms_connection_config,
41-
cache_lifetime_seconds, file_path, file_system) {}
41+
cache_lifetime_seconds, /*key_material_store=*/nullptr, file_path,
42+
file_system) {}
4243

4344
FileKeyUnwrapper::FileKeyUnwrapper(
4445
KeyToolkit* key_toolkit, const KmsConnectionConfig& kms_connection_config,
4546
double cache_lifetime_seconds,
4647
std::shared_ptr<FileKeyMaterialStore> key_material_store)
4748
: FileKeyUnwrapper(/*key_toolkit_owner=*/nullptr, key_toolkit, kms_connection_config,
48-
cache_lifetime_seconds, /*file_path=*/"",
49+
cache_lifetime_seconds, std::move(key_material_store),
50+
/*file_path=*/"",
4951
/*file_system=*/nullptr) {}
5052

5153
FileKeyUnwrapper::FileKeyUnwrapper(
5254
std::shared_ptr<KeyToolkit> key_toolkit_owner, KeyToolkit* key_toolkit,
5355
const KmsConnectionConfig& kms_connection_config, double cache_lifetime_seconds,
56+
std::shared_ptr<FileKeyMaterialStore> key_material_store,
5457
const std::string& file_path,
5558
const std::shared_ptr<::arrow::fs::FileSystem>& file_system)
5659
: key_toolkit_owner_(std::move(key_toolkit_owner)),
5760
key_toolkit_(key_toolkit ? key_toolkit : key_toolkit_owner_.get()),
5861
kms_connection_config_(kms_connection_config),
5962
cache_entry_lifetime_seconds_(cache_lifetime_seconds),
63+
key_material_store_(std::move(key_material_store)),
6064
file_path_(file_path),
6165
file_system_(file_system) {
6266
kek_per_kek_id_ = key_toolkit_->kek_read_cache_per_token().GetOrCreateInternalCache(
@@ -120,7 +124,7 @@ KeyWithMasterId FileKeyUnwrapper::GetDataEncryptionKey(const KeyMaterial& key_ma
120124
data_key = internal::DecryptKeyLocally(encoded_wrapped_dek, kek_bytes, aad);
121125
}
122126

123-
return KeyWithMasterId(data_key, master_key_id);
127+
return KeyWithMasterId(std::move(data_key), std::move(master_key_id));
124128
}
125129

126130
std::shared_ptr<KmsClient> FileKeyUnwrapper::GetKmsClientFromConfigOrKeyMaterial(

‎cpp/src/parquet/encryption/file_key_unwrapper.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class PARQUET_EXPORT FileKeyUnwrapper : public DecryptionKeyRetriever {
7373
private:
7474
FileKeyUnwrapper(std::shared_ptr<KeyToolkit> key_toolkit_owner, KeyToolkit* key_toolkit,
7575
const KmsConnectionConfig& kms_connection_config,
76-
double cache_lifetime_seconds, const std::string& file_path,
76+
double cache_lifetime_seconds,
77+
std::shared_ptr<FileKeyMaterialStore> key_material_store,
78+
const std::string& file_path,
7779
const std::shared_ptr<::arrow::fs::FileSystem>& file_system);
7880

7981
std::shared_ptr<KmsClient> GetKmsClientFromConfigOrKeyMaterial(

‎cpp/src/parquet/encryption/file_key_wrapper.cc‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ std::string FileKeyWrapper::GetEncryptionKeyMetadata(const std::string& data_key
5353
const std::string& master_key_id,
5454
bool is_footer_key,
5555
std::string key_id_in_file) {
56-
if (kms_client_ == NULL) {
56+
if (kms_client_ == NULLPTR) {
5757
throw ParquetException("No KMS client available. See previous errors.");
5858
}
5959

@@ -103,7 +103,7 @@ std::string FileKeyWrapper::GetEncryptionKeyMetadata(const std::string& data_key
103103
key_counter_++;
104104
}
105105
}
106-
key_material_store_->AddKeyMaterial(key_id_in_file, serialized_key_material);
106+
key_material_store_->AddKeyMaterial(key_id_in_file, std::move(serialized_key_material));
107107
std::string serialized_key_metadata =
108108
KeyMetadata::CreateSerializedForExternalMaterial(key_id_in_file);
109109
return serialized_key_metadata;
@@ -120,7 +120,8 @@ KeyEncryptionKey FileKeyWrapper::CreateKeyEncryptionKey(
120120
// Encrypt KEK with Master key
121121
std::string encoded_wrapped_kek = kms_client_->WrapKey(kek_bytes, master_key_id);
122122

123-
return KeyEncryptionKey(kek_bytes, kek_id, encoded_wrapped_kek);
123+
return KeyEncryptionKey(std::move(kek_bytes), std::move(kek_id),
124+
std::move(encoded_wrapped_kek));
124125
}
125126

126127
} // namespace parquet::encryption

‎cpp/src/parquet/encryption/key_management_test.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TestEncryptionKeyManagement : public ::testing::Test {
6969
wrap_locally_ = wrap_locally;
7070
std::shared_ptr<KmsClientFactory> kms_client_factory =
7171
std::make_shared<TestOnlyInMemoryKmsClientFactory>(wrap_locally, key_list_);
72-
crypto_factory_.RegisterKmsClientFactory(kms_client_factory);
72+
crypto_factory_.RegisterKmsClientFactory(std::move(kms_client_factory));
7373
}
7474

7575
std::string GetFileName(bool double_wrapping, bool wrap_locally,

‎cpp/src/parquet/encryption/key_toolkit.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace parquet::encryption {
3131

3232
std::shared_ptr<KmsClient> KeyToolkit::GetKmsClient(
3333
const KmsConnectionConfig& kms_connection_config, double cache_entry_lifetime_ms) {
34-
if (kms_client_factory_ == NULL) {
34+
if (kms_client_factory_ == nullptr) {
3535
throw ParquetException("No KmsClientFactory is registered.");
3636
}
3737
auto kms_client_per_kms_instance_cache =

‎cpp/src/parquet/encryption/key_toolkit.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class PARQUET_EXPORT KeyToolkit {
6262
void RemoveCacheEntriesForAllTokens();
6363

6464
void RegisterKmsClientFactory(std::shared_ptr<KmsClientFactory> kms_client_factory) {
65-
if (kms_client_factory_ != NULL) {
65+
if (kms_client_factory_ != NULLPTR) {
6666
throw ParquetException("KMS client factory has already been registered.");
6767
}
68-
kms_client_factory_ = kms_client_factory;
68+
kms_client_factory_ = std::move(kms_client_factory);
6969
}
7070

7171
/// Key rotation. In the single wrapping mode, decrypts data keys with old master keys,

‎cpp/src/parquet/encryption/kms_client.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void KmsConnectionConfig::SetDefaultIfEmpty() {
3434
if (kms_instance_url.empty()) {
3535
kms_instance_url = KmsClient::kKmsInstanceUrlDefault;
3636
}
37-
if (refreshable_key_access_token == NULL) {
37+
if (refreshable_key_access_token == nullptr) {
3838
refreshable_key_access_token = std::make_shared<KeyAccessToken>();
3939
}
4040
}

‎cpp/src/parquet/encryption/kms_client.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct PARQUET_EXPORT KmsConnectionConfig {
6363
KmsConnectionConfig();
6464

6565
const std::string& key_access_token() const {
66-
if (refreshable_key_access_token == NULL ||
66+
if (refreshable_key_access_token == NULLPTR ||
6767
refreshable_key_access_token->value().empty()) {
6868
throw ParquetException("key access token is not set!");
6969
}

0 commit comments

Comments
 (0)