o
    Zh                     @   s  d dl mZ d dlmZ d dlZd dlZdZzd dlm	Z
 W n ey)   dZ
Y nw zd dlmZ d dlm  mZ W n eyF   dZY nw ejj	ZdZdZdZd	Zd
d Zdd Zdd Zdd Zdd Zejjedddd Zejje dddd ZdS )    )	timedeltaNFInMemoryKmsClientTs   0123456789112345
footer_keys   1234567890123450Zcol_keyc                   C   s   t g dg dg ddS )N)i      r   i  r   )   r      r	      d   )ZFlamingoZParrotZDogZHorsezBrittle starsZ	Centipede)yearn_legsanimal)patable r   r   \/var/www/html/lang_env/lib/python3.10/site-packages/pyarrow/tests/test_dataset_encryption.pycreate_sample_table/   s   r   c                   C   s$   t jtdtddgidtddddS )	NFr   r   Z
AES_GCM_V1g      @)minutes   )r   Zplaintext_footerZcolumn_keysZencryption_algorithmcache_lifetimeZdata_key_length_bits)peZEncryptionConfigurationFOOTER_KEY_NAMECOL_KEY_NAMEr   r   r   r   r   create_encryption_config@   s   
r   c                   C   s   t jddS )Ni,  )r   )r   ZDecryptionConfigurationr   r   r   r   create_decryption_configL   s   r   c                   C   s    t jttdttdidS )NzUTF-8)Zcustom_kms_conf)r   ZKmsConnectionConfigr   
FOOTER_KEYdecoder   COL_KEYr   r   r   r   create_kms_connection_configP   s
   

r   c                 C   s   t | S )Nr   )Zkms_connection_configurationr   r   r   kms_factoryY   s   r    z+Parquet Encryption is not currently enabled)reasonc                  C   s  t  } t }t }t }tt}t|||}t	|||}t
j }|j|d}t }	|	d tj| d|||	d t
j }tjtdd tjd||	d W d    n1 s\w   Y  tj|d}
t
jj|
d	}tjd||	d}| | sJ d S )
Nencryption_config/Zsample_dataset)database_dirformatZfile_options
filesystemzno decryption)match)r'   r(   )decryption_config)Zdefault_fragment_scan_options)r   r   r   r   r   ZCryptoFactoryr    dsZParquetEncryptionConfigZParquetDecryptionConfigr   datasetParquetFileFormatmake_write_optionsfsZ_MockFileSystemZ
create_dirZwrite_datasetpytestraisesIOErrorZParquetFragmentScanOptionsequalsZto_table)r   r#   r*   Zkms_connection_configZcrypto_factoryZparquet_encryption_cfgZparquet_decryption_cfgpformatZwrite_optionsZmockfsZpq_scan_optsr,   r   r   r   "test_dataset_encryption_decryption]   s@   



	r5   z'Parquet Encryption is currently enabledc                  C   sF   t j } tt | jdd}W d   dS 1 sw   Y  dS )zTest write_dataset with ParquetFileFormat and test if an exception is thrown
    if you try to set encryption_config using make_write_optionsz
some valuer"   N)r   r,   r-   r0   r1   NotImplementedErrorr.   )r4   _r   r   r   -test_write_dataset_parquet_without_encryption   s   
	"r8   ) datetimer   Z
pyarrow.fsr/   Zpyarrowr   r0   Zencryption_unavailableZpyarrow.datasetr,   r+   ImportErrorZ pyarrow.tests.parquet.encryptionr   Zpyarrow.parquet.encryptionZparquetZ
encryptionr   markZ
pytestmarkr   r   r   r   r   r   r   r   r    Zskipifr5   r8   r   r   r   r   <module>   sD   	
-