o
    Œõ±j&  ã                   @   s¾   d dl mZmZmZmZ d dlZd dlZd dlZd dlZddl	m
Z
mZ ddlmZ ddlmZmZ g d¢Ze ¡ ZddddœZd	d
„ Zdd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ ZdS )é    )Úunicode_literalsÚdivisionÚabsolute_importÚprint_functionNé   )Ústr_clsÚ	type_name)ÚLibraryNotFoundError)Ú__version__Ú__version_info__)r
   r   ÚbackendÚffiÚ
load_orderÚ
use_ctypesÚuse_opensslÚuse_winlegacy)r   Úbackend_configr   c                   C   s°   t d dur
t d S t�B t d durt d W  d  ƒ S tjdkr5t ¡ d dk r0dt d< ndt d< ntjdkr?d	t d< nd
t d< t d W  d  ƒ S 1 sQw   Y  dS )zs
    :return:
        A unicode string of the backend being used: "openssl", "mac", "win",
        "winlegacy"
    r   NÚwin32r   é   Ú	winlegacyÚwinÚdarwinÚmacÚopenssl)Ú_module_valuesÚ_backend_lockÚsysÚplatformÚgetwindowsversion© r   r   ú„/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/oscrypto/__init__.pyr   "   s   þ




$ñr   c                   C   s|   t ƒ dkri S td durtd S t�! td dur%td W  d  ƒ S i td< td W  d  ƒ S 1 s7w   Y  dS )zÔ
    :return:
        A dict of config info for the backend. Only currently used by "openssl",
        it may contains zero or more of the following keys:
         - "libcrypto_path"
         - "libssl_path"
    r   r   N)r   r   r   r   r   r   r    Ú_backend_config>   s   
	þ$ûr!   c                 C   s"  t | tƒstdt| ƒ ƒ‚t |tƒstdt|ƒ ƒ‚tj | ¡s&td|  ƒ‚tj |¡s2td| ƒ‚|durOt |tƒsCtdt|ƒ ƒ‚tj |¡sOtd| ƒ‚t	�6 | ||dœ}t
d	 d
krmt
d |krm	 W d  ƒ dS t
d	 durwtdƒ‚d
t
d	< |t
d< W d  ƒ dS 1 sŠw   Y  dS )aÖ  
    Forces using OpenSSL dynamic libraries on OS X (.dylib) or Windows (.dll),
    or using a specific dynamic library on Linux/BSD (.so).

    This can also be used to configure oscrypto to use LibreSSL dynamic
    libraries.

    This method must be called before any oscrypto submodules are imported.

    :param libcrypto_path:
        A unicode string of the file path to the OpenSSL/LibreSSL libcrypto
        dynamic library.

    :param libssl_path:
        A unicode string of the file path to the OpenSSL/LibreSSL libssl
        dynamic library.

    :param trust_list_path:
        An optional unicode string of the path to a file containing
        OpenSSL-compatible CA certificates in PEM format. If this is not
        provided and the platform is OS X or Windows, the system trust roots
        will be exported from the OS and used for all TLS connections.

    :raises:
        ValueError - when one of the paths is not a unicode string
        OSError - when the trust_list_path does not exist on the filesystem
        oscrypto.errors.LibraryNotFoundError - when one of the path does not exist on the filesystem
        RuntimeError - when this function is called after another part of oscrypto has been imported
    z/libcrypto_path must be a unicode string, not %sz,libssl_path must be a unicode string, not %szlibcrypto does not exist at %szlibssl does not exist at %sNz0trust_list_path must be a unicode string, not %sz$trust_list_path does not exist at %s)Úlibcrypto_pathÚlibssl_pathÚtrust_list_pathr   r   r   zRAnother part of oscrypto has already been imported, unable to force use of OpenSSL)Ú
isinstancer   Ú
ValueErrorr   ÚosÚpathÚexistsr	   ÚOSErrorr   r   ÚRuntimeError)r"   r#   r$   Ú
new_configr   r   r    r   U   s4   


ýø

"òr   c                  C   s”   t jdkrt ¡ pt j} | dkrd} td|  ƒ‚t�& td dkr*	 W d  ƒ dS td dur4tdƒ‚dtd< W d  ƒ dS 1 sCw   Y  dS )	as  
    Forces use of the legacy Windows CryptoAPI. This should only be used on
    Windows XP or for testing. It is less full-featured than the Cryptography
    Next Generation (CNG) API, and as a result the elliptic curve and PSS
    padding features are implemented in pure Python. This isn't ideal, but it
    a shim for end-user client code. No one is going to run a server on Windows
    XP anyway, right?!

    :raises:
        EnvironmentError - when this function is called on an operating system other than Windows
        RuntimeError - when this function is called after another part of oscrypto has been imported
    r   ÚDarwinzOS Xz9The winlegacy backend can only be used on Windows, not %sr   r   NzcAnother part of oscrypto has already been imported, unable to force use of Windows legacy CryptoAPI)r   r   ÚsystemÚEnvironmentErrorr   r   r+   )Úplatr   r   r    r   —   s   
þÿ
"÷r   c                   C   sd   t �& td dkr	 W d  ƒ dS td durtdƒ‚dtd< W d  ƒ dS 1 s+w   Y  dS )z³
    Forces use of ctypes instead of cffi for the FFI layer

    :raises:
        RuntimeError - when this function is called after another part of oscrypto has been imported
    r   ÚctypesNr   zQAnother part of oscrypto has already been imported, unable to force use of ctypes)r   r   r+   r   r   r   r    r   ·   s   þÿ
"÷r   c               	   C   st   t d dur
t d S t�$ z
ddl} dt d< W n ty$   dt d< Y nw t d W  d  ƒ S 1 s3w   Y  dS )zh
    Returns the FFI module being used

    :return:
        A unicode string of "cffi" or "ctypes"
    r   Nr   Úcffir1   )r   r   r2   ÚImportError)r2   r   r   r    r   Ë   s   ÿ$ùr   c                   C   s   g d¢S )a)  
    Returns a list of the module and sub-module names for oscrypto in
    dependency load order, for the sake of live reloading code

    :return:
        A list of unicode strings of module names, as they would appear in
        sys.modules, ordered by which module should be reloaded first
    )Ezoscrypto._asn1zoscrypto._cipher_suiteszoscrypto._errorszoscrypto._intzoscrypto._typeszoscrypto.errorszoscrypto.versionÚoscryptozoscrypto._ffizoscrypto._pkcs12zoscrypto._pkcs5zoscrypto._randzoscrypto._tlszoscrypto._linux_bsd.trust_listz!oscrypto._mac._common_crypto_cffiz#oscrypto._mac._common_crypto_ctypeszoscrypto._mac._common_cryptoz#oscrypto._mac._core_foundation_cffiz%oscrypto._mac._core_foundation_ctypeszoscrypto._mac._core_foundationzoscrypto._mac._security_cffizoscrypto._mac._security_ctypeszoscrypto._mac._securityzoscrypto._mac.trust_listzoscrypto._mac.utilz!oscrypto._openssl._libcrypto_cffiz#oscrypto._openssl._libcrypto_ctypeszoscrypto._openssl._libcryptozoscrypto._openssl._libssl_cffiz oscrypto._openssl._libssl_ctypeszoscrypto._openssl._libsslzoscrypto._openssl.utilzoscrypto._win._cng_cffizoscrypto._win._cng_ctypeszoscrypto._win._cngzoscrypto._win._decodezoscrypto._win._advapi32_cffizoscrypto._win._advapi32_ctypeszoscrypto._win._advapi32zoscrypto._win._kernel32_cffizoscrypto._win._kernel32_ctypeszoscrypto._win._kernel32zoscrypto._win._secur32_cffizoscrypto._win._secur32_ctypeszoscrypto._win._secur32zoscrypto._win._crypt32_cffizoscrypto._win._crypt32_ctypeszoscrypto._win._crypt32zoscrypto._win.trust_listzoscrypto._win.utilzoscrypto.trust_listzoscrypto.utilzoscrypto.kdfzoscrypto._mac.symmetriczoscrypto._openssl.symmetriczoscrypto._win.symmetriczoscrypto.symmetriczoscrypto._asymmetriczoscrypto._ecdsazoscrypto._pkcs1zoscrypto._mac.asymmetriczoscrypto._openssl.asymmetriczoscrypto._win.asymmetriczoscrypto.asymmetriczoscrypto.keyszoscrypto._mac.tlszoscrypto._openssl.tlszoscrypto._win.tlszoscrypto.tlsr   r   r   r   r    r   à   s   
r   )N)Ú
__future__r   r   r   r   r'   r   r   Ú	threadingÚ_typesr   r   Úerrorsr	   Úversionr
   r   Ú__all__ÚLockr   r   r   r!   r   r   r   r   r   r   r   r   r    Ú<module>   s*   ý
B 