aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat/primitives/hmac.py
diff options
context:
space:
mode:
authorAyrx <terrycwk1994@gmail.com>2014-03-16 14:14:17 +0800
committerAyrx <terrycwk1994@gmail.com>2014-03-16 14:14:17 +0800
commitecac0290b7fedc71e72b1fb0a7bfc02433a11f7f (patch)
treecae9a09b6ab5349ce6dfdf43180054d5a9e10d7a /cryptography/hazmat/primitives/hmac.py
parent3fb221f1fb02ffed7a558bd06ba41bb75c329fc5 (diff)
downloadcryptography-ecac0290b7fedc71e72b1fb0a7bfc02433a11f7f.tar.gz
cryptography-ecac0290b7fedc71e72b1fb0a7bfc02433a11f7f.tar.bz2
cryptography-ecac0290b7fedc71e72b1fb0a7bfc02433a11f7f.zip
Added backend check to hmac primitives
Diffstat (limited to 'cryptography/hazmat/primitives/hmac.py')
-rw-r--r--cryptography/hazmat/primitives/hmac.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/cryptography/hazmat/primitives/hmac.py b/cryptography/hazmat/primitives/hmac.py
index 76d658aa..9e1d8d02 100644
--- a/cryptography/hazmat/primitives/hmac.py
+++ b/cryptography/hazmat/primitives/hmac.py
@@ -16,13 +16,20 @@ from __future__ import absolute_import, division, print_function
import six
from cryptography import utils
-from cryptography.exceptions import AlreadyFinalized, InvalidSignature
+from cryptography.exceptions import (
+ AlreadyFinalized, InvalidSignature, UnsupportedInterface)
+
+from cryptography.hazmat.backends.interfaces import HMACBackend
from cryptography.hazmat.primitives import constant_time, interfaces
@utils.register_interface(interfaces.HashContext)
class HMAC(object):
def __init__(self, key, algorithm, backend, ctx=None):
+ if not isinstance(backend, HMACBackend):
+ raise UnsupportedInterface(
+ "Backend object does not implement HMACBackend")
+
if not isinstance(algorithm, interfaces.HashAlgorithm):
raise TypeError("Expected instance of interfaces.HashAlgorithm.")
self.algorithm = algorithm