From f44d070afb8efe34df78dd4fce2aad68c15d9d4f Mon Sep 17 00:00:00 2001 From: Bortlesboat Date: Mon, 6 Apr 2026 13:51:50 -0400 Subject: [PATCH] core: raise clear error when OpenSSL library is not found On Windows, ctypes.util.find_library() can return None for all candidate library names. Passing None to LoadLibrary() raises a confusing TypeError. Check for None first and raise an EnvironmentError with an actionable message instead. Fixes #316 --- bitcoin/core/key.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bitcoin/core/key.py b/bitcoin/core/key.py index 0f902c8c..66905242 100644 --- a/bitcoin/core/key.py +++ b/bitcoin/core/key.py @@ -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