diff options
author | David Reid <dreid@dreid.org> | 2013-11-02 23:16:33 -0700 |
---|---|---|
committer | David Reid <dreid@dreid.org> | 2013-11-02 23:16:33 -0700 |
commit | d4e98f8d552843c371600c88e1cdab94678081a9 (patch) | |
tree | 5699ddce355497cbb6890e9c55013d64e7cfc9d8 /cryptography | |
parent | 178f6f19a611219f27a0b4e1837134b308de08d2 (diff) | |
parent | 3949f1171084c2e1cfe43f638857ea0e0f8f246d (diff) | |
download | cryptography-d4e98f8d552843c371600c88e1cdab94678081a9.tar.gz cryptography-d4e98f8d552843c371600c88e1cdab94678081a9.tar.bz2 cryptography-d4e98f8d552843c371600c88e1cdab94678081a9.zip |
Merge pull request #215 from alex/unsupported-cipher
Document and implement the public API for when the backend doesn't suppo...
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/exceptions.py | 16 | ||||
-rw-r--r-- | cryptography/hazmat/bindings/openssl/backend.py | 10 |
2 files changed, 23 insertions, 3 deletions
diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py new file mode 100644 index 00000000..391bed82 --- /dev/null +++ b/cryptography/exceptions.py @@ -0,0 +1,16 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class UnsupportedAlgorithm(Exception): + pass diff --git a/cryptography/hazmat/bindings/openssl/backend.py b/cryptography/hazmat/bindings/openssl/backend.py index fc73dd39..32adfed9 100644 --- a/cryptography/hazmat/bindings/openssl/backend.py +++ b/cryptography/hazmat/bindings/openssl/backend.py @@ -18,6 +18,7 @@ import sys import cffi +from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.block.ciphers import ( AES, Blowfish, Camellia, CAST5, TripleDES, @@ -128,9 +129,12 @@ class _CipherContext(object): ctx = self._backend.ffi.gc(ctx, self._backend.lib.EVP_CIPHER_CTX_free) registry = self._backend.ciphers._cipher_registry - evp_cipher = registry[type(cipher), type(mode)]( - self._backend, cipher, mode - ) + try: + adapter = registry[type(cipher), type(mode)] + except KeyError: + raise UnsupportedAlgorithm + + evp_cipher = adapter(self._backend, cipher, mode) assert evp_cipher != self._backend.ffi.NULL if isinstance(mode, interfaces.ModeWithInitializationVector): iv_nonce = mode.initialization_vector |