Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions bitcoin/core/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
import bitcoin.signature

import bitcoin.core.script

_ssl = ctypes.cdll.LoadLibrary(
ctypes.util.find_library('ssl.35') or ctypes.util.find_library('ssl') or ctypes.util.find_library('libeay32')
or ctypes.util.find_library('libcrypto')
_ssl_library = (
ctypes.util.find_library('ssl.35') or ctypes.util.find_library('ssl')
or ctypes.util.find_library('libeay32') or ctypes.util.find_library('libcrypto')
)
if _ssl_library is None:
raise EnvironmentError(
"OpenSSL library not found. "
"Install OpenSSL and ensure it is on your PATH or system library path."
)
_ssl = ctypes.cdll.LoadLibrary(_ssl_library)

_libsecp256k1_path = ctypes.util.find_library('secp256k1')
_libsecp256k1_enable_signing = False
Expand Down
28 changes: 28 additions & 0 deletions bitcoin/tests/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# LICENSE file.


import subprocess
import sys
import unittest

from bitcoin.core.key import *
Expand Down Expand Up @@ -38,3 +40,29 @@ def T(hex_pubkey, is_valid, is_fullyvalid, is_compressed):

T('0478d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455',
True, True, False)


class Test_OpenSSLLoading(unittest.TestCase):
def test_missing_library_raises_clear_error(self):
code = """
import ctypes.util
ctypes.util.find_library = lambda name: None

try:
import bitcoin.core.key
except EnvironmentError as exc:
assert str(exc) == (
"OpenSSL library not found. Install OpenSSL and ensure it is on your "
"PATH or system library path."
)
else:
raise AssertionError("bitcoin.core.key imported without OpenSSL")
"""

result = subprocess.run(
[sys.executable, "-c", code],
capture_output=True,
text=True,
)

self.assertEqual(result.returncode, 0, result.stderr)