
    z-Ph	                     L    d dl Z d dlmc mZ  G d dej                  Zd ZdS )    Nc                   $    e Zd ZdZd Zd Zd ZdS )InMemoryKmsClientzRThis is a mock class implementation of KmsClient, built for testing
    only.
    c                 \    t           j                            |            |j        | _        dS )z%Create an InMemoryKmsClient instance.N)pe	KmsClient__init__custom_kms_confmaster_keys_map)selfconfigs     `/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyarrow/tests/parquet/encryption.pyr   zInMemoryKmsClient.__init__   s)    
d###%5    c                     | j         |                             d          }d                    ||g          }t          j        |          }|S )z`Not a secure cipher - the wrapped key
        is just the master key concatenated with key bytesutf-8r   )r
   encodejoinbase64	b64encode)r   	key_bytesmaster_key_identifiermaster_key_byteswrapped_keyresults         r   wrap_keyzInMemoryKmsClient.wrap_key    sR      /0EFMM hh 0)<==!+..r   c                     | j         |         }t          j        |          }|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_keys          r   
unwrap_keyzInMemoryKmsClient.unwrap_key)   s{     #23HI$.{;;.ss3+BCC0#3#:#:7#C#CCC  4)=: : 	:r   N)__name__
__module____qualname____doc__r   r   r#    r   r   r   r      sK         6 6 6
  
: 
: 
: 
: 
:r   r   c                     t          | d          5 }|                    d          }|dk    sJ 	 ddd           dS # 1 swxY 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_strs      r   verify_file_encryptedr1   6   s     
dD		 $TIIaLL	G#####$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   =AA)r   pyarrow.parquet.encryptionparquet
encryptionr   r   r   r1   r(   r   r   <module>r5      sq   "  ' ' ' ' ' ' ' ' ': : : : : : : :@$ $ $ $ $r   