Skip to content

Commit

Permalink
Bump the minimum PyPy/cffi version and simplify as a result (#3585)
Browse files Browse the repository at this point in the history
* Bump the minimum PyPy/cffi version and simplify as a result

* unused imports

* grumble, fix
  • Loading branch information
alex authored and reaperhulk committed May 24, 2017
1 parent 70e8f90 commit 6091e11
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 96 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ matrix:
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
- env: TOXENV=pypy-nocoverage PYPY_VERSION=2.6.1
- env: TOXENV=pypy PYPY_VERSION=4.0.1
- env: TOXENV=pypy PYPY_VERSION=5.3
- env: TOXENV=pypy PYPY_VERSION=5.7.1
- python: 2.7
env: TOXENV=py27 OPENSSL=1.1.0e
Expand Down Expand Up @@ -65,7 +64,7 @@ matrix:
- language: generic
os: osx
osx_image: xcode8.3
env: TOXENV=pypy-nocoverage CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1 PYPY_VERSION=5.7.1
env: TOXENV=pypy CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1 PYPY_VERSION=5.7.1
- language: generic
os: osx
osx_image: xcode8.3
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog
has always been to check whether or not
:class:`~cryptography.exceptions.InvalidSignature` was raised.
* **BACKWARDS INCOMPATIBLE:** Dropped support for macOS 10.7 and 10.8.
* **BACKWARDS INCOMPATIBLE:** The minimum supported PyPy version is now 5.3.
* Python 3.3 support has been deprecated, and will be removed in the
``cryptography`` release.
* Add support for providing ``tag`` during
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
requirements.append("ipaddress")

if platform.python_implementation() == "PyPy":
if sys.pypy_version_info < (2, 6):
if sys.pypy_version_info < (5, 3):
raise RuntimeError(
"cryptography 1.0 is not compatible with PyPy < 2.6. Please "
"cryptography 1.9 is not compatible with PyPy < 5.3. Please "
"upgrade PyPy to use this library."
)
else:
requirements.append("cffi>=1.4.1")
setup_requirements.append("cffi>=1.4.1")
requirements.append("cffi>=1.7")
setup_requirements.append("cffi>=1.7")

test_requirements = [
"pytest>=2.9.0",
Expand Down
34 changes: 7 additions & 27 deletions src/cryptography/hazmat/primitives/ciphers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import abc

import cffi

import six

from cryptography import utils
Expand Down Expand Up @@ -150,19 +148,10 @@ def update(self, data):
raise AlreadyFinalized("Context was already finalized.")
return self._ctx.update(data)

# cffi 1.7 supports from_buffer on bytearray, which is required. We can
# remove this check in the future when we raise our minimum PyPy version.
if cffi.__version_info__ >= (1, 7):
def update_into(self, data, buf):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return self._ctx.update_into(data, buf)
else:
def update_into(self, data, buf):
raise NotImplementedError(
"update_into requires cffi 1.7+. To use this method please "
"update cffi."
)
def update_into(self, data, buf):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized.")
return self._ctx.update_into(data, buf)

def finalize(self):
if self._ctx is None:
Expand Down Expand Up @@ -199,18 +188,9 @@ def update(self, data):
self._check_limit(len(data))
return self._ctx.update(data)

# cffi 1.7 supports from_buffer on bytearray, which is required. We can
# remove this check in the future when we raise our minimum PyPy version.
if cffi.__version_info__ >= (1, 7):
def update_into(self, data, buf):
self._check_limit(len(data))
return self._ctx.update_into(data, buf)
else:
def update_into(self, data, buf):
raise NotImplementedError(
"update_into requires cffi 1.7+. To use this method please "
"update cffi."
)
def update_into(self, data, buf):
self._check_limit(len(data))
return self._ctx.update_into(data, buf)

def finalize(self):
if self._ctx is None:
Expand Down
6 changes: 0 additions & 6 deletions tests/hazmat/primitives/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import binascii

import cffi

import pytest

from cryptography.exceptions import (
Expand Down Expand Up @@ -72,10 +70,6 @@ def test_use_after_finalize(self, backend):
with pytest.raises(AlreadyFinalized):
decryptor.finalize()

@pytest.mark.skipif(
cffi.__version_info__ < (1, 7),
reason="cffi version too old"
)
def test_use_update_into_after_finalize(self, backend):
cipher = Cipher(
algorithms.AES(binascii.unhexlify(b"0" * 32)),
Expand Down
48 changes: 0 additions & 48 deletions tests/hazmat/primitives/test_ciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import binascii
import os

import cffi

import pytest

from cryptography.exceptions import AlreadyFinalized, _Reasons
Expand Down Expand Up @@ -141,10 +139,6 @@ def test_invalid_backend():
ciphers.Cipher(AES(b"AAAAAAAAAAAAAAAA"), modes.ECB, pretend_backend)


@pytest.mark.skipif(
cffi.__version_info__ < (1, 7),
reason="cffi version too old"
)
@pytest.mark.supported(
only_if=lambda backend: backend.cipher_supported(
AES(b"\x00" * 16), modes.ECB()
Expand Down Expand Up @@ -259,45 +253,3 @@ def test_update_into_buffer_too_small_gcm(self, backend):
buf = bytearray(5)
with pytest.raises(ValueError):
encryptor.update_into(b"testing", buf)


@pytest.mark.skipif(
cffi.__version_info__ >= (1, 7),
reason="cffi version too new"
)
@pytest.mark.requires_backend_interface(interface=CipherBackend)
class TestCipherUpdateIntoUnsupported(object):
def _too_old(self, mode, backend):
key = b"\x00" * 16
c = ciphers.Cipher(AES(key), mode, backend)
encryptor = c.encryptor()
buf = bytearray(32)
with pytest.raises(NotImplementedError):
encryptor.update_into(b"\x00" * 16, buf)

@pytest.mark.supported(
only_if=lambda backend: backend.cipher_supported(
AES(b"\x00" * 16), modes.ECB()
),
skip_message="Does not support AES ECB",
)
def test_cffi_too_old_ecb(self, backend):
self._too_old(modes.ECB(), backend)

@pytest.mark.supported(
only_if=lambda backend: backend.cipher_supported(
AES(b"\x00" * 16), modes.CTR(b"0" * 16)
),
skip_message="Does not support AES CTR",
)
def test_cffi_too_old_ctr(self, backend):
self._too_old(modes.CTR(b"0" * 16), backend)

@pytest.mark.supported(
only_if=lambda backend: backend.cipher_supported(
AES(b"\x00" * 16), modes.GCM(b"0" * 16)
),
skip_message="Does not support AES GCM",
)
def test_cffi_too_old_gcm(self, backend):
self._too_old(modes.GCM(b"0" * 16), backend)
8 changes: 0 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ basepython = python2.7
commands =
sphinx-build -W -b linkcheck docs docs/_build/html

# This target disables coverage on pypy because of performance problems with
# coverage.py on pypy.
[testenv:pypy-nocoverage]
basepython = pypy
commands =
pip list
py.test --capture=no --strict {posargs}

[testenv:pep8]
extras =
pep8test
Expand Down

0 comments on commit 6091e11

Please sign in to comment.