o
    ‹¨Êh‰  ã                   @   s”   d dl mZ d dlZd dlZzd dlmZ W n	 ey   Y nw d dlmZ d dlm	Z	 dd„ Z
G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZdS )é    )Úabsolute_importN)Úkeyczar)ÚCrypter)Úerrorsc                  C   s8   t  ¡ �} tj W d   ƒ n1 sw   Y  t| ƒ S ©N)r   ÚExceptionRaisedContextr   Ú__name__Úbool)Úexc© r   úF/var/www/html/env/lib/python3.10/site-packages/keyrings/alt/keyczar.pyÚhas_keyczar   s   
ÿ
r   c                   @   sH   e Zd ZdZejdd„ ƒZejdd„ ƒZedd„ ƒZ	dd	„ Z
d
d„ ZdS )ÚBaseCrypterzpBase Keyczar keyset encryption and decryption.
       The keyset initialisation is deferred until required.
    c                 C   ó   dS )z9Location for the main keyset that may be encrypted or notNr   ©Úselfr   r   r   Úkeyset_location   s   zBaseCrypter.keyset_locationc                 C   r   )zrLocation for the encrypting keyset.
           Use None to indicate that the main keyset is not encrypted
        Nr   r   r   r   r   Úencrypting_keyset_location   s   z&BaseCrypter.encrypting_keyset_locationc                 C   sZ   t | dƒs*| jstdƒ‚tj | j¡}| jr$tj | j¡}tj 	||¡}t |¡| _
| j
S )zThe actual keyczar crypterÚ_crypterzNo encrypted keyset location!)Úhasattrr   Ú
ValueErrorr   ÚreadersÚCreateReaderr   r   ÚReadÚEncryptedReaderr   )r   ÚreaderÚencrypting_keyczarr   r   r   Úcrypter&   s   
ÿÿzBaseCrypter.crypterc                 C   ó   |sdS | j  |¡S )zEncrypt the value.
        Ú )r   ÚEncrypt©r   Úvaluer   r   r   Úencrypt6   ó   zBaseCrypter.encryptc                 C   r   )zDecrypt the value.
        r   )r   ÚDecryptr!   r   r   r   Údecrypt=   r$   zBaseCrypter.decryptN)r   Ú
__module__Ú__qualname__Ú__doc__ÚabcÚabstractpropertyr   r   Úpropertyr   r#   r&   r   r   r   r   r      s    


r   c                   @   s2   e Zd ZdZd	dd„Zedd„ ƒZedd„ ƒZdS )
r   zCA Keyczar crypter using locations specified in the constructor
    Nc                 C   s   || _ || _d S r   )Ú_keyset_locationÚ_encrypting_keyset_location)r   r   r   r   r   r   Ú__init__I   s   
zCrypter.__init__c                 C   ó   | j S r   )r-   r   r   r   r   r   M   ó   zCrypter.keyset_locationc                 C   r0   r   )r.   r   r   r   r   r   Q   r1   z"Crypter.encrypting_keyset_locationr   )r   r'   r(   r)   r/   r,   r   r   r   r   r   r   r   E   s    

r   c                   @   s0   e Zd ZdZdZdZedd„ ƒZedd„ ƒZdS )	ÚEnvironCrypterzDA Keyczar crypter using locations specified by environment vars
    Ú"KEYRING_KEYCZAR_ENCRYPTED_LOCATIONÚ#KEYRING_KEYCZAR_ENCRYPTING_LOCATIONc                 C   s$   t j | j¡}|std| j ƒ‚|S )Nz%s environment value not set)ÚosÚenvironÚgetÚKEYSET_ENV_VARr   )r   Úvalr   r   r   r   ]   s   ÿzEnvironCrypter.keyset_locationc                 C   s   t j | j¡S r   )r5   r6   r7   ÚENC_KEYSET_ENV_VARr   r   r   r   r   e   s   z)EnvironCrypter.encrypting_keyset_locationN)	r   r'   r(   r)   r8   r:   r,   r   r   r   r   r   r   r2   V   s    
r2   )Ú
__future__r   r5   r*   r   ÚImportErrorÚkeyring.backendr   Úkeyringr   r   r   r2   r   r   r   r   Ú<module>   s    ÿ0