
commit a1149f5489065cf7445f83137f3747a4866351e1 Author: Damian Johnson <atagar@torproject.org> Date: Wed Apr 24 21:01:06 2013 -0700 Standardizing on digest() providing unicode Our digest() method provided bytes with python 2 and unicode with python 3. I'm trying to avoid these sort of version-dependent differences since they're a headache when we're support both serieses. The comparison for digest validation was also still failing in python 3 due to types. Caught thanks to aj00200. --- stem/descriptor/server_descriptor.py | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py index dc21813..d2efc0b 100644 --- a/stem/descriptor/server_descriptor.py +++ b/stem/descriptor/server_descriptor.py @@ -283,7 +283,7 @@ class ServerDescriptor(stem.descriptor.Descriptor): Provides the hex encoded sha1 of our content. This value is part of the network status entry for this relay. - :returns: **str** with the upper-case hex digest value for this server descriptor + :returns: **unicode** with the upper-case hex digest value for this server descriptor """ raise NotImplementedError("Unsupported Operation: this should be implemented by the ServerDescriptor subclass") @@ -668,7 +668,7 @@ class RelayDescriptor(ServerDescriptor): if start >= 0 and sig_start > 0 and end > start: for_digest = raw_descriptor[start:end] digest_hash = hashlib.sha1(stem.util.str_tools._to_bytes(for_digest)) - self._digest = digest_hash.hexdigest().upper() + self._digest = stem.util.str_tools._to_unicode(digest_hash.hexdigest().upper()) else: raise ValueError("unable to calculate digest for descriptor") @@ -756,7 +756,9 @@ class RelayDescriptor(ServerDescriptor): except ValueError: raise ValueError("Verification failed, seperator not found") - digest = codecs.encode(decrypted_bytes[seperator_index + 1:], 'hex_codec').upper() + digest_hex = codecs.encode(decrypted_bytes[seperator_index + 1:], 'hex_codec') + digest = stem.util.str_tools._to_unicode(digest_hex.upper()) + local_digest = self.digest() if digest != local_digest: @@ -852,7 +854,7 @@ class BridgeDescriptor(ServerDescriptor): if validate and not stem.util.tor_tools.is_hex_digits(value, 40): raise ValueError("Router digest line had an invalid sha1 digest: %s" % line) - self._digest = value + self._digest = stem.util.str_tools._to_unicode(value) del entries["router-digest"] ServerDescriptor._parse(self, entries, validate)