aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorDavid Reid <dreid@dreid.org>2013-10-29 10:05:47 -0700
committerDavid Reid <dreid@dreid.org>2013-10-29 10:05:47 -0700
commita9d9922f82d4e7b940679c4b548a4b14d0958ed9 (patch)
treefe842ec8a06805dd12092721982afdc213072772 /tests/utils.py
parentc402f359864f91132a31631c97713fb8293a3bd8 (diff)
parent50a881572bc7617d4d49c4ae7b200c3bcb7398d9 (diff)
downloadcryptography-a9d9922f82d4e7b940679c4b548a4b14d0958ed9.tar.gz
cryptography-a9d9922f82d4e7b940679c4b548a4b14d0958ed9.tar.bz2
cryptography-a9d9922f82d4e7b940679c4b548a4b14d0958ed9.zip
Merge pull request #157 from reaperhulk/hmac
HMAC support
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 9d01746a..ad676c04 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -127,6 +127,9 @@ def load_openssl_vectors(vector_data):
def load_hash_vectors(vector_data):
vectors = []
+ key = None
+ msg = None
+ md = None
for line in vector_data:
line = line.strip()
@@ -136,6 +139,11 @@ 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.
+ """
+ key = line.split(" = ")[1].encode("ascii")
elif line.startswith("Msg"):
"""
In the NIST vectors they have chosen to represent an empty
@@ -145,8 +153,16 @@ def load_hash_vectors(vector_data):
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 tuple is complete
- vectors.append((msg, md))
+ # after MD is found the Msg+MD (+ potential key) tuple is complete
+ if key is not None:
+ vectors.append((msg, md, key))
+ key = None
+ msg = None
+ md = None
+ else:
+ vectors.append((msg, md))
+ msg = None
+ md = None
else:
raise ValueError("Unknown line in hash vector")
return vectors