aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-01-30 15:42:37 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2014-01-30 15:42:37 -0800
commitebc5161f606fe1ac7d51b6ab997f663cfcf9be9b (patch)
tree833540b1b45ec859e48e62efb3b1449bab63a1d0 /cryptography
parent0929f8ff07e71410bd2ce89d407805bd476c1761 (diff)
downloadcryptography-ebc5161f606fe1ac7d51b6ab997f663cfcf9be9b.tar.gz
cryptography-ebc5161f606fe1ac7d51b6ab997f663cfcf9be9b.tar.bz2
cryptography-ebc5161f606fe1ac7d51b6ab997f663cfcf9be9b.zip
Fix
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/hazmat/backends/multibackend.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py
index e560c7df..94152370 100644
--- a/cryptography/hazmat/backends/multibackend.py
+++ b/cryptography/hazmat/backends/multibackend.py
@@ -30,11 +30,19 @@ class PrioritizedMultiBackend(object):
def __init__(self, backends):
self._backends = backends
+ def _filtered_backends(self, interface):
+ for b in self._backends:
+ if isinstance(b, interface):
+ yield b
+
def cipher_supported(self, algorithm, mode):
- return any(b.cipher_supported(algorithm, mode) for b in self._backends)
+ return any(
+ b.cipher_supported(algorithm, mode)
+ for b in self._filtered_backends(CipherBackend)
+ )
def create_symmetric_encryption_ctx(self, algorithm, mode):
- for b in self._backends:
+ for b in self._filtered_backends(CipherBackend):
try:
return b.create_symmetric_encryption_ctx(algorithm, mode)
except UnsupportedAlgorithm:
@@ -42,7 +50,7 @@ class PrioritizedMultiBackend(object):
raise UnsupportedAlgorithm
def create_symmetric_decryption_ctx(self, algorithm, mode):
- for b in self._backends:
+ for b in self._filtered_backends(CipherBackend):
try:
return b.create_symmetric_decryption_ctx(algorithm, mode)
except UnsupportedAlgorithm:
@@ -50,10 +58,13 @@ class PrioritizedMultiBackend(object):
raise UnsupportedAlgorithm
def hash_supported(self, algorithm):
- return any(b.hash_supported(algorithm) for b in self._backends)
+ return any(
+ b.hash_supported(algorithm)
+ for b in self._filtered_backends(HashBackend)
+ )
def create_hash_ctx(self, algorithm):
- for b in self._backends:
+ for b in self._filtered_backends(HashBackend):
try:
return b.create_hash_ctx(algorithm)
except UnsupportedAlgorithm:
@@ -61,10 +72,13 @@ class PrioritizedMultiBackend(object):
raise UnsupportedAlgorithm
def hmac_supported(self, algorithm):
- return any(b.hmac_supported(algorithm) for b in self._backends)
+ return any(
+ b.hmac_supported(algorithm)
+ for b in self._filtered_backends(HMACBackend)
+ )
def create_hmac_ctx(self, key, algorithm):
- for b in self._backends:
+ for b in self._filtered_backends(HMACBackend):
try:
return b.create_hmac_ctx(key, algorithm)
except UnsupportedAlgorithm:
@@ -72,11 +86,14 @@ class PrioritizedMultiBackend(object):
raise UnsupportedAlgorithm
def pbkdf2_hmac_supported(self, algorithm):
- return any(b.pbkdf2_hmac_supported(algorithm) for b in self._backends)
+ return any(
+ b.pbkdf2_hmac_supported(algorithm)
+ for b in self._filtered_backends(PBKDF2HMACBackend)
+ )
def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,
key_material):
- for b in self._backends:
+ for b in self._filtered_backends(PBKDF2HMACBackend):
try:
return b.derive_pbkdf2_hmac(
algorithm, length, salt, iterations, key_material