]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Handle a change in the implementation of hashlib in Python 3.9
authorNick Mathewson <nickm@torproject.org>
Thu, 5 Nov 2020 14:34:36 +0000 (09:34 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 5 Nov 2020 14:34:36 +0000 (09:34 -0500)
Previously, hashlib.shake_256 was a class (if present); now it can
also be a function.  This change invalidated our old
compatibility/workaround code, and made one of our tests fail.

Fixes bug 40179; bugfix on 0.3.1.6-rc when the workaround code was
added.

changes/bug40179_part1 [new file with mode: 0644]
src/test/hs_ntor_ref.py

diff --git a/changes/bug40179_part1 b/changes/bug40179_part1
new file mode 100644 (file)
index 0000000..c302373
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes (testing, portability):
+    - Fix our Python reference-implementation for the v3 onion service
+      handshake so that it works correctly with the version of hashlib provided
+      by Python 3.9. Fixes part of bug 40179; bugfix on 0.3.1.6-rc.
index 1b9772a5d6755f7ac4f643b796fd72312bc4b656..d58ac3ca23fa24b6d4efc5a97e0b56315436a861 100644 (file)
@@ -65,14 +65,16 @@ except ImportError:
 try:
     # Pull the sha3 functions in.
     from hashlib import sha3_256, shake_256
-    shake_squeeze = shake_256.digest
+    def shake_squeeze(obj, n):
+        return obj.digest(n)
 except ImportError:
     if hasattr(sha3, "SHA3256"):
         # If this happens, then we have the old "sha3" module which
         # hashlib and pysha3 superseded.
         sha3_256 = sha3.SHA3256
         shake_256 = sha3.SHAKE256
-        shake_squeeze = shake_256.squeeze
+        def shake_squeeze(obj, n):
+            return obj.squeeze(n)
     else:
         # error code 77 tells automake to skip this test
         sys.exit(77)