o
    Œõ±jÊ  ã                   @   s  d dl mZmZmZmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ eƒ dkr2ddlmZmZmZ n
ddlmZmZmZ g d	¢Zd
Zd
dgZedk rNe ¡  e e
ƒ ¡ dZedkrqe e
ƒ d d¡¡roe e
ƒ d d¡¡ ndZdd„ Zddd„Zdd„ ZG dd„ dƒZ dS )é    )Úunicode_literalsÚdivisionÚabsolute_importÚprint_functioné   )Úffi)Úbuffer_from_bytesÚbyte_string_from_bufferÚnull)Ústr_clsÚcffié   )Ú	libcryptoÚversionÚversion_info)Úhandle_openssl_errorr   Úlibcrypto_legacy_supportÚlibcrypto_versionÚlibcrypto_version_infoÚLibcryptoConstÚpeek_openssl_errorzutf-8Úcp1252)r   r   T)é   ÚlegacyÚasciiFc                 C   s`   zt | tƒW S  ty)   tD ]}zt | |dd�W    Y S  ty&   Y qw Y nw t | dd�S )NÚstrict)ÚerrorsÚreplace)r   Ú	_encodingÚUnicodeDecodeErrorÚ_fallback_encodings)ÚvalueÚencoding© r#   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/oscrypto/_openssl/_libcrypto.pyÚ_try_decode5   s   ÿýÿr%   Nc                 C   sH   | dkrdS |du rt }t ¡ }tdƒ}t ||¡ t|ƒ}|t|ƒƒ‚)ah  
    Checks if an error occurred, and if so throws an OSError containing the
    last OpenSSL error message

    :param result:
        An integer result code - 1 or greater indicates success

    :param exception_class:
        The exception class to use for the exception if an error occurred

    :raises:
        OSError - when an OpenSSL error occurs
    r   Néx   )ÚOSErrorr   ÚERR_get_errorr   ÚERR_error_stringr	   r%   )ÚresultÚexception_classÚ	error_numÚbufferÚerror_stringr#   r#   r$   r   F   s   r   c                  C   sh   t  ¡ } tdk rt| d? d@ ƒ}t| d? d@ ƒ}t| d@ ƒ}nt| d? d@ ƒ}d}t| d@ ƒ}|||fS )	z—
    Peeks into the error stack and pulls out the lib, func and reason

    :return:
        A three-element tuple of integers (lib, func, reason)
    )r   r   é   éÿ   é   iÿ  é   r   iÿÿ )r   ÚERR_peek_errorr   Úint)ÚerrorÚlibÚfuncÚreasonr#   r#   r$   r   e   s   
r   c                   @   sP   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZd	Zd
ZdZdZdZdZdZdS )r   r   r   r   é   éÿÿÿÿi  é   i  é   é   iŸ  iË  iÌ  r   N)Ú__name__Ú
__module__Ú__qualname__ÚEVP_CTRL_SET_RC2_KEY_BITSÚSSLEAY_VERSIONÚRSA_PKCS1_PADDINGÚRSA_NO_PADDINGÚRSA_PKCS1_OAEP_PADDINGÚEVP_MD_CTX_FLAG_PSS_MDLENÚEVP_PKEY_CTRL_RSA_PADDINGÚRSA_PKCS1_PSS_PADDINGÚEVP_PKEY_CTRL_RSA_PSS_SALTLENÚEVP_PKEY_RSAÚEVP_PKEY_OP_SIGNÚEVP_PKEY_OP_VERIFYÚNID_X9_62_prime256v1ÚNID_secp384r1ÚNID_secp521r1ÚOPENSSL_EC_NAMED_CURVEÚDH_GENERATOR_2r#   r#   r#   r$   r   {   s$    r   )N)!Ú
__future__r   r   r   r   Ú r   Ú_ffir   r	   r
   Ú_typesr   Ú_libcrypto_cffir   r   r   r   r   Ú_libcrypto_ctypesÚ__all__r   r    ÚERR_load_crypto_stringsÚOPENSSL_configr   ÚOSSL_PROVIDER_availableÚencodeÚOSSL_PROVIDER_loadr%   r   r   r   r#   r#   r#   r$   Ú<module>   s,   

