o
    &zh&                     @   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   L/var/www/html/kangema/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 sw   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 