[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/develop] Hash bytes within Storage.py
commit f76eb054d4dcad4a8677ea163054b99161cceb1c
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Jan 17 13:32:51 2020 -0800
Hash bytes within Storage.py
Another hashing byte/unicode fix...
Traceback (most recent call last):
File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_email_distributor.py", line 192, in test_EmailDistributor_cleanDatabase
self.assertEqual(len(dist.getBridges(bridgeRequest, 1)), 3)
File "/home/atagar/Desktop/tor/bridgedb/bridgedb/distributors/email/distributor.py", line 154, in getBridges
wasWarned = db.getWarnedEmail(bridgeRequest.client)
File "/home/atagar/Desktop/tor/bridgedb/bridgedb/Storage.py", line 264, in getWarnedEmail
addr = hashlib.sha1(addr).hexdigest()
builtins.TypeError: Unicode-objects must be encoded before hashing
Test results changed as follows...
before: FAILED (skips=114, failures=15, errors=122, successes=734)
after: FAILED (skips=114, failures=15, errors=117, successes=739)
---
bridgedb/Storage.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/bridgedb/Storage.py b/bridgedb/Storage.py
index 1f81052..cfd60bb 100644
--- a/bridgedb/Storage.py
+++ b/bridgedb/Storage.py
@@ -211,7 +211,7 @@ class Database(object):
cur.execute("DELETE FROM EmailedBridges WHERE when_mailed < ?", (t,))
def getEmailTime(self, addr):
- addr = hashlib.sha1(addr).hexdigest()
+ addr = hashlib.sha1(addr.encode('utf-8')).hexdigest()
cur = self._cur
cur.execute("SELECT when_mailed FROM EmailedBridges WHERE email = ?", (addr,))
v = cur.fetchone()
@@ -220,7 +220,7 @@ class Database(object):
return strToTime(v[0])
def setEmailTime(self, addr, whenMailed):
- addr = hashlib.sha1(addr).hexdigest()
+ addr = hashlib.sha1(addr.encode('utf-8')).hexdigest()
cur = self._cur
t = timeToStr(whenMailed)
cur.execute("INSERT OR REPLACE INTO EmailedBridges "
@@ -261,7 +261,7 @@ class Database(object):
(distributor, hex_key))
def getWarnedEmail(self, addr):
- addr = hashlib.sha1(addr).hexdigest()
+ addr = hashlib.sha1(addr.encode('utf-8')).hexdigest()
cur = self._cur
cur.execute("SELECT * FROM WarnedEmails WHERE email = ?", (addr,))
v = cur.fetchone()
@@ -270,7 +270,7 @@ class Database(object):
return True
def setWarnedEmail(self, addr, warned=True, whenWarned=time.time()):
- addr = hashlib.sha1(addr).hexdigest()
+ addr = hashlib.sha1(addr.encode('utf-8')).hexdigest()
t = timeToStr(whenWarned)
cur = self._cur
if warned == True:
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits