Mercurial > public > mercurial-scm > hg-stable
diff hgext/largefiles/lfutil.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 | a02e4c12ae60 |
children | ca82929e433d |
line wrap: on
line diff
--- a/hgext/largefiles/lfutil.py Mon Jan 13 17:16:54 2020 -0500 +++ b/hgext/largefiles/lfutil.py Mon Jan 13 14:12:31 2020 -0500 @@ -11,7 +11,6 @@ import contextlib import copy -import hashlib import os import stat @@ -32,6 +31,7 @@ util, vfs as vfsmod, ) +from mercurial.utils import hashutil shortname = b'.hglf' shortnameslash = shortname + b'/' @@ -432,7 +432,7 @@ def copyandhash(instream, outfile): '''Read bytes from instream (iterable) and write them to outfile, computing the SHA-1 hash of the data along the way. Return the hash.''' - hasher = hashlib.sha1(b'') + hasher = hashutil.sha1(b'') for data in instream: hasher.update(data) outfile.write(data) @@ -472,7 +472,7 @@ def hexsha1(fileobj): """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like object data""" - h = hashlib.sha1() + h = hashutil.sha1() for chunk in util.filechunkiter(fileobj): h.update(chunk) return hex(h.digest())