Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ jobs:
ARROW_BUILD_SHARED: ON
ARROW_BUILD_STATIC: OFF
ARROW_BUILD_TESTS: ON
ARROW_CMAKE_ARGS: -DPARQUET_BUILD_DBPS_LIBS=OFF
ARROW_DATASET: ON
ARROW_FLIGHT: OFF
ARROW_HDFS: ON
Expand Down Expand Up @@ -417,7 +418,9 @@ jobs:
ARROW_WITH_ZSTD: ON
ARROW_CMAKE_ARGS: >-
-DARROW_PACKAGE_PREFIX=/${{ matrix.msystem_lower}}
-DARROW_BUILD_SHARED=ON
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
-DPARQUET_BUILD_DBPS_LIBS=OFF
# We can't use unity build because we don't have enough memory on
# GitHub Actions.
# CMAKE_UNITY_BUILD: ON
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ jobs:
ARROW_WITH_ZSTD: ON
ARROW_CMAKE_ARGS: >-
-DARROW_PACKAGE_PREFIX=/ucrt${{ matrix.mingw-n-bits }}
-DARROW_BUILD_SHARED=ON
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
-DPARQUET_BUILD_DBPS_LIBS=OFF
CMAKE_UNITY_BUILD: ON
steps:
- name: Disable Crash Dialogs
Expand Down Expand Up @@ -349,6 +351,9 @@ jobs:
ARROW_WITH_SNAPPY: ON
ARROW_WITH_ZLIB: ON
ARROW_WITH_ZSTD: ON
ARROW_CMAKE_ARGS: >-
-DARROW_BUILD_SHARED=ON
-DPARQUET_BUILD_DBPS_LIBS=OFF
CMAKE_CXX_STANDARD: "17"
CMAKE_GENERATOR: Ninja
CMAKE_INSTALL_PREFIX: "${{ github.workspace }}/dist"
Expand Down
51 changes: 31 additions & 20 deletions cpp/src/parquet/encryption/aes_encryption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "parquet/encryption/openssl_internal.h"
#include "parquet/exception.h"

using ::arrow::util::span;
using parquet::ParquetException;

namespace parquet::encryption {
Expand Down Expand Up @@ -132,11 +131,11 @@ AesCryptoContext::CipherContext AesEncryptor::MakeCipherContext() const {
return ctx;
}

int32_t AesEncryptor::SignedFooterEncrypt(span<const uint8_t> footer,
span<const uint8_t> key,
span<const uint8_t> aad,
span<const uint8_t> nonce,
span<uint8_t> encrypted_footer) {
int32_t AesEncryptor::SignedFooterEncrypt(::arrow::util::span<const uint8_t> footer,
::arrow::util::span<const uint8_t> key,
::arrow::util::span<const uint8_t> aad,
::arrow::util::span<const uint8_t> nonce,
::arrow::util::span<uint8_t> encrypted_footer) {
if (static_cast<size_t>(key_length_) != key.size()) {
std::stringstream ss;
ss << "Wrong key length " << key.size() << ". Should be " << key_length_;
Expand All @@ -157,8 +156,10 @@ int32_t AesEncryptor::SignedFooterEncrypt(span<const uint8_t> footer,
return GcmEncrypt(footer, key, nonce, aad, encrypted_footer);
}

int32_t AesEncryptor::Encrypt(span<const uint8_t> plaintext, span<const uint8_t> key,
span<const uint8_t> aad, span<uint8_t> ciphertext) {
int32_t AesEncryptor::Encrypt(::arrow::util::span<const uint8_t> plaintext,
::arrow::util::span<const uint8_t> key,
::arrow::util::span<const uint8_t> aad,
::arrow::util::span<uint8_t> ciphertext) {
if (static_cast<size_t>(key_length_) != key.size()) {
std::stringstream ss;
ss << "Wrong key length " << key.size() << ". Should be " << key_length_;
Expand All @@ -184,9 +185,11 @@ int32_t AesEncryptor::Encrypt(span<const uint8_t> plaintext, span<const uint8_t>
return CtrEncrypt(plaintext, key, nonce, ciphertext);
}

int32_t AesEncryptor::GcmEncrypt(span<const uint8_t> plaintext, span<const uint8_t> key,
span<const uint8_t> nonce, span<const uint8_t> aad,
span<uint8_t> ciphertext) {
int32_t AesEncryptor::GcmEncrypt(::arrow::util::span<const uint8_t> plaintext,
::arrow::util::span<const uint8_t> key,
::arrow::util::span<const uint8_t> nonce,
::arrow::util::span<const uint8_t> aad,
::arrow::util::span<uint8_t> ciphertext) {
int len;
int32_t ciphertext_len;

Expand Down Expand Up @@ -261,8 +264,10 @@ int32_t AesEncryptor::GcmEncrypt(span<const uint8_t> plaintext, span<const uint8
return length_buffer_length_ + buffer_size;
}

int32_t AesEncryptor::CtrEncrypt(span<const uint8_t> plaintext, span<const uint8_t> key,
span<const uint8_t> nonce, span<uint8_t> ciphertext) {
int32_t AesEncryptor::CtrEncrypt(::arrow::util::span<const uint8_t> plaintext,
::arrow::util::span<const uint8_t> key,
::arrow::util::span<const uint8_t> nonce,
::arrow::util::span<uint8_t> ciphertext) {
int len;
int32_t ciphertext_len;

Expand Down Expand Up @@ -405,8 +410,10 @@ int32_t AesDecryptor::CiphertextLength(int32_t plaintext_len) const {
return plaintext_len + ciphertext_size_delta_;
}

int32_t AesDecryptor::Decrypt(span<const uint8_t> ciphertext, span<const uint8_t> key,
span<const uint8_t> aad, span<uint8_t> plaintext) {
int32_t AesDecryptor::Decrypt(::arrow::util::span<const uint8_t> ciphertext,
::arrow::util::span<const uint8_t> key,
::arrow::util::span<const uint8_t> aad,
::arrow::util::span<uint8_t> plaintext) {
if (static_cast<size_t>(key_length_) != key.size()) {
std::stringstream ss;
ss << "Wrong key length " << key.size() << ". Should be " << key_length_;
Expand Down Expand Up @@ -444,7 +451,8 @@ AesCryptoContext::CipherContext AesDecryptor::MakeCipherContext() const {
return ctx;
}

int32_t AesDecryptor::GetCiphertextLength(span<const uint8_t> ciphertext) const {
int32_t AesDecryptor::GetCiphertextLength(
::arrow::util::span<const uint8_t> ciphertext) const {
if (length_buffer_length_ > 0) {
// Note: length_buffer_length_ must be either 0 or kBufferSizeLength
if (ciphertext.size() < static_cast<size_t>(kBufferSizeLength)) {
Expand Down Expand Up @@ -489,8 +497,10 @@ int32_t AesDecryptor::GetCiphertextLength(span<const uint8_t> ciphertext) const
}
}

int32_t AesDecryptor::GcmDecrypt(span<const uint8_t> ciphertext, span<const uint8_t> key,
span<const uint8_t> aad, span<uint8_t> plaintext) {
int32_t AesDecryptor::GcmDecrypt(::arrow::util::span<const uint8_t> ciphertext,
::arrow::util::span<const uint8_t> key,
::arrow::util::span<const uint8_t> aad,
::arrow::util::span<uint8_t> plaintext) {
int len;
int32_t plaintext_len;

Expand Down Expand Up @@ -562,8 +572,9 @@ int32_t AesDecryptor::GcmDecrypt(span<const uint8_t> ciphertext, span<const uint
return plaintext_len;
}

int32_t AesDecryptor::CtrDecrypt(span<const uint8_t> ciphertext, span<const uint8_t> key,
span<uint8_t> plaintext) {
int32_t AesDecryptor::CtrDecrypt(::arrow::util::span<const uint8_t> ciphertext,
::arrow::util::span<const uint8_t> key,
::arrow::util::span<uint8_t> plaintext) {
int len;
int32_t plaintext_len;

Expand Down
7 changes: 4 additions & 3 deletions cpp/src/parquet/encryption/encoding_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
#include "parquet/column_page.h"
#include "parquet/encoding.h"
#include "parquet/metadata.h"
#include "parquet/platform.h"
#include "parquet/types.h"

namespace parquet::encryption {

class EncodingPropertiesBuilder;
class PARQUET_EXPORT EncodingPropertiesBuilder;

class EncodingProperties {
class PARQUET_EXPORT EncodingProperties {
public:
static std::unique_ptr<EncodingProperties> MakeFromMetadata(
const ColumnDescriptor* column_descriptor,
Expand Down Expand Up @@ -121,7 +122,7 @@ class EncodingProperties {
//--------------------------------
}; // class EncodingProperties

class EncodingPropertiesBuilder {
class PARQUET_EXPORT EncodingPropertiesBuilder {
public:
EncodingPropertiesBuilder() = default;

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/parquet/encryption/external/dbpa_enum_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <dbpa_interface.h>

#include "arrow/type_fwd.h" // For arrow::Compression
#include "parquet/platform.h"
#include "parquet/types.h"

namespace parquet::encryption::external {
Expand All @@ -34,7 +35,7 @@ namespace parquet::encryption::external {
* - parquet::Type and dbps::external::Type
* - arrow::Compression and dbps::external::CompressionCodec
*/
class DBPAEnumUtils {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed (for my own education)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unity is used in Windows for linking, and unless the classes and methods are tagged with PARQUET_EXPORT, they are not visible at linkage time.

class PARQUET_EXPORT DBPAEnumUtils {
public:
// Static maps for type conversions
static const std::unordered_map<parquet::Type::type, dbps::external::Type::type>
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/parquet/encryption/external/dbpa_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string>

#include <dbpa_interface.h>
#include "parquet/platform.h"

template <typename T>
using span = tcb::span<T>;
Expand All @@ -43,7 +44,7 @@ class DBPAExecutorTimeoutException;
* DBPAExecutor - A decorator for DataBatchProtectionAgentInterface with timeout support
* Original exceptions from wrapped agents are preserved and re-thrown unchanged.
*/
class DBPAExecutor : public DataBatchProtectionAgentInterface {
class PARQUET_EXPORT DBPAExecutor : public DataBatchProtectionAgentInterface {
public:
/**
* Constructor that takes ownership of the wrapped agent with configurable timeouts
Expand Down Expand Up @@ -112,7 +113,7 @@ class DBPAExecutor : public DataBatchProtectionAgentInterface {
/**
* Exception thrown when a DBPA operation times out
*/
class DBPAExecutorTimeoutException : public std::runtime_error {
class PARQUET_EXPORT DBPAExecutorTimeoutException : public std::runtime_error {
public:
explicit DBPAExecutorTimeoutException(const std::string& operation,
int64_t timeout_milliseconds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace parquet::encryption::external {

// Default implementation for handle closing function
void DefaultSharedLibraryClosingFn(void* library_handle) {
auto status = arrow::internal::CloseDynamicLibrary(library_handle);
auto status = ::arrow::internal::CloseDynamicLibrary(library_handle);
if (!status.ok()) {
ARROW_LOG(WARNING) << "Error closing library: " << status.message();
}
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/parquet/encryption/external/dbpa_library_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <optional>

#include <dbpa_interface.h>
#include "parquet/platform.h"

template <typename T>
using span = tcb::span<T>;
Expand All @@ -38,7 +39,7 @@ using dbps::external::Type;
// Default implementation for shared library closing function
// This is passed into the constructor of DBPALibraryWrapper,
// and is used as the default function to close the shared library.
void DefaultSharedLibraryClosingFn(void* library_handle);
PARQUET_EXPORT void DefaultSharedLibraryClosingFn(void* library_handle);

// Decorator/Wrapper class for the DataBatchProtectionAgentInterface
// Its main purpose is to close the shared library when Arrow is about to destroy
Expand All @@ -47,7 +48,7 @@ void DefaultSharedLibraryClosingFn(void* library_handle);
// In the constructor we allow to pass a function that will be used to close the shared
// library. This simplifies testing, as we can use a mock function to avoid actually
// closing the shared library.
class DBPALibraryWrapper : public DataBatchProtectionAgentInterface {
class PARQUET_EXPORT DBPALibraryWrapper : public DataBatchProtectionAgentInterface {
private:
std::unique_ptr<DataBatchProtectionAgentInterface> wrapped_agent_;
void* library_handle_;
Expand Down
10 changes: 6 additions & 4 deletions cpp/src/parquet/encryption/external/loadable_encryptor_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ typedef DataBatchProtectionAgentInterface* (*create_encryptor_t)();

std::unique_ptr<DataBatchProtectionAgentInterface> LoadableEncryptorUtils::CreateInstance(
void* library_handle) {
auto symbol_result = arrow::internal::GetSymbol(library_handle, "create_new_instance");
auto symbol_result =
::arrow::internal::GetSymbol(library_handle, "create_new_instance");
if (!symbol_result.ok()) {
ARROW_LOG(ERROR) << "Cannot load symbol 'create_new_instance()': "
<< symbol_result.status().message();
auto status = arrow::internal::CloseDynamicLibrary(library_handle);
auto status = ::arrow::internal::CloseDynamicLibrary(library_handle);

throw std::runtime_error("Failed to load symbol 'create_new_instance()': " +
symbol_result.status().message());
Expand All @@ -60,7 +61,7 @@ std::unique_ptr<DataBatchProtectionAgentInterface> LoadableEncryptorUtils::Creat

if (instance == nullptr) {
ARROW_LOG(ERROR) << "Cannot create instance of DataBatchProtectionAgentInterface";
auto status = arrow::internal::CloseDynamicLibrary(library_handle);
auto status = ::arrow::internal::CloseDynamicLibrary(library_handle);
throw std::runtime_error(
"Failed to create instance of DataBatchProtectionAgentInterface");
}
Expand All @@ -77,7 +78,8 @@ LoadableEncryptorUtils::LoadFromLibrary(const std::string& library_path) {
"LoadableEncryptorUtils::LoadFromLibrary: No library path provided");
}

auto library_handle_result = arrow::internal::LoadDynamicLibrary(library_path.c_str());
auto library_handle_result =
::arrow::internal::LoadDynamicLibrary(library_path.c_str());
if (!library_handle_result.ok()) {
throw std::runtime_error("Failed to load library: " +
library_handle_result.status().message());
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/parquet/encryption/external_dbpa_encryption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ ExternalDBPAEncryptorAdapter* ExternalDBPAEncryptorAdapterFactory::GetEncryptor(
auto key_metadata =
KeyMetadata::Parse(column_encryption_properties->key_metadata());
key_id = key_metadata.key_material().master_key_id();
} catch (const ParquetException& e) {
} catch (const ParquetException&) {
// It is possible for the key metadata to only contain the key id itself, so if
// it cannot be parsed as valid JSON, send the key id as string for the ExternalDBPA
// to process.
Expand Down Expand Up @@ -663,7 +663,7 @@ std::unique_ptr<DecryptorInterface> ExternalDBPADecryptorAdapterFactory::GetDecr
try {
auto key_metadata = KeyMetadata::Parse(crypto_metadata->key_metadata());
key_id = key_metadata.key_material().master_key_id();
} catch (const ParquetException& e) {
} catch (const ParquetException&) {
// It is possible for the key metadata to only contain the key id itself, so if
// it cannot be parsed as valid JSON, send the key id as string for the ExternalDBPA
// to process.
Expand Down
12 changes: 7 additions & 5 deletions cpp/src/parquet/encryption/external_dbpa_encryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
#include "parquet/encryption/encoding_properties.h"
#include "parquet/encryption/encryptor_interface.h"
#include "parquet/metadata.h"
#include "parquet/platform.h"
#include "parquet/types.h"

using dbps::external::DataBatchProtectionAgentInterface;

namespace parquet::encryption {

/// Call an external Data Batch Protection Agent (DBPA) to encrypt data.
class ExternalDBPAEncryptorAdapter : public EncryptorInterface {
class PARQUET_EXPORT ExternalDBPAEncryptorAdapter : public EncryptorInterface {
public:
static std::unique_ptr<ExternalDBPAEncryptorAdapter> Make(
ParquetCipher::type algorithm, std::string column_name, std::string key_id,
Expand Down Expand Up @@ -115,7 +116,7 @@ class ExternalDBPAEncryptorAdapter : public EncryptorInterface {
};

// Utilities for External DBPA adapters
class ExternalDBPAUtils {
class PARQUET_EXPORT ExternalDBPAUtils {
public:
// Convert Arrow KeyValueMetadata to a std::map<string, string>.
// Returns std::nullopt if the input is null or contains no pairs.
Expand All @@ -126,14 +127,15 @@ class ExternalDBPAUtils {
// Update encryptor-level metadata accumulator based on encoding attributes and
// EncryptionResult-provided metadata. If no metadata is available or page_type is
// unsupported/absent, function performs no-op.
PARQUET_EXPORT
void UpdateEncryptorMetadata(
std::map<int8_t, std::map<std::string, std::string>>& metadata_by_module,
const EncodingProperties& encoding_properties,
const dbps::external::EncryptionResult& result);

/// Factory for ExternalDBPAEncryptorAdapter instances. The cache exists while the write
/// operation is open, and is used to guarantee the lifetime of the encryptor.
class ExternalDBPAEncryptorAdapterFactory {
class PARQUET_EXPORT ExternalDBPAEncryptorAdapterFactory {
public:
ExternalDBPAEncryptorAdapter* GetEncryptor(
ParquetCipher::type algorithm,
Expand All @@ -146,7 +148,7 @@ class ExternalDBPAEncryptorAdapterFactory {

/// Call an external Data Batch Protection Agent (DBPA) to decrypt data.
/// connection configuration provided.
class ExternalDBPADecryptorAdapter : public DecryptorInterface {
class PARQUET_EXPORT ExternalDBPADecryptorAdapter : public DecryptorInterface {
public:
static std::unique_ptr<ExternalDBPADecryptorAdapter> Make(
ParquetCipher::type algorithm, std::string column_name, std::string key_id,
Expand Down Expand Up @@ -225,7 +227,7 @@ class ExternalDBPADecryptorAdapter : public DecryptorInterface {
};

/// Factory for ExternalDBPADecryptorAdapter instances. No cache exists for decryptors.
class ExternalDBPADecryptorAdapterFactory {
class PARQUET_EXPORT ExternalDBPADecryptorAdapterFactory {
public:
std::unique_ptr<DecryptorInterface> GetDecryptor(
ParquetCipher::type algorithm, const ColumnCryptoMetaData* crypto_metadata,
Expand Down
1 change: 1 addition & 0 deletions cpp/src/parquet/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ struct ParquetCipher {
/// Check whether a requested encryption algorithm is supported by the Parquet
/// library. Used in the crypto factory to validate the requested encryption
/// algorithm is available.
PARQUET_EXPORT
bool IsParquetCipherSupported(ParquetCipher::type cipher);

struct AadMetadata {
Expand Down
Loading