blob: 0aae04a76186c25b6db8fd849c238c475e7e16ae [file] [log] [blame]
Alex Gaynor450bb4c2014-02-03 15:42:04 -08001.. hazmat::
2
3MultiBackend
4============
5
6.. currentmodule:: cryptography.hazmat.backends.multibackend
7
8.. class:: MultiBackend(backends)
9
Alex Gaynordb809542014-02-03 16:19:32 -080010 .. versionadded:: 0.2
11
Alex Gaynor450bb4c2014-02-03 15:42:04 -080012 This class allows you to combine multiple backends into a single backend
Alex Stapleton63b3de22014-02-08 09:43:16 +000013 that offers the combined features of all of its constituents.
Alex Gaynor450bb4c2014-02-03 15:42:04 -080014
Alex Stapletonfaf305b2014-07-12 12:27:37 +010015 .. testsetup::
16
17 from cryptography import utils
18 from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
19 from cryptography.hazmat.backends.interfaces import HashBackend
20 from cryptography.hazmat.backends.openssl.backend import backend as backend2
21
22 @utils.register_interface(HashBackend)
23 class DummyHashBackend(object):
24 def hash_supported(self, algorithm):
25 return False
26
27 def create_hash_ctx(self, algorithm):
28 raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_HASH)
29
30 backend1 = DummyHashBackend()
31
32 .. doctest::
Alex Gaynor55988502014-02-03 16:15:06 -080033
34 >>> from cryptography.hazmat.backends.multibackend import MultiBackend
35 >>> from cryptography.hazmat.primitives import hashes
36 >>> backend1.hash_supported(hashes.SHA256())
37 False
Alex Gaynor1fb45242014-02-03 16:53:35 -080038 >>> backend2.hash_supported(hashes.SHA256())
Alex Gaynor55988502014-02-03 16:15:06 -080039 True
40 >>> multi_backend = MultiBackend([backend1, backend2])
Alex Gaynor1fb45242014-02-03 16:53:35 -080041 >>> multi_backend.hash_supported(hashes.SHA256())
Alex Gaynor55988502014-02-03 16:15:06 -080042 True
43
Alex Gaynor450bb4c2014-02-03 15:42:04 -080044 :param backends: A ``list`` of backend objects. Backends are checked for
Alex Gaynor2b1752e2014-02-03 16:11:23 -080045 feature support in the order they appear in this list.