U
    -e	                     @   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	   a/var/www/html/Darija-Ai-Train/env/lib/python3.8/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   sN   | j | }t|}|dd }|dd }||dkr>|S td||dS )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   s0   t | d}|d}|dks"tW 5 Q R X 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AssertionError)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    