o
    䯪g	                     @   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__custom_kms_confmaster_keys_map)selfconfig r
   \/var/www/html/chatdoc2/venv/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   expected_master_keydecoded_wrapped_keyr   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file	magic_strr
   r
   r   verify_file_encrypted6   s   
"r+   )r   pyarrow.parquet.encryptionparquet
encryptionr   r   r   r+   r
   r
   r
   r   <module>   s    