diff hgext/remotefilelog/historypack.py @ 44062:2d49482d0dd4

hgext: replace references to hashlib.sha1 with hashutil.sha1 When in a non-pure build of Mercurial, this will provide protections against SHA1 collision attacks. Differential Revision: https://phab.mercurial-scm.org/D7851
author Augie Fackler <augie@google.com>
date Mon, 13 Jan 2020 14:12:31 -0500
parents 649d3ac37a12
children 9d2b2df2c2ba
line wrap: on
line diff
--- a/hgext/remotefilelog/historypack.py	Mon Jan 13 17:16:54 2020 -0500
+++ b/hgext/remotefilelog/historypack.py	Mon Jan 13 14:12:31 2020 -0500
@@ -1,6 +1,5 @@
 from __future__ import absolute_import
 
-import hashlib
 import struct
 
 from mercurial.node import hex, nullid
@@ -8,6 +7,7 @@
     pycompat,
     util,
 )
+from mercurial.utils import hashutil
 from . import (
     basepack,
     constants,
@@ -197,7 +197,7 @@
 
     def _findsection(self, name):
         params = self.params
-        namehash = hashlib.sha1(name).digest()
+        namehash = hashutil.sha1(name).digest()
         fanoutkey = struct.unpack(
             params.fanoutstruct, namehash[: params.fanoutprefix]
         )[0]
@@ -499,7 +499,7 @@
 
             # Record metadata for the index
             self.files[filename] = (sectionstart, sectionlen)
-            node = hashlib.sha1(filename).digest()
+            node = hashutil.sha1(filename).digest()
             self.entries[node] = node
 
     def close(self, ledger=None):
@@ -517,7 +517,7 @@
         nodeindexlength = self.NODEINDEXENTRYLENGTH
 
         files = (
-            (hashlib.sha1(filename).digest(), filename, offset, size)
+            (hashutil.sha1(filename).digest(), filename, offset, size)
             for filename, (offset, size) in pycompat.iteritems(self.files)
         )
         files = sorted(files)