o
    ™¨Êh•  ã                   @   sÎ   d dl mZmZmZ d dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZ d dlmZmZ d dlmZ e dg d¢¡ZG d	d
„ d
eƒZdd„ Zdd„ Zdd„ ZG dd„ deƒZdd„ Ze ¡  eejƒ dS )é    )Úabsolute_importÚdivisionÚprint_functionN)Úutils)ÚInternalError)ÚffiÚlib)ÚCONDITIONAL_NAMESÚ_OpenSSLErrorWithText)Úcoder   ÚfuncÚreasonÚreason_textc                   @   sD   e Zd Zdd„ Zdd„ Ze d¡Ze d¡Ze d¡Z	e d¡Z
d	S )
Ú_OpenSSLErrorc                 C   s   || _ || _|| _|| _d S ©N)Ú_codeÚ_libÚ_funcÚ_reason)Úselfr   r   r   r   © r   ú^/var/www/html/env/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.pyÚ__init__   s   
z_OpenSSLError.__init__c                 C   s   || j ko	|| jkS r   )r   r   )r   r   r   r   r   r   Ú_lib_reason_match   s   z_OpenSSLError._lib_reason_matchr   r   r   r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r   Úread_only_propertyr   r   r   r   r   r   r   r   r      s    


r   c                 C   sP   g }	 |   ¡ }|dkr	 |S |  |¡}|  |¡}|  |¡}| t||||ƒ¡ q)NTr   )ÚERR_get_errorÚERR_GET_LIBÚERR_GET_FUNCÚERR_GET_REASONÚappendr   )r   Úerrorsr   Úerr_libÚerr_funcÚ
err_reasonr   r   r   Ú_consume_errors&   s   
ú

÷r'   c              	   C   sv   |s9t | ƒ}g }|D ]&}t dd¡}|  |j|t|ƒ¡ t |¡}| t|j|j	|j
|j|ƒ¡ q
td |¡|ƒ‚d S )Nzchar[]é   ai  Unknown OpenSSL error. This error is commonly encountered when another library is not cleaning up the OpenSSL error stack. If you are using cryptography with another library that uses OpenSSL try disabling it before reporting a bug. Otherwise please file an issue at https://github.com/pyca/cryptography/issues with information on how to reproduce this. ({0!r}))r'   r   ÚnewÚERR_error_string_nr   ÚlenÚstringr"   r
   r   r   r   r   Úformat)r   Úokr#   Úerrors_with_textÚerrÚbufÚerr_text_reasonr   r   r   Ú_openssl_assert6   s$   
ÿÿøòr3   c                 C   sj   t  d¡}| |_tƒ }| ¡ D ]\}}t| |ƒs| |ƒ ¡ qt| ƒD ]}||vr2t||t| |ƒƒ q#|S )Nr   )	ÚtypesÚ
ModuleTypeÚ_original_libÚsetÚitemsÚgetattrÚupdateÚdirÚsetattr)r   Úconditional_namesÚconditional_libÚexcluded_namesÚ	conditionÚnames_cbÚattrr   r   r   Úbuild_conditional_libraryQ   s   

€€rC   c                   @   sX   e Zd ZdZdZeZdZe ¡ Z	e ¡ Z
dd„ Zedd„ ƒZedd	„ ƒZed
d„ ƒZdS )ÚBindingz
    OpenSSL API wrapper.
    NFc                 C   s   |   ¡  d S r   )Ú_ensure_ffi_initialized)r   r   r   r   r   j   s   zBinding.__init__c                 C   s<   | j  ¡  | j j| _| j j| _| j  ¡ }t| j |dv ƒ d S )N)é   é   )r   ÚERR_clear_errorÚCryptography_osrandom_engine_idÚ_osrandom_engine_idÚ!Cryptography_osrandom_engine_nameÚ_osrandom_engine_nameÚ Cryptography_add_osrandom_enginer3   )ÚclsÚresultr   r   r   Ú_register_osrandom_enginem   s
   



z!Binding._register_osrandom_enginec                 C   sz   | j �0 | js+tttƒ| _d| _| j ¡  | j ¡  | j ¡  |  ¡  W d   ƒ d S W d   ƒ d S 1 s6w   Y  d S )NT)	Ú
_init_lockÚ_lib_loadedrC   r   r	   ÚSSL_library_initÚOpenSSL_add_all_algorithmsÚSSL_load_error_stringsrP   )rN   r   r   r   rE   z   s   



ö"ÿzBinding._ensure_ffi_initializedc                 C   s€   | j �3 |  ¡  tdƒ | jjr| j ¡ | jjkr"	 W d   ƒ d S t ¡ }t	| j|dkƒ W d   ƒ d S 1 s9w   Y  d S )NÚ_sslrF   )
Ú_lock_init_lockrE   Ú
__import__r   Ú"Cryptography_HAS_LOCKING_CALLBACKSÚCRYPTO_get_locking_callbackr   ÚNULLÚCryptography_setup_ssl_threadsr3   )rN   Úresr   r   r   Úinit_static_locksˆ   s   ø"ózBinding.init_static_locks)r   r   r   Ú__doc__r   r   rR   Ú	threadingÚLockrQ   rW   r   ÚclassmethodrP   rE   r^   r   r   r   r   rD   `   s    

rD   c                 C   s&   | j r| jst dtj¡ d S d S d S )Nz�OpenSSL version 1.0.1 is no longer supported by the OpenSSL project, please upgrade. A future version of cryptography will drop support for it.)Ú"CRYPTOGRAPHY_OPENSSL_LESS_THAN_102ÚCRYPTOGRAPHY_IS_LIBRESSLÚwarningsÚwarnr   ÚCryptographyDeprecationWarning)r   r   r   r   Ú_verify_openssl_versionš   s   ÿþüürh   )Ú
__future__r   r   r   Úcollectionsr`   r4   re   Úcryptographyr   Úcryptography.exceptionsr   Ú%cryptography.hazmat.bindings._opensslr   r   Ú1cryptography.hazmat.bindings.openssl._conditionalr	   Ú
namedtupler
   Úobjectr   r'   r3   rC   rD   rh   r^   r   r   r   r   Ú<module>   s(   ÿ: