def _ensure_ffi_initialized(cls): if cls.ffi is not None and cls.lib is not None: return cls.ffi, cls.lib = build_ffi( cls._module_prefix, cls._modules, _OSX_PRE_INCLUDE, _OSX_POST_INCLUDE, ["crypto", "ssl"] )
def test_implicit_compile_explodes(): # This uses a random comment to make sure each test gets its own hash random_comment = binascii.hexlify(os.urandom(24)) ffi = utils.build_ffi("/* %s */" % random_comment, "") with pytest.raises(RuntimeError): ffi.verifier.load_library()
def _ensure_ffi_initialized(cls): if cls.ffi is not None and cls.lib is not None: return cls.ffi, cls.lib = build_ffi( module_prefix=cls._module_prefix, modules=cls._modules, extra_link_args=["-framework", "Security"] )
def _ensure_ffi_initialized(cls): if cls.ffi is not None and cls.lib is not None: return # OpenSSL goes by a different library name on different operating # systems. if sys.platform != "win32": # In some circumstances, the order in which these libs are # specified on the linker command-line is significant; # libssl must come before libcrypto # (http://marc.info/?l=openssl-users&m=135361825921871) libraries = ["ssl", "crypto"] else: # pragma: no cover link_type = os.environ.get("PYCA_WINDOWS_LINK_TYPE", "static") libraries = _get_windows_libraries(link_type) cls.ffi, cls.lib = build_ffi( module_prefix=cls._module_prefix, modules=cls._modules, pre_include=_OSX_PRE_INCLUDE, post_include=_OSX_POST_INCLUDE, libraries=libraries, ) res = cls.lib.Cryptography_add_osrandom_engine() assert res != 0
def _ensure_ffi_initialized(cls): if cls.ffi is not None and cls.lib is not None: return cls.ffi, cls.lib = build_ffi( module_prefix=cls._module_prefix, modules=cls._modules, )
def _ensure_ffi_initialized(cls): if cls.ffi is not None and cls.lib is not None: return cls.ffi, cls.lib = build_ffi( module_prefix=cls._module_prefix, modules=cls._modules, extra_link_args=["-framework", "Security"])
def _ensure_ffi_initialized(cls): if cls.ffi is not None and cls.lib is not None: return # platform check to set the right library names if sys.platform != "win32": libraries = ["crypto", "ssl"] else: # pragma: no cover libraries = ["libeay32", "ssleay32"] cls.ffi, cls.lib = build_ffi(cls._module_prefix, cls._modules, _OSX_PRE_INCLUDE, _OSX_POST_INCLUDE, libraries)
def _ensure_ffi_initialized(cls): if cls.ffi is not None and cls.lib is not None: return # OpenSSL goes by a different library name on different operating # systems. if sys.platform != "win32": libraries = ["crypto", "ssl"] else: # pragma: no cover libraries = ["libeay32", "ssleay32", "advapi32"] cls.ffi, cls.lib = build_ffi(cls._module_prefix, cls._modules, _OSX_PRE_INCLUDE, _OSX_POST_INCLUDE, libraries) res = cls.lib.Cryptography_add_osrandom_engine() assert res != 0
def _ensure_ffi_initialized(cls): if cls.ffi is not None and cls.lib is not None: return # OpenSSL goes by a different library name on different operating # systems. if sys.platform != "win32": libraries = ["crypto", "ssl"] else: # pragma: no cover link_type = os.environ.get("PYCA_WINDOWS_LINK_TYPE", "static") libraries = _get_windows_libraries(link_type) cls.ffi, cls.lib = build_ffi( module_prefix=cls._module_prefix, modules=cls._modules, pre_include=_OSX_PRE_INCLUDE, post_include=_OSX_POST_INCLUDE, libraries=libraries, ) res = cls.lib.Cryptography_add_osrandom_engine() assert res != 0
from __future__ import absolute_import, division, print_function import hmac import os from cryptography.hazmat.bindings.utils import LazyLibrary, build_ffi with open(os.path.join(os.path.dirname(__file__), "src/constant_time.h")) as f: TYPES = f.read() with open(os.path.join(os.path.dirname(__file__), "src/constant_time.c")) as f: FUNCTIONS = f.read() _ffi = build_ffi(cdef_source=TYPES, verify_source=FUNCTIONS) _lib = LazyLibrary(_ffi) if hasattr(hmac, "compare_digest"): def bytes_eq(a, b): if not isinstance(a, bytes) or not isinstance(b, bytes): raise TypeError("a and b must be bytes.") return hmac.compare_digest(a, b) else: def bytes_eq(a, b): if not isinstance(a, bytes) or not isinstance(b, bytes): raise TypeError("a and b must be bytes.")
import hmac import os from cryptography.hazmat.bindings.utils import build_ffi with open(os.path.join(os.path.dirname(__file__), "src/constant_time.h")) as f: TYPES = f.read() with open(os.path.join(os.path.dirname(__file__), "src/constant_time.c")) as f: FUNCTIONS = f.read() _ffi, _lib = build_ffi( cdef_source=TYPES, verify_source=FUNCTIONS, ) if hasattr(hmac, "compare_digest"): def bytes_eq(a, b): if not isinstance(a, bytes) or not isinstance(b, bytes): raise TypeError("a and b must be bytes.") return hmac.compare_digest(a, b) else: def bytes_eq(a, b): if not isinstance(a, bytes) or not isinstance(b, bytes): raise TypeError("a and b must be bytes.") return _lib.Cryptography_constant_time_bytes_eq(