aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/test_hmac.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hazmat/primitives/test_hmac.py')
-rw-r--r--tests/hazmat/primitives/test_hmac.py30
1 files changed, 11 insertions, 19 deletions
diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py
index 83b18cbc..0e2fe688 100644
--- a/tests/hazmat/primitives/test_hmac.py
+++ b/tests/hazmat/primitives/test_hmac.py
@@ -4,11 +4,10 @@
from __future__ import absolute_import, division, print_function
-import pretend
+import binascii
import pytest
-from cryptography import utils
from cryptography.exceptions import (
AlreadyFinalized, InvalidSignature, _Reasons
)
@@ -16,17 +15,10 @@ from cryptography.hazmat.backends.interfaces import HMACBackend
from cryptography.hazmat.primitives import hashes, hmac
from .utils import generate_base_hmac_test
-from ..backends.test_multibackend import DummyHMACBackend
+from ...doubles import DummyHashAlgorithm
from ...utils import raises_unsupported_algorithm
-@utils.register_interface(hashes.HashAlgorithm)
-class UnsupportedDummyHash(object):
- name = "unsupported-dummy-hash"
- block_size = None
- digest_size = None
-
-
@pytest.mark.supported(
only_if=lambda backend: backend.hmac_supported(hashes.MD5()),
skip_message="Does not support MD5",
@@ -45,14 +37,6 @@ class TestHMAC(object):
with pytest.raises(TypeError):
h.update(u"\u00FC")
- def test_copy_backend_object(self):
- backend = DummyHMACBackend([hashes.SHA1])
- copied_ctx = pretend.stub()
- pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
- h = hmac.HMAC(b"key", hashes.SHA1(), backend=backend, ctx=pretend_ctx)
- assert h._backend is backend
- assert h.copy()._backend is backend
-
def test_hmac_algorithm_instance(self, backend):
with pytest.raises(TypeError):
hmac.HMAC(b"key", hashes.SHA1, backend=backend)
@@ -95,7 +79,15 @@ class TestHMAC(object):
def test_unsupported_hash(self, backend):
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):
- hmac.HMAC(b"key", UnsupportedDummyHash(), backend)
+ hmac.HMAC(b"key", DummyHashAlgorithm(), backend)
+
+ def test_buffer_protocol(self, backend):
+ key = bytearray(b"2b7e151628aed2a6abf7158809cf4f3c")
+ h = hmac.HMAC(key, hashes.SHA256(), backend)
+ h.update(bytearray(b"6bc1bee22e409f96e93d7e117393172a"))
+ assert h.finalize() == binascii.unhexlify(
+ b"a1bf7169c56a501c6585190ff4f07cad6e492a3ee187c0372614fb444b9fc3f0"
+ )
def test_invalid_backend():