[tor-commits] [bridgedb/master] Get unicode rather than byte descriptors

phw at torproject.org phw at torproject.org
Wed Feb 19 18:26:38 UTC 2020


commit 14678b00f0d90fada7e7d4616370673156e278a0
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jan 18 18:23:42 2020 -0800

    Get unicode rather than byte descriptors
    
    Test results changed as follows...
    
      before: FAILED (skips=115, failures=29, errors=34, successes=806)
      after:  FAILED (skips=115, failures=29, errors=3, successes=837)
---
 bridgedb/Bridges.py           |  2 +-
 bridgedb/bridges.py           | 11 ++++++-----
 bridgedb/test/test_Bridges.py |  2 +-
 bridgedb/test/test_bridges.py |  2 +-
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/bridgedb/Bridges.py b/bridgedb/Bridges.py
index 93d0190..c29a2bf 100644
--- a/bridgedb/Bridges.py
+++ b/bridgedb/Bridges.py
@@ -356,7 +356,7 @@ class BridgeRing(object):
 
     def dumpAssignments(self, f, description=""):
         logging.info("Dumping bridge assignments for %s..." % self.name)
-        for b in self.bridges.itervalues():
+        for b in self.bridges.values():
             desc = [ description ]
             for tp,val,_,subring in self.subrings:
                 if subring.getBridgeByID(b.identity):
diff --git a/bridgedb/bridges.py b/bridgedb/bridges.py
index cdd1ae8..049dbf1 100644
--- a/bridgedb/bridges.py
+++ b/bridgedb/bridges.py
@@ -240,7 +240,7 @@ class BridgeAddressBase(object):
         :param str value: The binary-encoded SHA-1 hash digest of the public
             half of this Bridge's identity key.
         """
-        self.fingerprint = toHex(value)
+        self.fingerprint = toHex(value).decode('utf-8')
 
     @identity.deleter
     def identity(self):
@@ -743,7 +743,7 @@ class BridgeBackwardsCompatibility(BridgeBase):
             if not fingerprint:
                 if not len(idDigest) == 20:
                     raise TypeError("Bridge with invalid ID")
-                self.fingerprint = toHex(idDigest)
+                self.fingerprint = toHex(idDigest).decode('utf-8')
         elif fingerprint:
             if not isValidFingerprint(fingerprint):
                 raise TypeError("Bridge with invalid fingerprint (%r)"
@@ -1665,7 +1665,7 @@ class Bridge(BridgeBackwardsCompatibility):
         logging.info("Verifying extrainfo signature for %s..." % self)
 
         # Get the bytes of the descriptor signature without the headers:
-        document, signature = descriptor.get_bytes().split(TOR_BEGIN_SIGNATURE)
+        document, signature = str(descriptor).split(TOR_BEGIN_SIGNATURE)
         signature = signature.replace(TOR_END_SIGNATURE, '')
         signature = signature.replace('\n', '')
         signature = signature.strip()
@@ -1709,10 +1709,11 @@ class Bridge(BridgeBackwardsCompatibility):
 
             # This is the hexadecimal SHA-1 hash digest of the descriptor document
             # as it was signed:
-            signedDigest = codecs.encode(unpadded, 'hex_codec')
-            actualDigest = hashlib.sha1(document).hexdigest()
+            signedDigest = codecs.encode(unpadded, 'hex_codec').decode('utf-8')
+            actualDigest = hashlib.sha1(document.encode('utf-8')).hexdigest()
 
         except Exception as error:
+            raise
             logging.debug("Error verifying extrainfo signature: %s" % error)
             raise InvalidExtraInfoSignature(
                 "Extrainfo signature for %s couldn't be decoded: %s" %
diff --git a/bridgedb/test/test_Bridges.py b/bridgedb/test/test_Bridges.py
index 19ab09c..1f4720f 100644
--- a/bridgedb/test/test_Bridges.py
+++ b/bridgedb/test/test_Bridges.py
@@ -149,7 +149,7 @@ class FixedBridgeSplitterTests(unittest.TestCase):
         f.seek(0)
 
         data = f.read()
-        first = self.splitter.rings[0].bridges.values()[0].fingerprint
+        first = list(self.splitter.rings[0].bridges.values())[0].fingerprint
 
         # The first bridge's fingerprint should be within the data somewhere
         self.assertIn(first, data)
diff --git a/bridgedb/test/test_bridges.py b/bridgedb/test/test_bridges.py
index cf0ee23..fea2d33 100644
--- a/bridgedb/test/test_bridges.py
+++ b/bridgedb/test/test_bridges.py
@@ -970,7 +970,7 @@ class BridgeTests(unittest.TestCase):
         self.assertEqual(
             identifier,
             ''.join(['$$',
-                     hashlib.sha1(bridge.fingerprint).hexdigest().upper(),
+                     hashlib.sha1(bridge.fingerprint.encode('utf-8')).hexdigest().upper(),
                      '~', bridge.nickname]))
 
     def test_Bridge_str_without_fingerprint(self):





More information about the tor-commits mailing list