[tor-commits] [stem/master] Hash detection in stem.client failed for pypy 3.5

atagar at torproject.org atagar at torproject.org
Fri May 24 18:47:24 UTC 2019


commit eabc0811b021f62170ceed6853ef2c602343c84b
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri May 24 11:09:26 2019 -0700

    Hash detection in stem.client failed for pypy 3.5
    
    Python's hashlib.HASH class is dynamically generated with different names under
    different python versions, making 'is this object an instance of it' uncommonly
    thorny. We already adjusted this once for pypy but turns out pypy 3.5 uses
    different case...
    
      https://trac.torproject.org/projects/tor/ticket/30598
---
 stem/client/cell.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/stem/client/cell.py b/stem/client/cell.py
index b74094c8..4b0f9fa1 100644
--- a/stem/client/cell.py
+++ b/stem/client/cell.py
@@ -347,10 +347,10 @@ class RelayCell(CircuitCell):
   IS_FIXED_SIZE = True
 
   def __init__(self, circ_id, command, data, digest = 0, stream_id = 0, recognized = 0, unused = b''):
-    if 'HASH' in str(type(digest)):
+    if 'hash' in str(type(digest)).lower():
       # Unfortunately hashlib generates from a dynamic private class so
       # isinstance() isn't such a great option. With python2/python3 the
-      # name is 'hashlib.HASH' whereas PyPy calls it just 'HASH'.
+      # name is 'hashlib.HASH' whereas PyPy calls it just 'HASH' or 'Hash'.
 
       digest_packed = digest.digest()[:RELAY_DIGEST_SIZE.size]
       digest = RELAY_DIGEST_SIZE.unpack(digest_packed)
@@ -400,7 +400,7 @@ class RelayCell(CircuitCell):
     :param bytes content: cell content to be decrypted
     :param cryptography.hazmat.primitives.ciphers.CipherContext key:
       key established with the relay we received this cell from
-    :param HASH digest: running digest held with the relay
+    :param hashlib.HASH digest: running digest held with the relay
 
     :returns: **tuple** with our decrypted cell and updated key/digest
 
@@ -453,7 +453,7 @@ class RelayCell(CircuitCell):
     :param int link_protocol: link protocol version
     :param cryptography.hazmat.primitives.ciphers.CipherContext key:
       key established with the relay we're sending this cell to
-    :param HASH digest: running digest held with the relay
+    :param hashlib.HASH digest: running digest held with the relay
 
     :returns: **tuple** with our encrypted payload and updated key/digest
     """





More information about the tor-commits mailing list