aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/utils.py7
-rw-r--r--tests/utils.py23
2 files changed, 15 insertions, 15 deletions
diff --git a/tests/hazmat/primitives/utils.py b/tests/hazmat/primitives/utils.py
index 6ecc70ff..f27afe41 100644
--- a/tests/hazmat/primitives/utils.py
+++ b/tests/hazmat/primitives/utils.py
@@ -141,8 +141,7 @@ def generate_hash_test(param_loader, path, file_names, hash_cls):
def hash_test(backend, algorithm, params):
- msg = params[0]
- md = params[1]
+ msg, md = params
m = hashes.Hash(algorithm, backend=backend)
m.update(binascii.unhexlify(msg))
expected_md = md.replace(" ", "").lower().encode("ascii")
@@ -206,9 +205,7 @@ def generate_hmac_test(param_loader, path, file_names, algorithm):
def hmac_test(backend, algorithm, params):
- msg = params[0]
- md = params[1]
- key = params[2]
+ msg, md, key = params
h = hmac.HMAC(binascii.unhexlify(key), algorithm, backend=backend)
h.update(binascii.unhexlify(msg))
assert h.finalize() == binascii.unhexlify(md.encode("ascii"))
diff --git a/tests/utils.py b/tests/utils.py
index a2432256..507bc421 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -11,11 +11,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import collections
import os
import pytest
+HashVector = collections.namedtuple("HashVector", ["message", "digest"])
+KeyedHashVector = collections.namedtuple(
+ "KeyedHashVector", ["message", "digest", "key"]
+)
+
+
def select_backends(names, backend_list):
if names is None:
return backend_list
@@ -158,27 +165,23 @@ def load_hash_vectors(vector_data):
if line.startswith("Len"):
length = int(line.split(" = ")[1])
elif line.startswith("Key"):
- """
- HMAC vectors contain a key attribute. Hash vectors do not.
- """
+ # HMAC vectors contain a key attribute. Hash vectors do not.
key = line.split(" = ")[1].encode("ascii")
elif line.startswith("Msg"):
- """
- In the NIST vectors they have chosen to represent an empty
- string as hex 00, which is of course not actually an empty
- string. So we parse the provided length and catch this edge case.
- """
+ # In the NIST vectors they have chosen to represent an empty
+ # string as hex 00, which is of course not actually an empty
+ # string. So we parse the provided length and catch this edge case.
msg = line.split(" = ")[1].encode("ascii") if length > 0 else b""
elif line.startswith("MD"):
md = line.split(" = ")[1]
# after MD is found the Msg+MD (+ potential key) tuple is complete
if key is not None:
- vectors.append((msg, md, key))
+ vectors.append(KeyedHashVector(msg, md, key))
key = None
msg = None
md = None
else:
- vectors.append((msg, md))
+ vectors.append(HashVector(msg, md))
msg = None
md = None
else: