tolleybot commented on code in PR #34616:
URL: https://github.com/apache/arrow/pull/34616#discussion_r1346254087


##########
python/pyarrow/_dataset_parquet.pyx:
##########
@@ -56,9 +63,180 @@ from pyarrow._parquet cimport (
 
 cdef Expression _true = Expression._scalar(True)
 
-
 ctypedef CParquetFileWriter* _CParquetFileWriterPtr
 
+IF PARQUET_ENCRYPTION_ENABLED:
+    cdef class ParquetEncryptionConfig(_Weakrefable):
+        """
+        Core configuration class encapsulating parameters for high-level 
encryption
+        within the Parquet framework.
+
+        The ParquetEncryptionConfig class serves as a bridge for passing 
encryption-related
+        parameters to the appropriate components within the Parquet library. 
It maintains references
+        to objects that define the encryption strategy, Key Management Service 
(KMS) configuration,
+        and specific encryption configurations for Parquet data.
+
+        Parameters
+        ----------
+        crypto_factory : pyarrow.parquet.encryption.CryptoFactory
+            Shared pointer to a `CryptoFactory` object. The `CryptoFactory` is 
responsible for
+            creating cryptographic components, such as encryptors and 
decryptors.
+        kms_connection_config : pyarrow.parquet.encryption.KmsConnectionConfig
+            Shared pointer to a `KmsConnectionConfig` object. This object 
holds the configuration
+            parameters necessary for connecting to a Key Management Service 
(KMS).
+        encryption_config : pyarrow.parquet.encryption.EncryptionConfiguration
+            Shared pointer to an `EncryptionConfiguration` object. This object 
defines specific
+            encryption settings for Parquet data, including the keys assigned 
to different columns.
+
+        Raises
+        ------
+        ValueError
+            Raised if `encryption_config` is None.
+        """
+        cdef:
+            shared_ptr[CParquetEncryptionConfig] c_config
+
+        # Avoid mistakenly creating attributes
+        __slots__ = ()
+
+        def __cinit__(self, CryptoFactory crypto_factory, KmsConnectionConfig 
kms_connection_config,
+                      EncryptionConfiguration encryption_config):
+
+            cdef shared_ptr[CEncryptionConfiguration] c_encryption_config
+
+            if crypto_factory is None:
+                raise ValueError("crypto_factory cannot be None")
+
+            if kms_connection_config is None:
+                raise ValueError("kms_connection_config cannot be None")
+
+            if encryption_config is None:
+                raise ValueError("encryption_config cannot be None")
+
+            self.c_config.reset(new CParquetEncryptionConfig())
+
+            c_encryption_config = 
ParquetEncryptionConfig.unwrap_encryptionconfig(
+                encryption_config)
+
+            self.c_config.get().crypto_factory = 
ParquetEncryptionConfig.unwrap_cryptofactory(crypto_factory)
+            self.c_config.get().kms_connection_config = 
ParquetEncryptionConfig.unwrap_kmsconnectionconfig(
+                kms_connection_config)
+            self.c_config.get().encryption_config = c_encryption_config
+
+        @staticmethod
+        cdef wrap(shared_ptr[CParquetEncryptionConfig] c_config):
+            cdef ParquetEncryptionConfig python_config = 
ParquetEncryptionConfig.__new__(ParquetEncryptionConfig)
+            python_config.c_config = c_config
+            return python_config
+
+        cdef shared_ptr[CParquetEncryptionConfig] unwrap(self):
+            return self.c_config
+
+        @staticmethod
+        cdef shared_ptr[CCryptoFactory] unwrap_cryptofactory(object 
crypto_factory) except *:
+            if isinstance(crypto_factory, CryptoFactory):
+                pycf = (<CryptoFactory> crypto_factory).unwrap()
+                return static_pointer_cast[CCryptoFactory, 
CPyCryptoFactory](pycf)
+            raise TypeError("Expected CryptoFactory, got %s" % 
type(crypto_factory))
+
+        @staticmethod
+        cdef shared_ptr[CKmsConnectionConfig] 
unwrap_kmsconnectionconfig(object kmsconnectionconfig):
+            if isinstance(kmsconnectionconfig, KmsConnectionConfig):
+                return (<KmsConnectionConfig> kmsconnectionconfig).unwrap()
+            raise TypeError("Expected KmsConnectionConfig, got %s" %
+                            type(kmsconnectionconfig))
+
+        @staticmethod
+        cdef shared_ptr[CEncryptionConfiguration] 
unwrap_encryptionconfig(object encryptionconfig):
+            if isinstance(encryptionconfig, EncryptionConfiguration):
+                return (<EncryptionConfiguration> encryptionconfig).unwrap()
+            raise TypeError("Expected EncryptionConfiguration, got %s" %
+                            type(encryptionconfig))
+
+    cdef class ParquetDecryptionConfig(_Weakrefable):
+        """
+        Core configuration class encapsulating parameters for high-level 
decryption
+        within the Parquet framework.
+
+        ParquetDecryptionConfig is designed to pass decryption-related 
parameters to
+        the appropriate decryption components within the Parquet library. It 
holds references to
+        objects that define the decryption strategy, Key Management Service 
(KMS) configuration,
+        and specific decryption configurations for reading encrypted Parquet 
data.
+
+        Parameters
+        ----------
+        crypto_factory : pyarrow.parquet.encryption.CryptoFactory
+            Shared pointer to a `CryptoFactory` object, pivotal in creating 
cryptographic
+            components for the decryption process.
+        kms_connection_config : pyarrow.parquet.encryption.KmsConnectionConfig
+            Shared pointer to a `KmsConnectionConfig` object, containing 
parameters necessary
+            for connecting to a Key Management Service (KMS) during decryption.
+        decryption_config : pyarrow.parquet.encryption.DecryptionConfiguration
+            Shared pointer to a `DecryptionConfiguration` object, specifying 
decryption settings
+            for reading encrypted Parquet data.
+
+        Raises
+        ------
+        ValueError
+            Raised if `decryption_config` is None.
+        """
+
+        cdef:
+            shared_ptr[CParquetDecryptionConfig] c_config
+
+        # Avoid mistakingly creating attributes
+        __slots__ = ()
+
+        def __cinit__(self, CryptoFactory crypto_factory, KmsConnectionConfig 
kms_connection_config,
+                      DecryptionConfiguration decryption_config):
+
+            cdef shared_ptr[CDecryptionConfiguration] c_decryption_config
+
+            if decryption_config is None:
+                raise ValueError(
+                    "decryption_config cannot be None")
+
+            self.c_config.reset(new CParquetDecryptionConfig())
+
+            c_decryption_config = 
ParquetDecryptionConfig.unwrap_decryptionconfig(
+                decryption_config)
+
+            self.c_config.get().crypto_factory = 
ParquetDecryptionConfig.unwrap_cryptofactory(crypto_factory)
+            self.c_config.get().kms_connection_config = 
ParquetDecryptionConfig.unwrap_kmsconnectionconfig(
+                kms_connection_config)
+            self.c_config.get().decryption_config = c_decryption_config
+
+        @staticmethod
+        cdef wrap(shared_ptr[CParquetDecryptionConfig] c_config):
+            cdef ParquetDecryptionConfig python_config = 
ParquetDecryptionConfig.__new__(ParquetDecryptionConfig)
+            python_config.c_config = c_config
+            return python_config
+
+        cdef shared_ptr[CParquetDecryptionConfig] unwrap(self):
+            return self.c_config
+
+        @staticmethod
+        cdef shared_ptr[CCryptoFactory] unwrap_cryptofactory(object 
crypto_factory) except *:
+            if isinstance(crypto_factory, CryptoFactory):
+                pycf = (<CryptoFactory> crypto_factory).unwrap()
+                return static_pointer_cast[CCryptoFactory, 
CPyCryptoFactory](pycf)
+            raise TypeError("Expected CryptoFactory, got %s" % 
type(crypto_factory))
+
+        @staticmethod
+        cdef shared_ptr[CKmsConnectionConfig] 
unwrap_kmsconnectionconfig(object kmsconnectionconfig) except *:
+            if isinstance(kmsconnectionconfig, KmsConnectionConfig):
+                return (<KmsConnectionConfig> kmsconnectionconfig).unwrap()
+            raise TypeError("Expected KmsConnectionConfig, got %s" %
+                            type(kmsconnectionconfig))
+
+        @staticmethod
+        cdef shared_ptr[CDecryptionConfiguration] 
unwrap_decryptionconfig(object decryptionconfig) except *:
+            if isinstance(decryptionconfig, DecryptionConfiguration):
+                return (<DecryptionConfiguration> decryptionconfig).unwrap()
+
+            raise TypeError("Expected DecryptionConfiguration, got %s" %
+                            type(decryptionconfig))

Review Comment:
   Ok



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to