From 9a00f0539d5ab9b03b84625791663f11d7bed75c Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 2 Jan 2014 13:09:34 -0800 Subject: All the necessary things for setup.py to build cffi stuff --- cryptography/hazmat/bindings/openssl/binding.py | 1 + cryptography/hazmat/primitives/constant_time.py | 4 +++- cryptography/hazmat/primitives/padding.py | 4 +++- setup.py | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cryptography/hazmat/bindings/openssl/binding.py b/cryptography/hazmat/bindings/openssl/binding.py index 8b5e3449..ccda368e 100644 --- a/cryptography/hazmat/bindings/openssl/binding.py +++ b/cryptography/hazmat/bindings/openssl/binding.py @@ -135,6 +135,7 @@ class Binding(object): customizations ), libraries=["crypto", "ssl"], + ext_package="cryptography", ) for name in cls._modules: diff --git a/cryptography/hazmat/primitives/constant_time.py b/cryptography/hazmat/primitives/constant_time.py index 6502803e..c3d81221 100644 --- a/cryptography/hazmat/primitives/constant_time.py +++ b/cryptography/hazmat/primitives/constant_time.py @@ -42,7 +42,9 @@ uint8_t Cryptography_constant_time_bytes_eq(uint8_t *a, size_t len_a, /* Now check the low bit to see if it's set */ return (mismatch & 1) == 0; } -""") +""", + ext_package="cryptography", +) def bytes_eq(a, b): diff --git a/cryptography/hazmat/primitives/padding.py b/cryptography/hazmat/primitives/padding.py index e517dee0..7c5271cb 100644 --- a/cryptography/hazmat/primitives/padding.py +++ b/cryptography/hazmat/primitives/padding.py @@ -59,7 +59,9 @@ uint8_t Cryptography_check_pkcs7_padding(const uint8_t *data, /* Now check the low bit to see if it's set */ return (mismatch & 1) == 0; } -""") +""", + ext_package="cryptography", +) class PKCS7(object): diff --git a/setup.py b/setup.py index 1856cadb..0776ba6e 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,8 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. +from distutils.command.build import build + from setuptools import setup, find_packages @@ -30,6 +32,20 @@ setup_requires = [ CFFI_DEPENDENCY, ] + +class cffi_build(build): + def finalize_options(self): + from cryptography.hazmat.bindings.openssl.binding import Binding + from cryptography.hazmat.primitives import constant_time, padding + + self.distribution.ext_modules = [ + Binding().ffi.verifier.get_extension(), + constant_time._ffi.verifier.get_extension(), + padding._ffi.verifier.get_extension() + ] + build.finalize_options(self) + + setup( name=about["__title__"], version=about["__version__"], @@ -70,4 +86,8 @@ setup( # for cffi zip_safe=False, + ext_package="cryptography", + cmdclass={ + "build": cffi_build, + } ) -- cgit v1.2.3 From 91f119e75865e72d66e8c8b4f24164988e5b8d20 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 2 Jan 2014 13:12:59 -0800 Subject: six is now required at build time --- setup.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 0776ba6e..2ff57e97 100644 --- a/setup.py +++ b/setup.py @@ -23,15 +23,11 @@ with open("cryptography/__about__.py") as fp: CFFI_DEPENDENCY = "cffi>=0.6" SIX_DEPENDENCY = "six>=1.4.1" -install_requires = [ +requirements = [ CFFI_DEPENDENCY, SIX_DEPENDENCY ] -setup_requires = [ - CFFI_DEPENDENCY, -] - class cffi_build(build): def finalize_options(self): @@ -81,8 +77,8 @@ setup( packages=find_packages(exclude=["tests", "tests.*"]), - install_requires=install_requires, - setup_requires=setup_requires, + install_requires=requirements, + setup_requires=requirements, # for cffi zip_safe=False, -- cgit v1.2.3 From eba623f88260a9a076ce3a4a71d1d61755327e05 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 2 Jan 2014 13:47:38 -0800 Subject: Some flake8 fixes --- cryptography/hazmat/primitives/constant_time.py | 3 ++- cryptography/hazmat/primitives/padding.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cryptography/hazmat/primitives/constant_time.py b/cryptography/hazmat/primitives/constant_time.py index c3d81221..e88a0d95 100644 --- a/cryptography/hazmat/primitives/constant_time.py +++ b/cryptography/hazmat/primitives/constant_time.py @@ -23,7 +23,8 @@ _ffi.cdef(""" uint8_t Cryptography_constant_time_bytes_eq(uint8_t *, size_t, uint8_t *, size_t); """) -_lib = _ffi.verify(""" +_lib = _ffi.verify( + """ uint8_t Cryptography_constant_time_bytes_eq(uint8_t *a, size_t len_a, uint8_t *b, size_t len_b) { size_t i = 0; diff --git a/cryptography/hazmat/primitives/padding.py b/cryptography/hazmat/primitives/padding.py index 7c5271cb..ddb2c63c 100644 --- a/cryptography/hazmat/primitives/padding.py +++ b/cryptography/hazmat/primitives/padding.py @@ -23,7 +23,8 @@ _ffi = cffi.FFI() _ffi.cdef(""" uint8_t Cryptography_check_pkcs7_padding(const uint8_t *, uint8_t); """) -_lib = _ffi.verify(""" +_lib = _ffi.verify( + """ /* Returns the value of the input with the most-significant-bit copied to all of the bits. */ static uint8_t Cryptography_DUPLICATE_MSB_TO_ALL(uint8_t a) { -- cgit v1.2.3 From 4969751fde0ef09cd72c738a80c32851c1b1f21d Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 3 Jan 2014 15:08:45 -0800 Subject: Explanatory comment --- setup.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/setup.py b/setup.py index fe37d9fb..0bdad485 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,15 @@ requirements = [ class cffi_build(build): + """ + This class exists, instead of just providing ``ext_modules=[...]`` directly + in ``setup()`` because importing cryptography requires we have several + packages installed first. + + By doing the imports here we ensure that packages listed in + ``setup_requires`` are already installed. + """ + def finalize_options(self): from cryptography.hazmat.bindings.openssl.binding import Binding from cryptography.hazmat.primitives import constant_time, padding -- cgit v1.2.3 From 6078221d25fd3eddef83a63ce026efd24c0a2107 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 4 Jan 2014 12:20:32 -0800 Subject: Re-add the ext_package decleration to the moved verify() call --- cryptography/hazmat/bindings/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cryptography/hazmat/bindings/utils.py b/cryptography/hazmat/bindings/utils.py index 9e1d3937..69290eb3 100644 --- a/cryptography/hazmat/bindings/utils.py +++ b/cryptography/hazmat/bindings/utils.py @@ -74,7 +74,8 @@ def build_ffi(module_prefix, modules, pre_include, post_include, libraries): functions + customizations ), - libraries=libraries + libraries=libraries, + ext_package="cryptography", ) for name in modules: -- cgit v1.2.3 From 50f233efe4d37a20b4372cf21f1c462914ea5d40 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 6 Jan 2014 11:10:40 -0800 Subject: Check to see if a binding is available before trying to install it --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0bdad485..514fdab7 100644 --- a/setup.py +++ b/setup.py @@ -47,10 +47,12 @@ class cffi_build(build): from cryptography.hazmat.primitives import constant_time, padding self.distribution.ext_modules = [ - Binding().ffi.verifier.get_extension(), constant_time._ffi.verifier.get_extension(), padding._ffi.verifier.get_extension() ] + if Binding.is_available(): + self.distribution.ext_modules.append(Binding().ffi.verifier.get_extension()) + build.finalize_options(self) -- cgit v1.2.3 From ffa8b4d5fedad8f9c1fdbd05a2da8fb2679168af Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 6 Jan 2014 11:19:11 -0800 Subject: flake8 --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 514fdab7..a053fe61 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,9 @@ class cffi_build(build): padding._ffi.verifier.get_extension() ] if Binding.is_available(): - self.distribution.ext_modules.append(Binding().ffi.verifier.get_extension()) + self.distribution.ext_modules.append( + Binding().ffi.verifier.get_extension() + ) build.finalize_options(self) -- cgit v1.2.3 From 5e5316de9ca968f646aa04301fcf3109aef0473f Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 7 Jan 2014 12:27:08 -0800 Subject: This is dangerous --- setup.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/setup.py b/setup.py index a053fe61..feed0cd8 100644 --- a/setup.py +++ b/setup.py @@ -47,13 +47,10 @@ class cffi_build(build): from cryptography.hazmat.primitives import constant_time, padding self.distribution.ext_modules = [ + Binding().ffi.verifier.get_extension(), constant_time._ffi.verifier.get_extension(), padding._ffi.verifier.get_extension() ] - if Binding.is_available(): - self.distribution.ext_modules.append( - Binding().ffi.verifier.get_extension() - ) build.finalize_options(self) -- cgit v1.2.3