aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-29 21:18:06 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-29 21:18:06 -0600
commit5ff316753118ac1445858a111c8d76da1c7c3e40 (patch)
treef7deaa2a7d54a77ec50e3e1a46f6f1849bc07ceb /tests/utils.py
parent3f17c7c68157ec04b98cb5fd61216a6644aa3a7c (diff)
parent307437b1b401aa3bfd8f911c150a825476d06d9c (diff)
downloadcryptography-5ff316753118ac1445858a111c8d76da1c7c3e40.tar.gz
cryptography-5ff316753118ac1445858a111c8d76da1c7c3e40.tar.bz2
cryptography-5ff316753118ac1445858a111c8d76da1c7c3e40.zip
Merge branch 'master' into urandom-engine
* master: (108 commits) PBKDF2HMAC requires a PBKDF2HMACBackend provider. one more replacement simplify hmac supported and hash supported calls for commoncrypto simplify check for algorithm a bit more language work + changelog changes for pbkdf2hmac one more style fix a few typo fixes, capitalization, etc switch to private attributes in pbkdf2hmac expand docs to talk more about the purposes of KDFs update docs re: PBKDF2HMAC iterations add test for null char replacement Added installation section to index.rst called -> used quotes inside, diff examples Expose this method because probably someone will need it eventually fix spacing, remove versionadded since HashAlgorithm was in 0.1 document HashAlgorithm Added canonical installation document with details about various platforms, fixes #519 update docs for pbkdf2 Add bindings for X509_REQ_get_extensions. ... Conflicts: cryptography/hazmat/bindings/openssl/binding.py docs/hazmat/backends/openssl.rst
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/tests/utils.py b/tests/utils.py
index a2432256..5c0e524f 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
@@ -82,6 +89,10 @@ def load_nist_vectors(vector_data):
# Build our data using a simple Key = Value format
name, value = [c.strip() for c in line.split("=")]
+ # Some tests (PBKDF2) contain \0, which should be interpreted as a
+ # null character rather than literal.
+ value = value.replace("\\0", "\0")
+
# COUNT is a special token that indicates a new block of data
if name.upper() == "COUNT":
test_data = {}
@@ -158,27 +169,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: