[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Providing ASCII bytes to hashlib.sha1()
commit 6c855996c0daed3b6db222996dd651534c134c0d
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Jan 30 09:32:03 2013 -0800
Providing ASCII bytes to hashlib.sha1()
Another unicode/ASCII bytes conversion issue...
======================================================================
ERROR: test_metrics_descriptor
----------------------------------------------------------------------
Traceback:
File "/home/atagar/Desktop/stem/test/data/python3/test/integ/descriptor/server_descriptor.py", line 89, in test_metrics_descriptor
self.assertEquals("2C7B27BEAB04B4E2459D89CA6D5CD1CC5F95A689", desc.digest())
File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/server_descriptor.py", line 666, in digest
digest_hash = hashlib.sha1(for_digest)
TypeError: Unicode-objects must be encoded before hashing
---
stem/descriptor/extrainfo_descriptor.py | 3 ++-
stem/descriptor/server_descriptor.py | 4 ++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 2c5b6dc..c64550c 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -71,6 +71,7 @@ import re
import stem.descriptor
import stem.util.connection
import stem.util.enum
+import stem.util.str_tools
# known statuses for dirreq-v2-resp and dirreq-v3-resp...
DirResponse = stem.util.enum.Enum(
@@ -820,7 +821,7 @@ class RelayExtraInfoDescriptor(ExtraInfoDescriptor):
# our digest is calculated from everything except our signature
raw_content, ending = str(self), "\nrouter-signature\n"
raw_content = raw_content[:raw_content.find(ending) + len(ending)]
- self._digest = hashlib.sha1(raw_content).hexdigest().upper()
+ self._digest = hashlib.sha1(stem.util.str_tools.to_bytes(raw_content)).hexdigest().upper()
return self._digest
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 9e5004b..2376a56 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -663,7 +663,7 @@ class RelayDescriptor(ServerDescriptor):
if start >= 0 and sig_start > 0 and end > start:
for_digest = raw_descriptor[start:end]
- digest_hash = hashlib.sha1(for_digest)
+ digest_hash = hashlib.sha1(stem.util.str_tools.to_bytes(for_digest))
self._digest = digest_hash.hexdigest().upper()
else:
raise ValueError("unable to calculate digest for descriptor")
@@ -684,7 +684,7 @@ class RelayDescriptor(ServerDescriptor):
if self.fingerprint:
# calculate the signing key hash
- key_der_as_hash = hashlib.sha1(key_as_bytes).hexdigest()
+ key_der_as_hash = hashlib.sha1(stem.util.str_tools.to_bytes(key_as_bytes)).hexdigest()
if key_der_as_hash != self.fingerprint.lower():
log.warn("Signing key hash: %s != fingerprint: %s" % (key_der_as_hash, self.fingerprint.lower()))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits