We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
MultiBackend doesn't implement TraditionalOpenSSLSerializationBackend


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cryptography/hazmat/backends/multibackend.py`
Content:
```
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 #    http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10 # implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 
14 from __future__ import absolute_import, division, print_function
15 
16 from cryptography import utils
17 from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
18 from cryptography.hazmat.backends.interfaces import (
19     CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend,
20     HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend, RSABackend
21 )
22 
23 
24 @utils.register_interface(CMACBackend)
25 @utils.register_interface(CipherBackend)
26 @utils.register_interface(HashBackend)
27 @utils.register_interface(HMACBackend)
28 @utils.register_interface(PBKDF2HMACBackend)
29 @utils.register_interface(PKCS8SerializationBackend)
30 @utils.register_interface(RSABackend)
31 @utils.register_interface(DSABackend)
32 @utils.register_interface(EllipticCurveBackend)
33 class MultiBackend(object):
34     name = "multibackend"
35 
36     def __init__(self, backends):
37         self._backends = backends
38 
39     def _filtered_backends(self, interface):
40         for b in self._backends:
41             if isinstance(b, interface):
42                 yield b
43 
44     def cipher_supported(self, algorithm, mode):
45         return any(
46             b.cipher_supported(algorithm, mode)
47             for b in self._filtered_backends(CipherBackend)
48         )
49 
50     def create_symmetric_encryption_ctx(self, algorithm, mode):
51         for b in self._filtered_backends(CipherBackend):
52             try:
53                 return b.create_symmetric_encryption_ctx(algorithm, mode)
54             except UnsupportedAlgorithm:
55                 pass
56         raise UnsupportedAlgorithm(
57             "cipher {0} in {1} mode is not supported by this backend.".format(
58                 algorithm.name, mode.name if mode else mode),
59             _Reasons.UNSUPPORTED_CIPHER
60         )
61 
62     def create_symmetric_decryption_ctx(self, algorithm, mode):
63         for b in self._filtered_backends(CipherBackend):
64             try:
65                 return b.create_symmetric_decryption_ctx(algorithm, mode)
66             except UnsupportedAlgorithm:
67                 pass
68         raise UnsupportedAlgorithm(
69             "cipher {0} in {1} mode is not supported by this backend.".format(
70                 algorithm.name, mode.name if mode else mode),
71             _Reasons.UNSUPPORTED_CIPHER
72         )
73 
74     def hash_supported(self, algorithm):
75         return any(
76             b.hash_supported(algorithm)
77             for b in self._filtered_backends(HashBackend)
78         )
79 
80     def create_hash_ctx(self, algorithm):
81         for b in self._filtered_backends(HashBackend):
82             try:
83                 return b.create_hash_ctx(algorithm)
84             except UnsupportedAlgorithm:
85                 pass
86         raise UnsupportedAlgorithm(
87             "{0} is not a supported hash on this backend.".format(
88                 algorithm.name),
89             _Reasons.UNSUPPORTED_HASH
90         )
91 
92     def hmac_supported(self, algorithm):
93         return any(
94             b.hmac_supported(algorithm)
95             for b in self._filtered_backends(HMACBackend)
96         )
97 
98     def create_hmac_ctx(self, key, algorithm):
99         for b in self._filtered_backends(HMACBackend):
100             try:
101                 return b.create_hmac_ctx(key, algorithm)
102             except UnsupportedAlgorithm:
103                 pass
104         raise UnsupportedAlgorithm(
105             "{0} is not a supported hash on this backend.".format(
106                 algorithm.name),
107             _Reasons.UNSUPPORTED_HASH
108         )
109 
110     def pbkdf2_hmac_supported(self, algorithm):
111         return any(
112             b.pbkdf2_hmac_supported(algorithm)
113             for b in self._filtered_backends(PBKDF2HMACBackend)
114         )
115 
116     def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,
117                            key_material):
118         for b in self._filtered_backends(PBKDF2HMACBackend):
119             try:
120                 return b.derive_pbkdf2_hmac(
121                     algorithm, length, salt, iterations, key_material
122                 )
123             except UnsupportedAlgorithm:
124                 pass
125         raise UnsupportedAlgorithm(
126             "{0} is not a supported hash on this backend.".format(
127                 algorithm.name),
128             _Reasons.UNSUPPORTED_HASH
129         )
130 
131     def generate_rsa_private_key(self, public_exponent, key_size):
132         for b in self._filtered_backends(RSABackend):
133             return b.generate_rsa_private_key(public_exponent, key_size)
134         raise UnsupportedAlgorithm("RSA is not supported by the backend.",
135                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
136 
137     def generate_rsa_parameters_supported(self, public_exponent, key_size):
138         for b in self._filtered_backends(RSABackend):
139             return b.generate_rsa_parameters_supported(
140                 public_exponent, key_size
141             )
142         raise UnsupportedAlgorithm("RSA is not supported by the backend.",
143                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
144 
145     def create_rsa_signature_ctx(self, private_key, padding, algorithm):
146         for b in self._filtered_backends(RSABackend):
147             return b.create_rsa_signature_ctx(private_key, padding, algorithm)
148         raise UnsupportedAlgorithm("RSA is not supported by the backend.",
149                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
150 
151     def create_rsa_verification_ctx(self, public_key, signature, padding,
152                                     algorithm):
153         for b in self._filtered_backends(RSABackend):
154             return b.create_rsa_verification_ctx(public_key, signature,
155                                                  padding, algorithm)
156         raise UnsupportedAlgorithm("RSA is not supported by the backend.",
157                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
158 
159     def mgf1_hash_supported(self, algorithm):
160         for b in self._filtered_backends(RSABackend):
161             return b.mgf1_hash_supported(algorithm)
162         raise UnsupportedAlgorithm("RSA is not supported by the backend.",
163                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
164 
165     def decrypt_rsa(self, private_key, ciphertext, padding):
166         for b in self._filtered_backends(RSABackend):
167             return b.decrypt_rsa(private_key, ciphertext, padding)
168         raise UnsupportedAlgorithm("RSA is not supported by the backend.",
169                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
170 
171     def encrypt_rsa(self, public_key, plaintext, padding):
172         for b in self._filtered_backends(RSABackend):
173             return b.encrypt_rsa(public_key, plaintext, padding)
174         raise UnsupportedAlgorithm("RSA is not supported by the backend.",
175                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
176 
177     def rsa_padding_supported(self, padding):
178         for b in self._filtered_backends(RSABackend):
179             return b.rsa_padding_supported(padding)
180         raise UnsupportedAlgorithm("RSA is not supported by the backend.",
181                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
182 
183     def load_rsa_private_numbers(self, numbers):
184         for b in self._filtered_backends(RSABackend):
185             return b.load_rsa_private_numbers(numbers)
186 
187         raise UnsupportedAlgorithm("RSA is not supported by the backend",
188                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
189 
190     def load_rsa_public_numbers(self, numbers):
191         for b in self._filtered_backends(RSABackend):
192             return b.load_rsa_public_numbers(numbers)
193 
194         raise UnsupportedAlgorithm("RSA is not supported by the backend",
195                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
196 
197     def generate_dsa_parameters(self, key_size):
198         for b in self._filtered_backends(DSABackend):
199             return b.generate_dsa_parameters(key_size)
200         raise UnsupportedAlgorithm("DSA is not supported by the backend.",
201                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
202 
203     def generate_dsa_private_key(self, parameters):
204         for b in self._filtered_backends(DSABackend):
205             return b.generate_dsa_private_key(parameters)
206         raise UnsupportedAlgorithm("DSA is not supported by the backend.",
207                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
208 
209     def generate_dsa_private_key_and_parameters(self, key_size):
210         for b in self._filtered_backends(DSABackend):
211             return b.generate_dsa_private_key_and_parameters(key_size)
212         raise UnsupportedAlgorithm("DSA is not supported by the backend.",
213                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
214 
215     def create_dsa_verification_ctx(self, public_key, signature, algorithm):
216         for b in self._filtered_backends(DSABackend):
217             return b.create_dsa_verification_ctx(public_key, signature,
218                                                  algorithm)
219         raise UnsupportedAlgorithm("DSA is not supported by the backend.",
220                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
221 
222     def create_dsa_signature_ctx(self, private_key, algorithm):
223         for b in self._filtered_backends(DSABackend):
224             return b.create_dsa_signature_ctx(private_key, algorithm)
225         raise UnsupportedAlgorithm("DSA is not supported by the backend.",
226                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
227 
228     def dsa_hash_supported(self, algorithm):
229         for b in self._filtered_backends(DSABackend):
230             return b.dsa_hash_supported(algorithm)
231         raise UnsupportedAlgorithm("DSA is not supported by the backend.",
232                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
233 
234     def dsa_parameters_supported(self, p, q, g):
235         for b in self._filtered_backends(DSABackend):
236             return b.dsa_parameters_supported(p, q, g)
237         raise UnsupportedAlgorithm("DSA is not supported by the backend.",
238                                    _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
239 
240     def cmac_algorithm_supported(self, algorithm):
241         return any(
242             b.cmac_algorithm_supported(algorithm)
243             for b in self._filtered_backends(CMACBackend)
244         )
245 
246     def create_cmac_ctx(self, algorithm):
247         for b in self._filtered_backends(CMACBackend):
248             try:
249                 return b.create_cmac_ctx(algorithm)
250             except UnsupportedAlgorithm:
251                 pass
252         raise UnsupportedAlgorithm("This backend does not support CMAC.",
253                                    _Reasons.UNSUPPORTED_CIPHER)
254 
255     def elliptic_curve_supported(self, curve):
256         return any(
257             b.elliptic_curve_supported(curve)
258             for b in self._filtered_backends(EllipticCurveBackend)
259         )
260 
261     def elliptic_curve_signature_algorithm_supported(
262         self, signature_algorithm, curve
263     ):
264         return any(
265             b.elliptic_curve_signature_algorithm_supported(
266                 signature_algorithm, curve
267             )
268             for b in self._filtered_backends(EllipticCurveBackend)
269         )
270 
271     def generate_elliptic_curve_private_key(self, curve):
272         for b in self._filtered_backends(EllipticCurveBackend):
273             try:
274                 return b.generate_elliptic_curve_private_key(curve)
275             except UnsupportedAlgorithm:
276                 continue
277 
278         raise UnsupportedAlgorithm(
279             "This backend does not support this elliptic curve.",
280             _Reasons.UNSUPPORTED_ELLIPTIC_CURVE
281         )
282 
283     def elliptic_curve_private_key_from_numbers(self, numbers):
284         for b in self._filtered_backends(EllipticCurveBackend):
285             try:
286                 return b.elliptic_curve_private_key_from_numbers(numbers)
287             except UnsupportedAlgorithm:
288                 continue
289 
290         raise UnsupportedAlgorithm(
291             "This backend does not support this elliptic curve.",
292             _Reasons.UNSUPPORTED_ELLIPTIC_CURVE
293         )
294 
295     def elliptic_curve_public_key_from_numbers(self, numbers):
296         for b in self._filtered_backends(EllipticCurveBackend):
297             try:
298                 return b.elliptic_curve_public_key_from_numbers(numbers)
299             except UnsupportedAlgorithm:
300                 continue
301 
302         raise UnsupportedAlgorithm(
303             "This backend does not support this elliptic curve.",
304             _Reasons.UNSUPPORTED_ELLIPTIC_CURVE
305         )
306 
307     def load_pkcs8_pem_private_key(self, data, password):
308         for b in self._filtered_backends(PKCS8SerializationBackend):
309             return b.load_pkcs8_pem_private_key(data, password)
310 
311         raise UnsupportedAlgorithm(
312             "This backend does not support this key serialization.",
313             _Reasons.UNSUPPORTED_SERIALIZATION
314         )
315
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py
--- a/cryptography/hazmat/backends/multibackend.py
+++ b/cryptography/hazmat/backends/multibackend.py
@@ -17,7 +17,8 @@
 from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
 from cryptography.hazmat.backends.interfaces import (
     CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend,
-    HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend, RSABackend
+    HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend,
+    RSABackend, TraditionalOpenSSLSerializationBackend
 )
 
 
@@ -28,6 +29,7 @@
 @utils.register_interface(PBKDF2HMACBackend)
 @utils.register_interface(PKCS8SerializationBackend)
 @utils.register_interface(RSABackend)
+@utils.register_interface(TraditionalOpenSSLSerializationBackend)
 @utils.register_interface(DSABackend)
 @utils.register_interface(EllipticCurveBackend)
 class MultiBackend(object):
@@ -312,3 +314,14 @@
             "This backend does not support this key serialization.",
             _Reasons.UNSUPPORTED_SERIALIZATION
         )
+
+    def load_traditional_openssl_pem_private_key(self, data, password):
+        for b in self._filtered_backends(
+            TraditionalOpenSSLSerializationBackend
+        ):
+            return b.load_traditional_openssl_pem_private_key(data, password)
+
+        raise UnsupportedAlgorithm(
+            "This backend does not support this key serialization.",
+            _Reasons.UNSUPPORTED_SERIALIZATION
+        )

{"golden_diff": "diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py\n--- a/cryptography/hazmat/backends/multibackend.py\n+++ b/cryptography/hazmat/backends/multibackend.py\n@@ -17,7 +17,8 @@\n from cryptography.exceptions import UnsupportedAlgorithm, _Reasons\n from cryptography.hazmat.backends.interfaces import (\n     CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend,\n-    HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend, RSABackend\n+    HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend,\n+    RSABackend, TraditionalOpenSSLSerializationBackend\n )\n \n \n@@ -28,6 +29,7 @@\n @utils.register_interface(PBKDF2HMACBackend)\n @utils.register_interface(PKCS8SerializationBackend)\n @utils.register_interface(RSABackend)\n+@utils.register_interface(TraditionalOpenSSLSerializationBackend)\n @utils.register_interface(DSABackend)\n @utils.register_interface(EllipticCurveBackend)\n class MultiBackend(object):\n@@ -312,3 +314,14 @@\n             \"This backend does not support this key serialization.\",\n             _Reasons.UNSUPPORTED_SERIALIZATION\n         )\n+\n+    def load_traditional_openssl_pem_private_key(self, data, password):\n+        for b in self._filtered_backends(\n+            TraditionalOpenSSLSerializationBackend\n+        ):\n+            return b.load_traditional_openssl_pem_private_key(data, password)\n+\n+        raise UnsupportedAlgorithm(\n+            \"This backend does not support this key serialization.\",\n+            _Reasons.UNSUPPORTED_SERIALIZATION\n+        )\n", "issue": "MultiBackend doesn't implement TraditionalOpenSSLSerializationBackend\n\n", "before_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n# implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import, division, print_function\n\nfrom cryptography import utils\nfrom cryptography.exceptions import UnsupportedAlgorithm, _Reasons\nfrom cryptography.hazmat.backends.interfaces import (\n    CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend,\n    HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend, RSABackend\n)\n\n\n@utils.register_interface(CMACBackend)\n@utils.register_interface(CipherBackend)\n@utils.register_interface(HashBackend)\n@utils.register_interface(HMACBackend)\n@utils.register_interface(PBKDF2HMACBackend)\n@utils.register_interface(PKCS8SerializationBackend)\n@utils.register_interface(RSABackend)\n@utils.register_interface(DSABackend)\n@utils.register_interface(EllipticCurveBackend)\nclass MultiBackend(object):\n    name = \"multibackend\"\n\n    def __init__(self, backends):\n        self._backends = backends\n\n    def _filtered_backends(self, interface):\n        for b in self._backends:\n            if isinstance(b, interface):\n                yield b\n\n    def cipher_supported(self, algorithm, mode):\n        return any(\n            b.cipher_supported(algorithm, mode)\n            for b in self._filtered_backends(CipherBackend)\n        )\n\n    def create_symmetric_encryption_ctx(self, algorithm, mode):\n        for b in self._filtered_backends(CipherBackend):\n            try:\n                return b.create_symmetric_encryption_ctx(algorithm, mode)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"cipher {0} in {1} mode is not supported by this backend.\".format(\n                algorithm.name, mode.name if mode else mode),\n            _Reasons.UNSUPPORTED_CIPHER\n        )\n\n    def create_symmetric_decryption_ctx(self, algorithm, mode):\n        for b in self._filtered_backends(CipherBackend):\n            try:\n                return b.create_symmetric_decryption_ctx(algorithm, mode)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"cipher {0} in {1} mode is not supported by this backend.\".format(\n                algorithm.name, mode.name if mode else mode),\n            _Reasons.UNSUPPORTED_CIPHER\n        )\n\n    def hash_supported(self, algorithm):\n        return any(\n            b.hash_supported(algorithm)\n            for b in self._filtered_backends(HashBackend)\n        )\n\n    def create_hash_ctx(self, algorithm):\n        for b in self._filtered_backends(HashBackend):\n            try:\n                return b.create_hash_ctx(algorithm)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"{0} is not a supported hash on this backend.\".format(\n                algorithm.name),\n            _Reasons.UNSUPPORTED_HASH\n        )\n\n    def hmac_supported(self, algorithm):\n        return any(\n            b.hmac_supported(algorithm)\n            for b in self._filtered_backends(HMACBackend)\n        )\n\n    def create_hmac_ctx(self, key, algorithm):\n        for b in self._filtered_backends(HMACBackend):\n            try:\n                return b.create_hmac_ctx(key, algorithm)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"{0} is not a supported hash on this backend.\".format(\n                algorithm.name),\n            _Reasons.UNSUPPORTED_HASH\n        )\n\n    def pbkdf2_hmac_supported(self, algorithm):\n        return any(\n            b.pbkdf2_hmac_supported(algorithm)\n            for b in self._filtered_backends(PBKDF2HMACBackend)\n        )\n\n    def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,\n                           key_material):\n        for b in self._filtered_backends(PBKDF2HMACBackend):\n            try:\n                return b.derive_pbkdf2_hmac(\n                    algorithm, length, salt, iterations, key_material\n                )\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"{0} is not a supported hash on this backend.\".format(\n                algorithm.name),\n            _Reasons.UNSUPPORTED_HASH\n        )\n\n    def generate_rsa_private_key(self, public_exponent, key_size):\n        for b in self._filtered_backends(RSABackend):\n            return b.generate_rsa_private_key(public_exponent, key_size)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def generate_rsa_parameters_supported(self, public_exponent, key_size):\n        for b in self._filtered_backends(RSABackend):\n            return b.generate_rsa_parameters_supported(\n                public_exponent, key_size\n            )\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def create_rsa_signature_ctx(self, private_key, padding, algorithm):\n        for b in self._filtered_backends(RSABackend):\n            return b.create_rsa_signature_ctx(private_key, padding, algorithm)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def create_rsa_verification_ctx(self, public_key, signature, padding,\n                                    algorithm):\n        for b in self._filtered_backends(RSABackend):\n            return b.create_rsa_verification_ctx(public_key, signature,\n                                                 padding, algorithm)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def mgf1_hash_supported(self, algorithm):\n        for b in self._filtered_backends(RSABackend):\n            return b.mgf1_hash_supported(algorithm)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def decrypt_rsa(self, private_key, ciphertext, padding):\n        for b in self._filtered_backends(RSABackend):\n            return b.decrypt_rsa(private_key, ciphertext, padding)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def encrypt_rsa(self, public_key, plaintext, padding):\n        for b in self._filtered_backends(RSABackend):\n            return b.encrypt_rsa(public_key, plaintext, padding)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def rsa_padding_supported(self, padding):\n        for b in self._filtered_backends(RSABackend):\n            return b.rsa_padding_supported(padding)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def load_rsa_private_numbers(self, numbers):\n        for b in self._filtered_backends(RSABackend):\n            return b.load_rsa_private_numbers(numbers)\n\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def load_rsa_public_numbers(self, numbers):\n        for b in self._filtered_backends(RSABackend):\n            return b.load_rsa_public_numbers(numbers)\n\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def generate_dsa_parameters(self, key_size):\n        for b in self._filtered_backends(DSABackend):\n            return b.generate_dsa_parameters(key_size)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def generate_dsa_private_key(self, parameters):\n        for b in self._filtered_backends(DSABackend):\n            return b.generate_dsa_private_key(parameters)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def generate_dsa_private_key_and_parameters(self, key_size):\n        for b in self._filtered_backends(DSABackend):\n            return b.generate_dsa_private_key_and_parameters(key_size)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def create_dsa_verification_ctx(self, public_key, signature, algorithm):\n        for b in self._filtered_backends(DSABackend):\n            return b.create_dsa_verification_ctx(public_key, signature,\n                                                 algorithm)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def create_dsa_signature_ctx(self, private_key, algorithm):\n        for b in self._filtered_backends(DSABackend):\n            return b.create_dsa_signature_ctx(private_key, algorithm)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def dsa_hash_supported(self, algorithm):\n        for b in self._filtered_backends(DSABackend):\n            return b.dsa_hash_supported(algorithm)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def dsa_parameters_supported(self, p, q, g):\n        for b in self._filtered_backends(DSABackend):\n            return b.dsa_parameters_supported(p, q, g)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def cmac_algorithm_supported(self, algorithm):\n        return any(\n            b.cmac_algorithm_supported(algorithm)\n            for b in self._filtered_backends(CMACBackend)\n        )\n\n    def create_cmac_ctx(self, algorithm):\n        for b in self._filtered_backends(CMACBackend):\n            try:\n                return b.create_cmac_ctx(algorithm)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\"This backend does not support CMAC.\",\n                                   _Reasons.UNSUPPORTED_CIPHER)\n\n    def elliptic_curve_supported(self, curve):\n        return any(\n            b.elliptic_curve_supported(curve)\n            for b in self._filtered_backends(EllipticCurveBackend)\n        )\n\n    def elliptic_curve_signature_algorithm_supported(\n        self, signature_algorithm, curve\n    ):\n        return any(\n            b.elliptic_curve_signature_algorithm_supported(\n                signature_algorithm, curve\n            )\n            for b in self._filtered_backends(EllipticCurveBackend)\n        )\n\n    def generate_elliptic_curve_private_key(self, curve):\n        for b in self._filtered_backends(EllipticCurveBackend):\n            try:\n                return b.generate_elliptic_curve_private_key(curve)\n            except UnsupportedAlgorithm:\n                continue\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this elliptic curve.\",\n            _Reasons.UNSUPPORTED_ELLIPTIC_CURVE\n        )\n\n    def elliptic_curve_private_key_from_numbers(self, numbers):\n        for b in self._filtered_backends(EllipticCurveBackend):\n            try:\n                return b.elliptic_curve_private_key_from_numbers(numbers)\n            except UnsupportedAlgorithm:\n                continue\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this elliptic curve.\",\n            _Reasons.UNSUPPORTED_ELLIPTIC_CURVE\n        )\n\n    def elliptic_curve_public_key_from_numbers(self, numbers):\n        for b in self._filtered_backends(EllipticCurveBackend):\n            try:\n                return b.elliptic_curve_public_key_from_numbers(numbers)\n            except UnsupportedAlgorithm:\n                continue\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this elliptic curve.\",\n            _Reasons.UNSUPPORTED_ELLIPTIC_CURVE\n        )\n\n    def load_pkcs8_pem_private_key(self, data, password):\n        for b in self._filtered_backends(PKCS8SerializationBackend):\n            return b.load_pkcs8_pem_private_key(data, password)\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this key serialization.\",\n            _Reasons.UNSUPPORTED_SERIALIZATION\n        )\n", "path": "cryptography/hazmat/backends/multibackend.py"}], "after_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n# implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import, division, print_function\n\nfrom cryptography import utils\nfrom cryptography.exceptions import UnsupportedAlgorithm, _Reasons\nfrom cryptography.hazmat.backends.interfaces import (\n    CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend,\n    HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend,\n    RSABackend, TraditionalOpenSSLSerializationBackend\n)\n\n\n@utils.register_interface(CMACBackend)\n@utils.register_interface(CipherBackend)\n@utils.register_interface(HashBackend)\n@utils.register_interface(HMACBackend)\n@utils.register_interface(PBKDF2HMACBackend)\n@utils.register_interface(PKCS8SerializationBackend)\n@utils.register_interface(RSABackend)\n@utils.register_interface(TraditionalOpenSSLSerializationBackend)\n@utils.register_interface(DSABackend)\n@utils.register_interface(EllipticCurveBackend)\nclass MultiBackend(object):\n    name = \"multibackend\"\n\n    def __init__(self, backends):\n        self._backends = backends\n\n    def _filtered_backends(self, interface):\n        for b in self._backends:\n            if isinstance(b, interface):\n                yield b\n\n    def cipher_supported(self, algorithm, mode):\n        return any(\n            b.cipher_supported(algorithm, mode)\n            for b in self._filtered_backends(CipherBackend)\n        )\n\n    def create_symmetric_encryption_ctx(self, algorithm, mode):\n        for b in self._filtered_backends(CipherBackend):\n            try:\n                return b.create_symmetric_encryption_ctx(algorithm, mode)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"cipher {0} in {1} mode is not supported by this backend.\".format(\n                algorithm.name, mode.name if mode else mode),\n            _Reasons.UNSUPPORTED_CIPHER\n        )\n\n    def create_symmetric_decryption_ctx(self, algorithm, mode):\n        for b in self._filtered_backends(CipherBackend):\n            try:\n                return b.create_symmetric_decryption_ctx(algorithm, mode)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"cipher {0} in {1} mode is not supported by this backend.\".format(\n                algorithm.name, mode.name if mode else mode),\n            _Reasons.UNSUPPORTED_CIPHER\n        )\n\n    def hash_supported(self, algorithm):\n        return any(\n            b.hash_supported(algorithm)\n            for b in self._filtered_backends(HashBackend)\n        )\n\n    def create_hash_ctx(self, algorithm):\n        for b in self._filtered_backends(HashBackend):\n            try:\n                return b.create_hash_ctx(algorithm)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"{0} is not a supported hash on this backend.\".format(\n                algorithm.name),\n            _Reasons.UNSUPPORTED_HASH\n        )\n\n    def hmac_supported(self, algorithm):\n        return any(\n            b.hmac_supported(algorithm)\n            for b in self._filtered_backends(HMACBackend)\n        )\n\n    def create_hmac_ctx(self, key, algorithm):\n        for b in self._filtered_backends(HMACBackend):\n            try:\n                return b.create_hmac_ctx(key, algorithm)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"{0} is not a supported hash on this backend.\".format(\n                algorithm.name),\n            _Reasons.UNSUPPORTED_HASH\n        )\n\n    def pbkdf2_hmac_supported(self, algorithm):\n        return any(\n            b.pbkdf2_hmac_supported(algorithm)\n            for b in self._filtered_backends(PBKDF2HMACBackend)\n        )\n\n    def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,\n                           key_material):\n        for b in self._filtered_backends(PBKDF2HMACBackend):\n            try:\n                return b.derive_pbkdf2_hmac(\n                    algorithm, length, salt, iterations, key_material\n                )\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\n            \"{0} is not a supported hash on this backend.\".format(\n                algorithm.name),\n            _Reasons.UNSUPPORTED_HASH\n        )\n\n    def generate_rsa_private_key(self, public_exponent, key_size):\n        for b in self._filtered_backends(RSABackend):\n            return b.generate_rsa_private_key(public_exponent, key_size)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def generate_rsa_parameters_supported(self, public_exponent, key_size):\n        for b in self._filtered_backends(RSABackend):\n            return b.generate_rsa_parameters_supported(\n                public_exponent, key_size\n            )\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def create_rsa_signature_ctx(self, private_key, padding, algorithm):\n        for b in self._filtered_backends(RSABackend):\n            return b.create_rsa_signature_ctx(private_key, padding, algorithm)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def create_rsa_verification_ctx(self, public_key, signature, padding,\n                                    algorithm):\n        for b in self._filtered_backends(RSABackend):\n            return b.create_rsa_verification_ctx(public_key, signature,\n                                                 padding, algorithm)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def mgf1_hash_supported(self, algorithm):\n        for b in self._filtered_backends(RSABackend):\n            return b.mgf1_hash_supported(algorithm)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def decrypt_rsa(self, private_key, ciphertext, padding):\n        for b in self._filtered_backends(RSABackend):\n            return b.decrypt_rsa(private_key, ciphertext, padding)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def encrypt_rsa(self, public_key, plaintext, padding):\n        for b in self._filtered_backends(RSABackend):\n            return b.encrypt_rsa(public_key, plaintext, padding)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def rsa_padding_supported(self, padding):\n        for b in self._filtered_backends(RSABackend):\n            return b.rsa_padding_supported(padding)\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def load_rsa_private_numbers(self, numbers):\n        for b in self._filtered_backends(RSABackend):\n            return b.load_rsa_private_numbers(numbers)\n\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def load_rsa_public_numbers(self, numbers):\n        for b in self._filtered_backends(RSABackend):\n            return b.load_rsa_public_numbers(numbers)\n\n        raise UnsupportedAlgorithm(\"RSA is not supported by the backend\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def generate_dsa_parameters(self, key_size):\n        for b in self._filtered_backends(DSABackend):\n            return b.generate_dsa_parameters(key_size)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def generate_dsa_private_key(self, parameters):\n        for b in self._filtered_backends(DSABackend):\n            return b.generate_dsa_private_key(parameters)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def generate_dsa_private_key_and_parameters(self, key_size):\n        for b in self._filtered_backends(DSABackend):\n            return b.generate_dsa_private_key_and_parameters(key_size)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def create_dsa_verification_ctx(self, public_key, signature, algorithm):\n        for b in self._filtered_backends(DSABackend):\n            return b.create_dsa_verification_ctx(public_key, signature,\n                                                 algorithm)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def create_dsa_signature_ctx(self, private_key, algorithm):\n        for b in self._filtered_backends(DSABackend):\n            return b.create_dsa_signature_ctx(private_key, algorithm)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def dsa_hash_supported(self, algorithm):\n        for b in self._filtered_backends(DSABackend):\n            return b.dsa_hash_supported(algorithm)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def dsa_parameters_supported(self, p, q, g):\n        for b in self._filtered_backends(DSABackend):\n            return b.dsa_parameters_supported(p, q, g)\n        raise UnsupportedAlgorithm(\"DSA is not supported by the backend.\",\n                                   _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)\n\n    def cmac_algorithm_supported(self, algorithm):\n        return any(\n            b.cmac_algorithm_supported(algorithm)\n            for b in self._filtered_backends(CMACBackend)\n        )\n\n    def create_cmac_ctx(self, algorithm):\n        for b in self._filtered_backends(CMACBackend):\n            try:\n                return b.create_cmac_ctx(algorithm)\n            except UnsupportedAlgorithm:\n                pass\n        raise UnsupportedAlgorithm(\"This backend does not support CMAC.\",\n                                   _Reasons.UNSUPPORTED_CIPHER)\n\n    def elliptic_curve_supported(self, curve):\n        return any(\n            b.elliptic_curve_supported(curve)\n            for b in self._filtered_backends(EllipticCurveBackend)\n        )\n\n    def elliptic_curve_signature_algorithm_supported(\n        self, signature_algorithm, curve\n    ):\n        return any(\n            b.elliptic_curve_signature_algorithm_supported(\n                signature_algorithm, curve\n            )\n            for b in self._filtered_backends(EllipticCurveBackend)\n        )\n\n    def generate_elliptic_curve_private_key(self, curve):\n        for b in self._filtered_backends(EllipticCurveBackend):\n            try:\n                return b.generate_elliptic_curve_private_key(curve)\n            except UnsupportedAlgorithm:\n                continue\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this elliptic curve.\",\n            _Reasons.UNSUPPORTED_ELLIPTIC_CURVE\n        )\n\n    def elliptic_curve_private_key_from_numbers(self, numbers):\n        for b in self._filtered_backends(EllipticCurveBackend):\n            try:\n                return b.elliptic_curve_private_key_from_numbers(numbers)\n            except UnsupportedAlgorithm:\n                continue\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this elliptic curve.\",\n            _Reasons.UNSUPPORTED_ELLIPTIC_CURVE\n        )\n\n    def elliptic_curve_public_key_from_numbers(self, numbers):\n        for b in self._filtered_backends(EllipticCurveBackend):\n            try:\n                return b.elliptic_curve_public_key_from_numbers(numbers)\n            except UnsupportedAlgorithm:\n                continue\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this elliptic curve.\",\n            _Reasons.UNSUPPORTED_ELLIPTIC_CURVE\n        )\n\n    def load_pkcs8_pem_private_key(self, data, password):\n        for b in self._filtered_backends(PKCS8SerializationBackend):\n            return b.load_pkcs8_pem_private_key(data, password)\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this key serialization.\",\n            _Reasons.UNSUPPORTED_SERIALIZATION\n        )\n\n    def load_traditional_openssl_pem_private_key(self, data, password):\n        for b in self._filtered_backends(\n            TraditionalOpenSSLSerializationBackend\n        ):\n            return b.load_traditional_openssl_pem_private_key(data, password)\n\n        raise UnsupportedAlgorithm(\n            \"This backend does not support this key serialization.\",\n            _Reasons.UNSUPPORTED_SERIALIZATION\n        )\n", "path": "cryptography/hazmat/backends/multibackend.py"}]}