aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-07-02 22:56:01 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-07-02 22:56:01 -0500
commit2a39f7f3c80b9c725b586ca96defbe5bad62bf83 (patch)
treeb5fba2d28e2d2b1b9de2fe3e8cf9e55ba9c95696
parent751c53b6f7cdc3e8301dd8672091acc105ed8874 (diff)
downloadcryptography-2a39f7f3c80b9c725b586ca96defbe5bad62bf83.tar.gz
cryptography-2a39f7f3c80b9c725b586ca96defbe5bad62bf83.tar.bz2
cryptography-2a39f7f3c80b9c725b586ca96defbe5bad62bf83.zip
switch to env variable based static/dynamic switch for windows
-rw-r--r--cryptography/hazmat/bindings/openssl/binding.py19
-rw-r--r--docs/installation.rst18
-rw-r--r--tests/hazmat/bindings/test_openssl.py12
3 files changed, 41 insertions, 8 deletions
diff --git a/cryptography/hazmat/bindings/openssl/binding.py b/cryptography/hazmat/bindings/openssl/binding.py
index 6b4afe13..7305874b 100644
--- a/cryptography/hazmat/bindings/openssl/binding.py
+++ b/cryptography/hazmat/bindings/openssl/binding.py
@@ -13,6 +13,7 @@
from __future__ import absolute_import, division, print_function
+import os
import sys
import threading
@@ -97,10 +98,8 @@ class Binding(object):
if sys.platform != "win32":
libraries = ["crypto", "ssl"]
else: # pragma: no cover
- libraries = [
- "libeay32mt", "ssleay32mt", "advapi32",
- "crypt32", "gdi32", "user32", "ws2_32"
- ]
+ link_type = os.environ.get("PYCA_OPENSSL_INSTALL", "static")
+ libraries = _get_windows_libraries(link_type)
cls.ffi, cls.lib = build_ffi(
module_prefix=cls._module_prefix,
@@ -157,3 +156,15 @@ class Binding(object):
mode, n, file, line
)
)
+
+
+def _get_windows_libraries(link_type):
+ if link_type == "dynamic":
+ return ["libeay32", "ssleay32", "advapi32"]
+ elif link_type == "static":
+ return ["libeay32mt", "ssleay32mt", "advapi32",
+ "crypt32", "gdi32", "user32", "ws2_32"]
+ else:
+ raise ValueError(
+ "PYCA_OPENSSL_INSTALL must be 'static' or 'dynamic'"
+ )
diff --git a/docs/installation.rst b/docs/installation.rst
index 56d21e72..81e150de 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -45,13 +45,25 @@ dependencies are included. Just run
If you prefer to compile it yourself you'll need to have OpenSSL installed.
There are `pre-compiled binaries`_ available. If your installation is in an
unusual location set the ``LIB`` and ``INCLUDE`` environment variables to
-include the corresponding locations. For example:
+include the corresponding locations.For example:
.. code-block:: console
C:\> \path\to\vcvarsall.bat x86_amd64
- C:\> set LIB=C:\OpenSSL-1.0.1h-64bit\lib\VC\static;%LIB%
- C:\> set INCLUDE=C:\OpenSSL-1.0.1h-64bit\include;%INCLUDE%
+ C:\> set LIB=C:\OpenSSL\lib\VC\static;C:\OpenSSL\lib;%LIB%
+ C:\> set INCLUDE=C:\OpenSSL\include;%INCLUDE%
+ C:\> pip install cryptography
+
+You can also choose to build statically or dynamically using the
+``PYCA_OPENSSL_INSTALL`` variable. Allowed values are ``static`` (default) and
+``dynamic``.
+
+.. code-block:: console
+
+ C:\> \path\to\vcvarsall.bat x86_amd64
+ C:\> set LIB=C:\OpenSSL\lib\VC\static;C:\OpenSSL\lib;%LIB%
+ C:\> set INCLUDE=C:\OpenSSL\include;%INCLUDE%
+ C:\> set PYCA_OPENSSL_INSTALL=dynamic
C:\> pip install cryptography
Building cryptography on Linux
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index 58d7602b..84f46b2e 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -15,7 +15,9 @@ from __future__ import absolute_import, division, print_function
import pytest
-from cryptography.hazmat.bindings.openssl.binding import Binding
+from cryptography.hazmat.bindings.openssl.binding import (
+ Binding, _get_windows_libraries
+)
class TestOpenSSL(object):
@@ -137,3 +139,11 @@ class TestOpenSSL(object):
resp = b.lib.SSL_set_mode(ssl, b.lib.SSL_OP_ALL)
assert resp == b.lib.SSL_OP_ALL
assert b.lib.SSL_OP_ALL == b.lib.SSL_get_mode(ssl)
+
+ def test_windows_static_dynamic_libraries(self):
+ assert len(_get_windows_libraries("static")) == 7
+
+ assert len(_get_windows_libraries("dynamic")) == 3
+
+ with pytest.raises(ValueError):
+ _get_windows_libraries("notvalid")