remove pycryptopp from tests

This commit is contained in:
heartsucker 2019-05-28 16:22:31 +02:00 committed by meejah
parent 67abb02a83
commit 772d4bad23

View File

@ -3,16 +3,18 @@ from __future__ import print_function
def foo(): pass # keep the line number constant def foo(): pass # keep the line number constant
import binascii
import six import six
import hashlib
import os, time, sys import os, time, sys
import yaml import yaml
from six.moves import StringIO from six.moves import StringIO
from datetime import timedelta from datetime import timedelta
from twisted.trial import unittest 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 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
@ -26,6 +28,10 @@ if six.PY3:
long = int long = int
def sha256(data):
return binascii.hexlify(hashlib.sha256(data).digest())
class Base32(unittest.TestCase): class Base32(unittest.TestCase):
def test_b2a_matches_Pythons(self): def test_b2a_matches_Pythons(self):
import base64 import base64
@ -1825,7 +1831,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 = _hash(subseed+str(i)).hexdigest() what = sha256(subseed+str(i))
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)
@ -1833,7 +1839,7 @@ class ByteSpans(unittest.TestCase):
#print #print
for i in range(1000): for i in range(1000):
what = _hash(seed+str(i)).hexdigest() what = sha256(seed+str(i))
op = what[0] op = what[0]
subop = what[1] subop = what[1]
start = int(what[2:4], 16) start = int(what[2:4], 16)
@ -1879,7 +1885,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 = _hash(what[12:14]+str(j)).hexdigest() what = sha256(what[12:14]+str(j))
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)
@ -2148,14 +2154,14 @@ class StringSpans(unittest.TestCase):
created = 0 created = 0
pieces = [] pieces = []
while created < length: while created < length:
piece = _hash(seed + str(created)).hexdigest() piece = sha256(seed + str(created))
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 = _hash(subseed+str(i)).hexdigest() what = sha256(subseed+str(i))
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]));
@ -2164,7 +2170,7 @@ class StringSpans(unittest.TestCase):
#print #print
for i in range(1000): for i in range(1000):
what = _hash(seed+str(i)).hexdigest() what = sha256(seed+str(i))
op = what[0] op = what[0]
subop = what[1] subop = what[1]
start = int(what[2:4], 16) start = int(what[2:4], 16)
@ -2192,7 +2198,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 = _hash(what[12:14]+str(j)).hexdigest() what = sha256(what[12:14]+str(j))
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)