-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the key management tools API for encryption (#426)
- Loading branch information
Showing
35 changed files
with
3,065 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <parquet/encryption/encryption.h> | ||
#include <parquet/encryption/crypto_factory.h> | ||
#include <arrow/filesystem/localfs.h> | ||
|
||
#include "cpp/ParquetSharpExport.h" | ||
#include "../ExceptionInfo.h" | ||
#include "ManagedKmsClientFactory.h" | ||
|
||
using namespace parquet::encryption; | ||
|
||
extern "C" | ||
{ | ||
PARQUETSHARP_EXPORT ExceptionInfo* CryptoFactory_Create(CryptoFactory** crypto_factory) | ||
{ | ||
TRYCATCH(*crypto_factory = new CryptoFactory();) | ||
} | ||
|
||
PARQUETSHARP_EXPORT void CryptoFactory_Free(CryptoFactory* crypto_factory) | ||
{ | ||
delete crypto_factory; | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* CryptoFactory_RegisterKmsClientFactory( | ||
CryptoFactory* crypto_factory, | ||
void* const client_factory_handle, | ||
const ManagedKmsClient::FreeGcHandleFunc free_gc_handle, | ||
const ManagedKmsClientFactory::CreateClientFunc create_client, | ||
const ManagedKmsClient::WrapFunc wrap, | ||
const ManagedKmsClient::UnwrapFunc unwrap) | ||
{ | ||
TRYCATCH( | ||
crypto_factory->RegisterKmsClientFactory( | ||
std::make_shared<ManagedKmsClientFactory>(client_factory_handle, free_gc_handle, create_client, wrap, unwrap)); | ||
) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* CryptoFactory_GetFileEncryptionProperties( | ||
CryptoFactory* crypto_factory, | ||
const KmsConnectionConfig* kms_connection_config, | ||
const EncryptionConfiguration* encryption_configuration, | ||
const char* file_path, | ||
std::shared_ptr<parquet::FileEncryptionProperties>** file_encryption_properties) | ||
{ | ||
TRYCATCH( | ||
std::string file_path_str = file_path == nullptr ? "" : file_path; | ||
std::shared_ptr<::arrow::fs::FileSystem> file_system = file_path_str.empty() ? | ||
nullptr : std::make_shared<::arrow::fs::LocalFileSystem>(); | ||
(*file_encryption_properties) = new std::shared_ptr<parquet::FileEncryptionProperties>( | ||
crypto_factory->GetFileEncryptionProperties( | ||
*kms_connection_config, *encryption_configuration, file_path_str, file_system)); | ||
) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* CryptoFactory_GetFileDecryptionProperties( | ||
CryptoFactory* crypto_factory, | ||
const KmsConnectionConfig* kms_connection_config, | ||
const DecryptionConfiguration* decryption_configuration, | ||
const char* file_path, | ||
std::shared_ptr<parquet::FileDecryptionProperties>** file_decryption_properties) | ||
{ | ||
TRYCATCH( | ||
std::string file_path_str = file_path == nullptr ? "" : file_path; | ||
std::shared_ptr<::arrow::fs::FileSystem> file_system = file_path_str.empty() ? | ||
nullptr : std::make_shared<::arrow::fs::LocalFileSystem>(); | ||
(*file_decryption_properties) = new std::shared_ptr<parquet::FileDecryptionProperties>( | ||
crypto_factory->GetFileDecryptionProperties( | ||
*kms_connection_config, *decryption_configuration, file_path_str, file_system)); | ||
) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* CryptoFactory_RotateMasterKeys( | ||
CryptoFactory* crypto_factory, | ||
const KmsConnectionConfig* kms_connection_config, | ||
const char* file_path, | ||
bool double_wrapping, | ||
double cache_lifetime_seconds) | ||
{ | ||
TRYCATCH( | ||
std::string file_path_str = file_path == nullptr ? "" : file_path; | ||
std::shared_ptr<::arrow::fs::FileSystem> file_system = std::make_shared<::arrow::fs::LocalFileSystem>(); | ||
crypto_factory->RotateMasterKeys( | ||
*kms_connection_config, file_path_str, file_system, double_wrapping, cache_lifetime_seconds); | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <parquet/encryption/crypto_factory.h> | ||
|
||
#include "cpp/ParquetSharpExport.h" | ||
#include "../ExceptionInfo.h" | ||
|
||
using namespace parquet::encryption; | ||
|
||
extern "C" | ||
{ | ||
PARQUETSHARP_EXPORT ExceptionInfo* DecryptionConfiguration_Create(DecryptionConfiguration** configuration) | ||
{ | ||
TRYCATCH(*configuration = new DecryptionConfiguration();) | ||
} | ||
|
||
PARQUETSHARP_EXPORT void DecryptionConfiguration_Free(DecryptionConfiguration* configuration) | ||
{ | ||
delete configuration; | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* DecryptionConfiguration_GetCacheLifetimeSeconds(const DecryptionConfiguration* configuration, double* cache_lifetime_seconds) | ||
{ | ||
TRYCATCH(*cache_lifetime_seconds = configuration->cache_lifetime_seconds;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* DecryptionConfiguration_SetCacheLifetimeSeconds(DecryptionConfiguration* configuration, double cache_lifetime_seconds) | ||
{ | ||
TRYCATCH(configuration->cache_lifetime_seconds = cache_lifetime_seconds;) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include <parquet/encryption/crypto_factory.h> | ||
|
||
#include "cpp/ParquetSharpExport.h" | ||
#include "../ExceptionInfo.h" | ||
|
||
using namespace parquet::encryption; | ||
|
||
extern "C" | ||
{ | ||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_Create(const char* footer_key, EncryptionConfiguration** configuration) | ||
{ | ||
TRYCATCH(*configuration = new EncryptionConfiguration(footer_key == nullptr ? "" : footer_key);) | ||
} | ||
|
||
PARQUETSHARP_EXPORT void EncryptionConfiguration_Free(EncryptionConfiguration* configuration) | ||
{ | ||
delete configuration; | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetFooterKey(const EncryptionConfiguration* configuration, const char** footer_key) | ||
{ | ||
TRYCATCH(*footer_key = configuration->footer_key.c_str();) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetFooterKey(EncryptionConfiguration* configuration, const char* footer_key) | ||
{ | ||
TRYCATCH(configuration->footer_key = footer_key;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetColumnKeys(const EncryptionConfiguration* configuration, const char** column_keys) | ||
{ | ||
TRYCATCH(*column_keys = configuration->column_keys.c_str();) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetColumnKeys(EncryptionConfiguration* configuration, const char* column_keys) | ||
{ | ||
TRYCATCH(configuration->column_keys = column_keys;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetUniformEncryption(const EncryptionConfiguration* configuration, bool* uniform_encryption) | ||
{ | ||
TRYCATCH(*uniform_encryption = configuration->uniform_encryption;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetUniformEncryption(EncryptionConfiguration* configuration, bool uniform_encryption) | ||
{ | ||
TRYCATCH(configuration->uniform_encryption = uniform_encryption;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetEncryptionAlgorithm(const EncryptionConfiguration* configuration, parquet::ParquetCipher::type* encryption_algorithm) | ||
{ | ||
TRYCATCH(*encryption_algorithm = configuration->encryption_algorithm;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetEncryptionAlgorithm(EncryptionConfiguration* configuration, parquet::ParquetCipher::type encryption_algorithm) | ||
{ | ||
TRYCATCH(configuration->encryption_algorithm = encryption_algorithm;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetPlaintextFooter(const EncryptionConfiguration* configuration, bool* plaintext_footer) | ||
{ | ||
TRYCATCH(*plaintext_footer = configuration->plaintext_footer;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetPlaintextFooter(EncryptionConfiguration* configuration, bool plaintext_footer) | ||
{ | ||
TRYCATCH(configuration->plaintext_footer = plaintext_footer;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetDoubleWrapping(const EncryptionConfiguration* configuration, bool* double_wrapping) | ||
{ | ||
TRYCATCH(*double_wrapping = configuration->double_wrapping;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetDoubleWrapping(EncryptionConfiguration* configuration, bool double_wrapping) | ||
{ | ||
TRYCATCH(configuration->double_wrapping = double_wrapping;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetCacheLifetimeSeconds(const EncryptionConfiguration* configuration, double* cache_lifetime_seconds) | ||
{ | ||
TRYCATCH(*cache_lifetime_seconds = configuration->cache_lifetime_seconds;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetCacheLifetimeSeconds(EncryptionConfiguration* configuration, double cache_lifetime_seconds) | ||
{ | ||
TRYCATCH(configuration->cache_lifetime_seconds = cache_lifetime_seconds;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetInternalKeyMaterial(const EncryptionConfiguration* configuration, bool* internal_key_material) | ||
{ | ||
TRYCATCH(*internal_key_material = configuration->internal_key_material;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetInternalKeyMaterial(EncryptionConfiguration* configuration, bool internal_key_material) | ||
{ | ||
TRYCATCH(configuration->internal_key_material = internal_key_material;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_GetDataKeyLengthBits(const EncryptionConfiguration* configuration, int32_t* data_key_length_bits) | ||
{ | ||
TRYCATCH(*data_key_length_bits = configuration->data_key_length_bits;) | ||
} | ||
|
||
PARQUETSHARP_EXPORT ExceptionInfo* EncryptionConfiguration_SetDataKeyLengthBits(EncryptionConfiguration* configuration, int32_t data_key_length_bits) | ||
{ | ||
TRYCATCH(configuration->data_key_length_bits = data_key_length_bits;) | ||
} | ||
} |
Oops, something went wrong.