summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-08-05 16:12:10 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-08-07 12:00:23 +0200
commit127b461b11af985a52fb482f09c7cd7a08832f9d (patch)
treef5a4ea6376f8d7bf9a0c30d2f5198d82511d628e /tests
parentb55e07771fdc9f9cc80fb099429774672aaf9be9 (diff)
[py3] Ported django.utils.crypto.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/utils/crypto.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/tests/regressiontests/utils/crypto.py b/tests/regressiontests/utils/crypto.py
index 2bdc5ba530..52a286cb27 100644
--- a/tests/regressiontests/utils/crypto.py
+++ b/tests/regressiontests/utils/crypto.py
@@ -1,4 +1,6 @@
+from __future__ import unicode_literals
+import binascii
import math
import timeit
import hashlib
@@ -108,15 +110,15 @@ class TestUtilsCryptoPBKDF2(unittest.TestCase):
"c4007d5298f9033c0241d5ab69305e7b64eceeb8d"
"834cfec"),
},
- # Check leading zeros are not stripped (#17481)
+ # Check leading zeros are not stripped (#17481)
{
- "args": {
- "password": chr(186),
- "salt": "salt",
- "iterations": 1,
- "dklen": 20,
- "digest": hashlib.sha1,
- },
+ "args": {
+ "password": b'\xba',
+ "salt": "salt",
+ "iterations": 1,
+ "dklen": 20,
+ "digest": hashlib.sha1,
+ },
"result": '0053d3b91a7f1e54effebd6d68771e8a6e0b2c5b',
},
]
@@ -124,12 +126,14 @@ class TestUtilsCryptoPBKDF2(unittest.TestCase):
def test_public_vectors(self):
for vector in self.rfc_vectors:
result = pbkdf2(**vector['args'])
- self.assertEqual(result.encode('hex'), vector['result'])
+ self.assertEqual(binascii.hexlify(result).decode('ascii'),
+ vector['result'])
def test_regression_vectors(self):
for vector in self.regression_vectors:
result = pbkdf2(**vector['args'])
- self.assertEqual(result.encode('hex'), vector['result'])
+ self.assertEqual(binascii.hexlify(result).decode('ascii'),
+ vector['result'])
def test_performance_scalability(self):
"""
@@ -140,11 +144,11 @@ class TestUtilsCryptoPBKDF2(unittest.TestCase):
# to run the test suite and false positives caused by imprecise
# measurement.
n1, n2 = 200000, 800000
- elapsed = lambda f: timeit.Timer(f,
+ elapsed = lambda f: timeit.Timer(f,
'from django.utils.crypto import pbkdf2').timeit(number=1)
t1 = elapsed('pbkdf2("password", "salt", iterations=%d)' % n1)
t2 = elapsed('pbkdf2("password", "salt", iterations=%d)' % n2)
measured_scale_exponent = math.log(t2 / t1, n2 / n1)
- # This should be less than 1. We allow up to 1.2 so that tests don't
+ # This should be less than 1. We allow up to 1.2 so that tests don't
# fail nondeterministically too often.
self.assertLess(measured_scale_exponent, 1.2)