o
    Zh	                     @   s8   d dl Z d dlm  mZ G dd dejZdd ZdS )    Nc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	InMemoryKmsClientzRThis is a mock class implementation of KmsClient, built for testing
    only.
    c                 C   s   t j|  |j| _dS )z%Create an InMemoryKmsClient instance.N)pe	KmsClient__init__Zcustom_kms_confmaster_keys_map)selfconfig r	   W/var/www/html/lang_env/lib/python3.10/site-packages/pyarrow/tests/parquet/encryption.pyr      s   zInMemoryKmsClient.__init__c                 C   s,   | j | d}d||g}t|}|S )z`Not a secure cipher - the wrapped key
        is just the master key concatenated with key bytesutf-8    )r   encodejoinbase64	b64encode)r   	key_bytesmaster_key_identifiermaster_key_byteswrapped_keyresultr	   r	   r
   wrap_key    s   

zInMemoryKmsClient.wrap_keyc                 C   sJ   | j | }t|}|dd }|dd }||dkr|S td||)zGNot a secure cipher - just extract the key from
        the wrapped keyN   r   zIncorrect master key used)r   r   	b64decodedecode
ValueError)r   r   r   Zexpected_master_keyZdecoded_wrapped_keyr   Zdecrypted_keyr	   r	   r
   
unwrap_key)   s   

zInMemoryKmsClient.unwrap_keyN)__name__
__module____qualname____doc__r   r   r   r	   r	   r	   r
   r      s
    	r   c                 C   sF   t | d}|d}|dksJ W d   dS 1 sw   Y  dS )zVerify that the file is encrypted by looking at its first 4 bytes.
    If it's the magic string PARE
    then this is a parquet with encrypted footer.rb   s   PAREN)openread)pathfileZ	magic_strr	   r	   r
   verify_file_encrypted6   s   
"r&   )r   Zpyarrow.parquet.encryptionZparquetZ
encryptionr   r   r   r&   r	   r	   r	   r
   <module>   s    