U af&@sddlmZmZmZmZddlZddlZddlZddlZddl m Z m Z ddl m Z ddlmZmZddd d d d d dgZeZddddZdd ZddZddd ZddZdd Zdd Zdd ZdS))unicode_literalsdivisionabsolute_importprint_functionN)str_cls type_name)LibraryNotFoundError) __version____version_info__r r backendffi load_order use_ctypes use_openssl use_winlegacy)r backend_configr c Cstddk rtdSttddk r:tdW5QRStjdkrhtddkr^dtd<qdtd<ntjdkr|d td<nd td<tdW5QRSQRXdS) zs :return: A unicode string of the backend being used: "openssl", "mac", "win", "winlegacy" r Nwin32r winlegacywindarwinmacopenssl)_module_values _backend_locksysplatformgetwindowsversionrrB/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/oscrypto/__init__.pyr "s       c CsntdkriStddk r"tdSt>tddk rHtdW5QRSitd<tdW5QRSQRXdS)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" rrN)r rrrrrr _backend_config>s   r!c Cst|tstdt|t|ts4tdt|tj|sLtd|tj|sdtd||dk rt|tstdt|tj|std|t \|||d}t d d krt d |krW5QRdSt d dk rt d d t d <|t d <W5QRXdS) 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 %szlibcrypto does not exist at %szlibssl 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_pathtrust_list_pathr rrzRAnother part of oscrypto has already been imported, unable to force use of OpenSSL) isinstancer ValueErrorrospathexistsr OSErrorrr RuntimeError)r"r#r$Z new_configrrr rUs0          c Csztjdkr0tptj}|dkr$d}td|t<tddkrPW5QRdStddk rdtddtd<W5QRXdS) 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 rDarwinzOS Xz9The winlegacy backend can only be used on Windows, not %sr rNzcAnother part of oscrypto has already been imported, unable to force use of Windows legacy CryptoAPI)rrsystemEnvironmentErrorrrr+)platrrr rs    c CsJt<tddkr W5QRdStddk r4tddtd<W5QRXdS)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)rrr+rrrr rs  c Csjtddk rtdStHzddl}dtd<Wntk rJdtd<YnXtdW5QRSQRXdS)zh Returns the FFI module being used :return: A unicode string of "cffi" or "ctypes" r Nrcffir0)rrr1 ImportError)r1rrr r s  cECsddddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEgES)Fa) 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 zoscrypto._asn1zoscrypto._cipher_suiteszoscrypto._errorsz oscrypto._intzoscrypto._typeszoscrypto.errorszoscrypto.versionZoscryptoz oscrypto._ffizoscrypto._pkcs12zoscrypto._pkcs5zoscrypto._randz oscrypto._tlszoscrypto._linux_bsd.trust_listz!oscrypto._mac._common_crypto_cffiz#oscrypto._mac._common_crypto_ctypeszoscrypto._mac._common_cryptoz#oscrypto._mac._core_foundation_cffiz%oscrypto._mac._core_foundation_ctypeszoscrypto._mac._core_foundationzoscrypto._mac._security_cffizoscrypto._mac._security_ctypeszoscrypto._mac._securityzoscrypto._mac.trust_listzoscrypto._mac.utilz!oscrypto._openssl._libcrypto_cffiz#oscrypto._openssl._libcrypto_ctypeszoscrypto._openssl._libcryptozoscrypto._openssl._libssl_cffiz oscrypto._openssl._libssl_ctypeszoscrypto._openssl._libsslzoscrypto._openssl.utilzoscrypto._win._cng_cffizoscrypto._win._cng_ctypeszoscrypto._win._cngzoscrypto._win._decodezoscrypto._win._advapi32_cffizoscrypto._win._advapi32_ctypeszoscrypto._win._advapi32zoscrypto._win._kernel32_cffizoscrypto._win._kernel32_ctypeszoscrypto._win._kernel32zoscrypto._win._secur32_cffizoscrypto._win._secur32_ctypeszoscrypto._win._secur32zoscrypto._win._crypt32_cffizoscrypto._win._crypt32_ctypeszoscrypto._win._crypt32zoscrypto._win.trust_listzoscrypto._win.utilzoscrypto.trust_listz oscrypto.utilz oscrypto.kdfzoscrypto._mac.symmetriczoscrypto._openssl.symmetriczoscrypto._win.symmetriczoscrypto.symmetriczoscrypto._asymmetriczoscrypto._ecdsazoscrypto._pkcs1zoscrypto._mac.asymmetriczoscrypto._openssl.asymmetriczoscrypto._win.asymmetriczoscrypto.asymmetricz oscrypto.keyszoscrypto._mac.tlszoscrypto._openssl.tlszoscrypto._win.tlsz oscrypto.tlsrrrrr rs )N) __future__rrrrr'rr threading_typesrrerrorsr versionr r __all__Lockrrr r!rrrr rrrrr s8   B