test_util.py: use SHA-256 from pycryptopp instead of MD5 from hashlib (for uses in which any hash will do), since hashlib was only added to the stdlib in Python 2.5.

This commit is contained in:
david-sarah 2010-08-05 22:00:51 -07:00
parent 600cb95fe2
commit a79ec1c6cd
2 changed files with 9 additions and 8 deletions

1
NEWS
View File

@ -8,6 +8,7 @@
created by other Tahoe-LAFS versions. (#1159) created by other Tahoe-LAFS versions. (#1159)
- Partial GET requests using the Range header were not handled - Partial GET requests using the Range header were not handled
correctly by the new downloader. (#1154) correctly by the new downloader. (#1154)
- Restore compatibility of test suite with Python 2.4.x.
* Release 1.8.0β (2010-08-02) * Release 1.8.0β (2010-08-02)

View File

@ -7,7 +7,7 @@ from twisted.trial import unittest
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
from twisted.python.failure import Failure from twisted.python.failure import Failure
from twisted.python import log from twisted.python import log
from hashlib import md5 from pycryptopp.hash.sha256 import SHA256 as _hash
from allmydata.util import base32, idlib, humanreadable, mathutil, hashutil from allmydata.util import base32, idlib, humanreadable, mathutil, hashutil
from allmydata.util import assertutil, fileutil, deferredutil, abbreviate from allmydata.util import assertutil, fileutil, deferredutil, abbreviate
@ -1781,7 +1781,7 @@ class ByteSpans(unittest.TestCase):
def _create(subseed): def _create(subseed):
ns1 = S1(); ns2 = S2() ns1 = S1(); ns2 = S2()
for i in range(10): for i in range(10):
what = md5(subseed+str(i)).hexdigest() what = _hash(subseed+str(i)).hexdigest()
start = int(what[2:4], 16) start = int(what[2:4], 16)
length = max(1,int(what[5:6], 16)) length = max(1,int(what[5:6], 16))
ns1.add(start, length); ns2.add(start, length) ns1.add(start, length); ns2.add(start, length)
@ -1789,7 +1789,7 @@ class ByteSpans(unittest.TestCase):
#print #print
for i in range(1000): for i in range(1000):
what = md5(seed+str(i)).hexdigest() what = _hash(seed+str(i)).hexdigest()
op = what[0] op = what[0]
subop = what[1] subop = what[1]
start = int(what[2:4], 16) start = int(what[2:4], 16)
@ -1835,7 +1835,7 @@ class ByteSpans(unittest.TestCase):
self.failUnlessEqual(bool(s1), bool(s2)) self.failUnlessEqual(bool(s1), bool(s2))
self.failUnlessEqual(list(s1), list(s2)) self.failUnlessEqual(list(s1), list(s2))
for j in range(10): for j in range(10):
what = md5(what[12:14]+str(j)).hexdigest() what = _hash(what[12:14]+str(j)).hexdigest()
start = int(what[2:4], 16) start = int(what[2:4], 16)
length = max(1, int(what[5:6], 16)) length = max(1, int(what[5:6], 16))
span = (start, length) span = (start, length)
@ -2104,14 +2104,14 @@ class StringSpans(unittest.TestCase):
created = 0 created = 0
pieces = [] pieces = []
while created < length: while created < length:
piece = md5(seed + str(created)).hexdigest() piece = _hash(seed + str(created)).hexdigest()
pieces.append(piece) pieces.append(piece)
created += len(piece) created += len(piece)
return "".join(pieces)[:length] return "".join(pieces)[:length]
def _create(subseed): def _create(subseed):
ns1 = S1(); ns2 = S2() ns1 = S1(); ns2 = S2()
for i in range(10): for i in range(10):
what = md5(subseed+str(i)).hexdigest() what = _hash(subseed+str(i)).hexdigest()
start = int(what[2:4], 16) start = int(what[2:4], 16)
length = max(1,int(what[5:6], 16)) length = max(1,int(what[5:6], 16))
ns1.add(start, _randstr(length, what[7:9])); ns1.add(start, _randstr(length, what[7:9]));
@ -2120,7 +2120,7 @@ class StringSpans(unittest.TestCase):
#print #print
for i in range(1000): for i in range(1000):
what = md5(seed+str(i)).hexdigest() what = _hash(seed+str(i)).hexdigest()
op = what[0] op = what[0]
subop = what[1] subop = what[1]
start = int(what[2:4], 16) start = int(what[2:4], 16)
@ -2148,7 +2148,7 @@ class StringSpans(unittest.TestCase):
self.failUnlessEqual(s1.len(), s2.len()) self.failUnlessEqual(s1.len(), s2.len())
self.failUnlessEqual(list(s1._dump()), list(s2._dump())) self.failUnlessEqual(list(s1._dump()), list(s2._dump()))
for j in range(100): for j in range(100):
what = md5(what[12:14]+str(j)).hexdigest() what = _hash(what[12:14]+str(j)).hexdigest()
start = int(what[2:4], 16) start = int(what[2:4], 16)
length = max(1, int(what[5:6], 16)) length = max(1, int(what[5:6], 16))
d1 = s1.get(start, length); d2 = s2.get(start, length) d1 = s1.get(start, length); d2 = s2.get(start, length)