a oe @sddlZddlZddlZddlmZmZmZmZmZddl m Z ee e ej fZe ZejZejZejddZee dddZeeed d d Zeeeegefd d dZee dddZe e dddZeZdZe eedddZdS)N)AnyCallableNoReturnTypeUnion)BindingF)Zshould_clear_after_alloc)charpreturncCs|sdSt|dS)z Get a native string type representing of the given CFFI ``char*`` object. :param charp: A C-style string represented using CFFI. :return: :class:`str` utf-8)ffistringdecode)rr.C:\Program Files\Certbot\pkgs\OpenSSL\_util.pytextsr)exception_typer cCsRg}t}|dkrqF|tt|tt|tt|fq||dS)ac Convert an OpenSSL library failure into a Python exception. When a call to the native OpenSSL library fails, this is usually signalled by the return value, and an error code is stored in an error queue associated with the current thread. The err library provides functions to obtain these error codes and textual error messages. rN)libZ ERR_get_errorappendrZERR_lib_error_stringZERR_func_error_stringZERR_reason_error_string)rerrorserrorrrrexception_from_error_queue"s    r)rr cstddfdd }|S)z~ Create an assert function that uses :func:`exception_from_error_queue` to raise an exception wrapped by *error*. N)okr cs|durtdS)zT If *ok* is not True, retrieve the error from OpenSSL and raise it. TN)r)rrrropenssl_assertBsz#make_assert..openssl_assert)bool)rrrrr make_assert<sr)sr cCs*t|}t|tr"|tS|SdS)z Convert a Python path to a :py:class:`bytes` for the path which can be passed into an OpenSSL API accepting a filename. :param s: A path (valid for os.fspath). :return: An instance of :py:class:`bytes`. N)osfspath isinstancestrencodesysgetfilesystemencoding)rbrrr path_bytesLs  r&cCs |dS)Ncharmap)r")rrrr byte_string]sr(z,str for {0} is no longer accepted, use bytes)labelobjr cCs.t|tr*tjt|tdd|dS|S)a If ``obj`` is text, emit a warning that it should be bytes instead and try to convert it to bytes automatically. :param str label: The name of the parameter from which ``obj`` was taken (so a developer can easily find the source of the problem and correct it). :return: If ``obj`` is the text string type, a ``bytes`` object giving the UTF-8 encoding of that text is returned. Otherwise, ``obj`` itself is returned. )category stacklevelr )r r!warningswarn _TEXT_WARNINGformatDeprecationWarningr")r)r*rrrtext_to_bytes_and_warnhs  r3)rr#r.typingrrrrrZ,cryptography.hazmat.bindings.openssl.bindingrr!bytesPathLikeZStrOrBytesPathZbindingr rZ new_allocatorZno_zero_allocatorr Exceptionrrrr&r(objectZ UNSPECIFIEDr0r3rrrrs"