aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2019-01-16 19:10:48 -0600
committerAlex Gaynor <alex.gaynor@gmail.com>2019-01-16 20:10:48 -0500
commitbfc6fae472457c37abafb3818b44f0bd639be6cc (patch)
tree6670cd7d3ee34e8af308f4fe27af6dcb5a89d9b5 /tests/hazmat
parentc6656af81d3b4440d0d1032fd82e64d717541d62 (diff)
downloadcryptography-bfc6fae472457c37abafb3818b44f0bd639be6cc.tar.gz
cryptography-bfc6fae472457c37abafb3818b44f0bd639be6cc.tar.bz2
cryptography-bfc6fae472457c37abafb3818b44f0bd639be6cc.zip
support bytes-like keys in CMAC and HMAC contexts (#4701)
Diffstat (limited to 'tests/hazmat')
-rw-r--r--tests/hazmat/primitives/test_cmac.py13
-rw-r--r--tests/hazmat/primitives/test_hmac.py10
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()