o
    6Îh°  ã                   @   s2   d dl mZmZ G dd„ dƒZG dd„ deƒZdS )é   )Úbase64url_encodeÚensure_binaryc                   @   sd   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	ddd„Z
ddd„Zdd„ Zdd„ ZdS )ÚKeyz7
    A simple interface for implementing JWK keys.
    c                 C   s   d S ©N© )ÚselfÚkeyÚ	algorithmr   r   úf/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/jose/backends/base.pyÚ__init__	   s   zKey.__init__c                 C   ó   t ƒ ‚r   ©ÚNotImplementedError)r   Úmsgr   r   r
   Úsign   ó   zKey.signc                 C   r   r   r   )r   r   Úsigr   r   r
   Úverify   r   z
Key.verifyc                 C   r   r   r   ©r   r   r   r
   Ú
public_key   r   zKey.public_keyc                 C   r   r   r   r   r   r   r
   Úto_pem   r   z
Key.to_pemc                 C   r   r   r   r   r   r   r
   Úto_dict   r   zKey.to_dictNc                 C   r   )aI  
        Encrypt the plain text and generate an auth tag if appropriate

        Args:
            plain_text (bytes): Data to encrypt
            aad (bytes, optional): Authenticated Additional Data if key's algorithm supports auth mode

        Returns:
            (bytes, bytes, bytes): IV, cipher text, and auth tag
        r   )r   Ú
plain_textÚaadr   r   r
   Úencrypt   s   zKey.encryptc                 C   r   )ay  
        Decrypt the cipher text and validate the auth tag if present
        Args:
            cipher_text (bytes): Cipher text to decrypt
            iv (bytes): IV if block mode
            aad (bytes): Additional Authenticated Data to verify if auth mode
            tag (bytes): Authentication tag if auth mode

        Returns:
            bytes: Decrypted value
        r   )r   Úcipher_textÚivr   Útagr   r   r
   Údecrypt(   s   zKey.decryptc                 C   r   )z¡
        Wrap the the plain text key data

        Args:
            key_data (bytes): Key data to wrap

        Returns:
            bytes: Wrapped key
        r   )r   Úkey_datar   r   r
   Úwrap_key6   ó   
zKey.wrap_keyc                 C   r   )z¯
        Unwrap the the wrapped key data

        Args:
            wrapped_key (bytes): Wrapped key data to unwrap

        Returns:
            bytes: Unwrapped key
        r   )r   Úwrapped_keyr   r   r
   Ú
unwrap_keyB   r!   zKey.unwrap_keyr   )NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r    r#   r   r   r   r
   r      s    

r   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚDIRKeyc                 C   s   t |ƒ| _|| _d S r   )r   Ú_keyÚ_alg)r   r   r	   r   r   r
   r   P   s   

zDIRKey.__init__c                 C   s   | j dt| jƒdœS )NÚoct)ÚalgÚktyÚk)r*   r   r)   r   r   r   r
   r   T   s   ýzDIRKey.to_dictN)r$   r%   r&   r   r   r   r   r   r
   r(   O   s    r(   N)Úutilsr   r   r   r(   r   r   r   r
   Ú<module>   s    K