Merge branch 'master' into more-error-condition

Conflicts:
	tests/hazmat/bindings/test_openssl.py
diff --git a/cryptography/hazmat/bindings/openssl/backend.py b/cryptography/hazmat/bindings/openssl/backend.py
index 7367818..ea1073b 100644
--- a/cryptography/hazmat/bindings/openssl/backend.py
+++ b/cryptography/hazmat/bindings/openssl/backend.py
@@ -147,7 +147,9 @@
             raise UnsupportedAlgorithm
 
         evp_cipher = adapter(self._backend, cipher, mode)
-        assert evp_cipher != self._backend.ffi.NULL
+        if evp_cipher == self._backend.ffi.NULL:
+            raise UnsupportedAlgorithm
+
         if isinstance(mode, interfaces.ModeWithInitializationVector):
             iv_nonce = mode.initialization_vector
         elif isinstance(mode, interfaces.ModeWithNonce):
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index fb01c10..3523fa4 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -11,11 +11,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import binascii
+
 import pytest
 
+from cryptography.exceptions import UnsupportedAlgorithm
 from cryptography.hazmat.bindings.openssl.backend import backend, Backend
-from cryptography.hazmat.primitives.block.ciphers import AES
-from cryptography.hazmat.primitives.block.modes import CBC
+from cryptography.hazmat.primitives.block import BlockCipher
+from cryptography.hazmat.primitives.block.ciphers import AES, TripleDES
+from cryptography.hazmat.primitives.block.modes import CBC, ECB
 
 
 class TestOpenSSL(object):
@@ -44,3 +48,15 @@
         b = Backend()
         assert b.ffi is backend.ffi
         assert b.lib is backend.lib
+
+    def test_nonexistent_cipher(self):
+        b = Backend()
+        # TODO: this test assumes that 3DES-ECB doesn't exist
+        b.ciphers.register_cipher_adapter(
+            TripleDES, ECB, lambda backend, cipher, mode: backend.ffi.NULL
+        )
+        cipher = BlockCipher(
+            TripleDES(binascii.unhexlify(b"0" * 16)), ECB(), backend=b
+        )
+        with pytest.raises(UnsupportedAlgorithm):
+            cipher.encryptor()