o
    ÿÑÐb  ã                   @   sd   d dl Z ddlmZ ddlmZmZ ddlmZmZm	Z	 G dd„ deƒZ
G d	d
„ d
eƒZdd„ ZdS )é    Né   )ÚOctKey)ÚJWE_ALG_ALGORITHMSÚJWE_ENC_ALGORITHMSé   )ÚJWEAlgorithmÚJWEZipAlgorithmÚJsonWebEncryptionc                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
ÚDirectAlgorithmÚdirz$Direct use of a shared symmetric keyc                 C   s
   t  |¡S ©N)r   Z
import_key)ÚselfÚraw_data© r   úb/var/www/secure340b-portal/env/lib/python3.10/site-packages/authlib/jose/rfc7518/jwe_algorithms.pyÚprepare_key   s   
zDirectAlgorithm.prepare_keyc                 C   s.   |  d¡}t|ƒd |jkrtdƒ‚d|dœS )NZencrypté   úInvalid "cek" lengthó    )ÚekÚcek©Z
get_op_keyÚlenZCEK_SIZEÚ
ValueError)r   Úenc_algÚheadersÚkeyr   r   r   r   Úwrap   s   

zDirectAlgorithm.wrapc                 C   s(   |  d¡}t|ƒd |jkrtdƒ‚|S )NZdecryptr   r   r   )r   r   r   r   r   r   r   r   r   Úunwrap   s   
zDirectAlgorithm.unwrapN)Ú__name__Ú
__module__Ú__qualname__ÚnameÚdescriptionr   r   r   r   r   r   r   r
      s    r
   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚDeflateZipAlgorithmZDEFZDEFLATEc                 C   s   t  |¡}|dd… S )z+Compress bytes data with DEFLATE algorithm.r   éüÿÿÿ)ÚzlibÚcompress)r   ÚsÚdatar   r   r   r'      s   
zDeflateZipAlgorithm.compressc                 C   s   t  |t j ¡S )zDecompress DEFLATE bytes data.)r&   Ú
decompressÚ	MAX_WBITS)r   r(   r   r   r   r*   %   s   zDeflateZipAlgorithm.decompressN)r   r    r!   r"   r#   r'   r*   r   r   r   r   r$      s
    r$   c                  C   sD   t  tƒ ¡ t  tƒ ¡ tD ]} t  | ¡ qtD ]} t  | ¡ qd S r   )r	   Zregister_algorithmr
   r$   r   r   )Ú	algorithmr   r   r   Úregister_jwe_rfc7518*   s   ÿr-   )r&   Zoct_keyr   Z_cryptography_backendsr   r   Zrfc7516r   r   r	   r
   r$   r-   r   r   r   r   Ú<module>   s    