3 y�_ �@sddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddl mZmZddlmZejddd d d d g�ZGd d�de�Zdd�Zdd�Zdd�Zddd�Zdd�ZGdd�de�Zdd�Zdd�Zee j�ej�eej�dS) �)�absolute_import�division�print_functionN)�utils)� InternalError)�ffi�lib)�CONDITIONAL_NAMES�_OpenSSLErrorWithText�coder�func�reasonZ reason_textc@sDeZdZdd�Zdd�Zejd�Zejd�Zejd�Z ejd�Z d S) � _OpenSSLErrorcCs||_||_||_||_dS)N)�_code�_lib�_func�_reason)�selfr rr r �r�/usr/lib64/python3.6/binding.py�__init__sz_OpenSSLError.__init__cCs||jko||jkS)N)rr )rrr rrr�_lib_reason_matchsz_OpenSSLError._lib_reason_matchrrrrN) �__name__� __module__� __qualname__rrrZread_only_propertyr rr r rrrrrs    rcCsRg}xH|j�}|dkrP|j|�}|j|�}|j|�}|jt||||��qW|S)Nr)Z ERR_get_errorZ ERR_GET_LIBZ ERR_GET_FUNCZERR_GET_REASON�appendr)r�errorsr Zerr_libZerr_funcZ err_reasonrrr�_consume_errors(s   rcCs^g}xT|D]L}tjdd�}tj|j|t|��tj|�}|jt|j|j|j |j |��q W|S)Nzchar[]�) r�newrZERR_error_string_nr �len�stringrr r r )r�errors_with_text�errZbufZerr_text_reasonrrr�_errors_with_text8s   r$cCs tt|��S)N)r$r)rrrr�_consume_errors_with_textHsr%cCs0|s,|dkrt|�}t|�}tdj|�|��dS)NaiUnknown 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}))rr$r�format)r�okrr"rrr�_openssl_assertLsr(cCsrtjd�}||_t�}x*|j�D]\}}t||�s |j|��q Wx*t|�D]}||krLt||t||��qLW|S)Nr) �types� ModuleTypeZ _original_lib�set�items�getattr�update�dir�setattr)rZconditional_namesZconditional_libZexcluded_namesZ conditionZnames_cb�attrrrr�build_conditional_library^s  r2c@sXeZdZdZdZeZdZej�Z ej�Z dd�Z e dd��Z e dd ��Ze d d ��ZdS) �Bindingz OpenSSL API wrapper. NFcCs |j�dS)N)�_ensure_ffi_initialized)rrrrrxszBinding.__init__cCs0|jj�|jjr,|jj�}t|j|dk�dS)N��)r5r6)rZERR_clear_errorZ"CRYPTOGRAPHY_NEEDS_OSRANDOM_ENGINEZ Cryptography_add_osrandom_enginer()�cls�resultrrr�_register_osrandom_engine{s  z!Binding._register_osrandom_enginec CsT|j�D|jsFttt�|_d|_|jj�|jj�|jj�|j�WdQRXdS)NT) � _init_lock� _lib_loadedr2rr ZSSL_library_initZOpenSSL_add_all_algorithmsZSSL_load_error_stringsr9)r7rrrr4�s    zBinding._ensure_ffi_initializedc Cs^|j�N|j�td�|jj s4|jj�|jjkr8dStj�}t |j|dk�WdQRXdS)NZ_sslr5) �_lock_init_lockr4� __import__rZ"Cryptography_HAS_LOCKING_CALLBACKSZCRYPTO_get_locking_callbackrZNULLZCryptography_setup_ssl_threadsr()r7�resrrr�init_static_locks�s zBinding.init_static_locks)rrr�__doc__rrr;� threadingZLockr:r<r� classmethodr9r4r?rrrrr3ms r3cCs6|jr2|j r2tjjd�r*tjdtj�nt d��dS)NZCRYPTOGRAPHY_ALLOW_OPENSSL_102z�OpenSSL version 1.0.2 is no longer supported by the OpenSSL project, please upgrade. The next version of cryptography will completely remove support for it.a)You are linking against OpenSSL 1.0.2, which is no longer supported by the OpenSSL project. To use this version of cryptography you need to upgrade to a newer version of OpenSSL. For this version only you can also set the environment variable CRYPTOGRAPHY_ALLOW_OPENSSL_102 to allow OpenSSL 1.0.2.) Z"CRYPTOGRAPHY_OPENSSL_LESS_THAN_110ZCRYPTOGRAPHY_IS_LIBRESSL�os�environ�get�warnings�warnrZCryptographyDeprecationWarning� RuntimeError)rrrr�_verify_openssl_version�s  rIcCs.tjtj�}|jd�|kr*tdj||���dS)N�asciiaThe version of cryptography does not match the loaded shared object. This can happen if you have multiple copies of cryptography installed in your Python path. Please try creating a new virtual environment to resolve this issue. Loaded python version: {}, shared object version: {})rr!rZCRYPTOGRAPHY_PACKAGE_VERSION�encode� ImportErrorr&)�versionZso_package_versionrrr�_verify_package_version�s  rN)N) Z __future__rrr� collectionsrCrAr)rFZ cryptographyrZcryptography.exceptionsrZ%cryptography.hazmat.bindings._opensslrrZ1cryptography.hazmat.bindings.openssl._conditionalr � namedtupler �objectrrr$r%r(r2r3rIrN� __version__r?rrrr�s0    <