diff options
Diffstat (limited to 'tests/hazmat')
| -rw-r--r-- | tests/hazmat/primitives/test_cmac.py | 13 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_hmac.py | 10 | 
2 files changed, 23 insertions, 0 deletions
| diff --git a/tests/hazmat/primitives/test_cmac.py b/tests/hazmat/primitives/test_cmac.py index 2ca05d6d..e319396d 100644 --- a/tests/hazmat/primitives/test_cmac.py +++ b/tests/hazmat/primitives/test_cmac.py @@ -183,6 +183,19 @@ class TestCMAC(object):          copy_cmac = cmac.copy()          assert cmac.finalize() == copy_cmac.finalize() +    @pytest.mark.supported( +        only_if=lambda backend: backend.cmac_algorithm_supported( +            AES(fake_key)), +        skip_message="Does not support CMAC." +    ) +    def test_buffer_protocol(self, backend): +        key = bytearray(b"2b7e151628aed2a6abf7158809cf4f3c") +        cmac = CMAC(AES(key), backend) +        cmac.update(b"6bc1bee22e409f96e93d7e117393172a") +        assert cmac.finalize() == binascii.unhexlify( +            b"a21e6e647bfeaf5ca0a5e1bcd957dfad" +        ) +  def test_invalid_backend():      key = b"2b7e151628aed2a6abf7158809cf4f3c" diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py index 50aa9cc2..b6d18ff1 100644 --- a/tests/hazmat/primitives/test_hmac.py +++ b/tests/hazmat/primitives/test_hmac.py @@ -4,6 +4,8 @@  from __future__ import absolute_import, division, print_function +import binascii +  import pytest  from cryptography.exceptions import ( @@ -79,6 +81,14 @@ class TestHMAC(object):          with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):              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(b"6bc1bee22e409f96e93d7e117393172a") +        assert h.finalize() == binascii.unhexlify( +            b"a1bf7169c56a501c6585190ff4f07cad6e492a3ee187c0372614fb444b9fc3f0" +        ) +  def test_invalid_backend():      pretend_backend = object() | 
