From 2d02857b4b1d6d8adbdd1fa1a753a2c464860bcf Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 30 Jan 2014 11:36:10 -0800 Subject: Added support for HMAC backend --- cryptography/hazmat/backends/multibackend.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py index 210efbe8..035517ea 100644 --- a/cryptography/hazmat/backends/multibackend.py +++ b/cryptography/hazmat/backends/multibackend.py @@ -15,11 +15,14 @@ from __future__ import absolute_import, division, print_function from cryptography import utils from cryptography.exceptions import UnsupportedAlgorithm -from cryptography.hazmat.backends.interfaces import CipherBackend, HashBackend +from cryptography.hazmat.backends.interfaces import ( + CipherBackend, HashBackend, HMACBackend +) @utils.register_interface(CipherBackend) @utils.register_interface(HashBackend) +@utils.register_interface(HMACBackend) class PrioritizedMultiBackend(object): name = "multibackend" @@ -55,3 +58,14 @@ class PrioritizedMultiBackend(object): except UnsupportedAlgorithm: pass raise UnsupportedAlgorithm + + def hmac_supported(self, algorithm): + return any(b.hmac_supported(algorithm) for b in self._backends) + + def create_hmac_ctx(self, key, algorithm): + for b in self._backends: + try: + return b.create_hmac_ctx(key, algorithm) + except UnsupportedAlgorithm: + pass + raise UnsupportedAlgorithm -- cgit v1.2.3