o
    vh                     @   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#   Z/var/www/html/hyperkenya/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   Nx   )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,   

