3 L]@sddlmZmZmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZddlmZejddd d d d gZGd ddeZddZddZddZGdddeZddZddZeejejeejdS))absolute_importdivisionprint_functionN)utils) InternalError)ffilib)CONDITIONAL_NAMES_OpenSSLErrorWithTextcoderfuncreasonZ reason_textc@sDeZdZddZddZejdZejdZejdZ ejdZ d S) _OpenSSLErrorcCs||_||_||_||_dS)N)_code_lib_func_reason)selfr rr r rV/tmp/pip-install-wfra5znf/cryptography/cryptography/hazmat/bindings/openssl/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_REASONappendr)rerrorsr Zerr_libZerr_funcZ err_reasonrrr_consume_errors's   rcCsz|svt|}g}xT|D]L}tjdd}|j|j|t|tj|}|jt|j|j |j |j |qWt dj ||dS)Nzchar[]aiUnknown 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}))rrnewZERR_error_string_nr lenstringrr rr r rformat)rokrZerrors_with_texterrbufZerr_text_reasonrrr_openssl_assert7s   r&cCsrtjd}||_t}x*|jD]\}}t||s |j|q Wx*t|D]}||krLt||t||qLW|S)Nr) types ModuleTypeZ _original_libsetitemsgetattrupdatedirsetattr)rZconditional_namesZconditional_libZexcluded_names conditionZnames_cbattrrrrbuild_conditional_libraryRs  r1c@sXeZdZdZdZeZdZejZ ejZ ddZ e ddZ e dd Ze d d ZdS) Bindingz OpenSSL API wrapper. NFcCs |jdS)N)_ensure_ffi_initialized)rrrrrkszBinding.__init__cCs0|jj|jjr,|jj}t|j|dkdS)N)r4r5)rZERR_clear_errorZCryptography_HAS_ENGINEZ Cryptography_add_osrandom_enginer&)clsresultrrr_register_osrandom_enginens  z!Binding._register_osrandom_enginec CsT|jD|jsFttt|_d|_|jj|jj|jj|jWdQRXdS)NT) _init_lock _lib_loadedr1rr ZSSL_library_initZOpenSSL_add_all_algorithmsZSSL_load_error_stringsr8)r6rrrr3zs    zBinding._ensure_ffi_initializedc Cs^|jN|jtd|jj s4|jj|jjkr8dStj}t |j|dkWdQRXdS)N_sslr4) _lock_init_lockr3 __import__rZ"Cryptography_HAS_LOCKING_CALLBACKSZCRYPTO_get_locking_callbackrZNULLZCryptography_setup_ssl_threadsr&)r6resrrrinit_static_lockss zBinding.init_static_locks)rrr__doc__rrr: threadingLockr9r<r classmethodr8r3r?rrrrr2as r2cCs |jr|j rtjdtjdS)NzOpenSSL version 1.0.1 is no longer supported by the OpenSSL project, please upgrade. A future version of cryptography will drop support for it.)Z"CRYPTOGRAPHY_OPENSSL_LESS_THAN_102ZCRYPTOGRAPHY_IS_LIBRESSLwarningswarnrZCryptographyDeprecationWarning)rrrr_verify_openssl_versions rFcCs.tjtj}|jd|kr*tdj||dS)NasciiaThe 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_VERSIONencode ImportErrorr")versionZso_package_versionrrr_verify_package_versions  rK) __future__rrr collectionsrAr'rDZ cryptographyrZcryptography.exceptionsrZ%cryptography.hazmat.bindings._opensslrrZ1cryptography.hazmat.bindings.openssl._conditionalr namedtupler objectrrr&r1r2rFrK __version__r?rrrrs*   9