diff options
| author | Ayrx <terrycwk1994@gmail.com> | 2014-03-16 13:06:25 +0800 |
|---|---|---|
| committer | Ayrx <terrycwk1994@gmail.com> | 2014-03-16 13:06:25 +0800 |
| commit | b482ca185fc1fa0a6cce614c442c35c2fbfac906 (patch) | |
| tree | e3c79014d612943c29b7c9be8503e4991e035b20 /cryptography | |
| parent | 3fb221f1fb02ffed7a558bd06ba41bb75c329fc5 (diff) | |
| download | cryptography-b482ca185fc1fa0a6cce614c442c35c2fbfac906.tar.gz cryptography-b482ca185fc1fa0a6cce614c442c35c2fbfac906.tar.bz2 cryptography-b482ca185fc1fa0a6cce614c442c35c2fbfac906.zip | |
Added backend check to hash primitives
Diffstat (limited to 'cryptography')
| -rw-r--r-- | cryptography/hazmat/primitives/hashes.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/cryptography/hazmat/primitives/hashes.py b/cryptography/hazmat/primitives/hashes.py index bee188b3..409f564e 100644 --- a/cryptography/hazmat/primitives/hashes.py +++ b/cryptography/hazmat/primitives/hashes.py @@ -16,13 +16,18 @@ from __future__ import absolute_import, division, print_function import six from cryptography import utils -from cryptography.exceptions import AlreadyFinalized +from cryptography.exceptions import AlreadyFinalized, UnsupportedInterface +from cryptography.hazmat.backends.interfaces import HashBackend from cryptography.hazmat.primitives import interfaces @utils.register_interface(interfaces.HashContext) class Hash(object): def __init__(self, algorithm, backend, ctx=None): + if not isinstance(backend, HashBackend): + raise UnsupportedInterface( + "Backend object does not implement HashBackend") + if not isinstance(algorithm, interfaces.HashAlgorithm): raise TypeError("Expected instance of interfaces.HashAlgorithm.") self.algorithm = algorithm |
