
    g	                     N    d dl Z d dlmc mZ  G d dej
                        Zd Zy)    Nc                   "    e Zd ZdZd Zd Zd Zy)InMemoryKmsClientzRThis is a mock class implementation of KmsClient, built for testing
    only.
    c                 d    t         j                  j                  |        |j                  | _        y)z%Create an InMemoryKmsClient instance.N)pe	KmsClient__init__custom_kms_confmaster_keys_map)selfconfigs     U/var/www/openai/venv/lib/python3.12/site-packages/pyarrow/tests/parquet/encryption.pyr   zInMemoryKmsClient.__init__   s"    
d#%55    c                     | j                   |   j                  d      }dj                  ||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    sM      //0EFMMhh 0)<=!!+.r   c                     | j                   |   }t        j                  |      }|dd }|dd }||j                  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)   so     #223HI$..{;.s3+BC0#3#:#:7#CC  4)=: 	:r   N)__name__
__module____qualname____doc__r   r   r#    r   r   r   r      s    6

:r   r   c                 x    t        | d      5 }|j                  d      }|dk(  sJ 	 ddd       y# 1 sw Y   yxY w)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   s7     
dD	TIIaL	G### 
		s   09)r   pyarrow.parquet.encryptionparquet
encryptionr   r   r   r1   r(   r   r   <module>r5      s&   "  ' ': :@$r   