comparison hgext/sqlitestore.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 adde839cc54f
children 77b8588dd84e
comparison
equal deleted inserted replaced
44061:cbc5755df6bf 44062:2d49482d0dd4
43 # --extra-config-opt extensions.sqlitestore= \ 43 # --extra-config-opt extensions.sqlitestore= \
44 # --extra-config-opt storage.new-repo-backend=sqlite 44 # --extra-config-opt storage.new-repo-backend=sqlite
45 45
46 from __future__ import absolute_import 46 from __future__ import absolute_import
47 47
48 import hashlib
49 import sqlite3 48 import sqlite3
50 import struct 49 import struct
51 import threading 50 import threading
52 import zlib 51 import zlib
53 52
73 ) 72 )
74 from mercurial.interfaces import ( 73 from mercurial.interfaces import (
75 repository, 74 repository,
76 util as interfaceutil, 75 util as interfaceutil,
77 ) 76 )
78 from mercurial.utils import storageutil 77 from mercurial.utils import (
78 hashutil,
79 storageutil,
80 )
79 81
80 try: 82 try:
81 from mercurial import zstd 83 from mercurial import zstd
82 84
83 zstd.__version__ 85 zstd.__version__
805 807
806 fulltext = resolvedeltachain( 808 fulltext = resolvedeltachain(
807 self._db, pathid, node, {}, {-1: None}, zstddctx=self._dctx 809 self._db, pathid, node, {}, {-1: None}, zstddctx=self._dctx
808 ) 810 )
809 811
810 deltahash = hashlib.sha1(fulltext).digest() 812 deltahash = hashutil.sha1(fulltext).digest()
811 813
812 if self._compengine == b'zstd': 814 if self._compengine == b'zstd':
813 deltablob = self._cctx.compress(fulltext) 815 deltablob = self._cctx.compress(fulltext)
814 compression = COMPRESSION_ZSTD 816 compression = COMPRESSION_ZSTD
815 elif self._compengine == b'zlib': 817 elif self._compengine == b'zlib':
835 (deltaid, rid), 837 (deltaid, rid),
836 ) 838 )
837 839
838 # Now create the tombstone delta and replace the delta on the censored 840 # Now create the tombstone delta and replace the delta on the censored
839 # node. 841 # node.
840 deltahash = hashlib.sha1(tombstone).digest() 842 deltahash = hashutil.sha1(tombstone).digest()
841 tombstonedeltaid = insertdelta( 843 tombstonedeltaid = insertdelta(
842 self._db, COMPRESSION_NONE, deltahash, tombstone 844 self._db, COMPRESSION_NONE, deltahash, tombstone
843 ) 845 )
844 846
845 flags = self._revisions[censornode].flags 847 flags = self._revisions[censornode].flags
1002 1004
1003 # Deltas are stored with a hash of their content. This allows 1005 # Deltas are stored with a hash of their content. This allows
1004 # us to de-duplicate. The table is configured to ignore conflicts 1006 # us to de-duplicate. The table is configured to ignore conflicts
1005 # and it is faster to just insert and silently noop than to look 1007 # and it is faster to just insert and silently noop than to look
1006 # first. 1008 # first.
1007 deltahash = hashlib.sha1(delta).digest() 1009 deltahash = hashutil.sha1(delta).digest()
1008 1010
1009 if self._compengine == b'zstd': 1011 if self._compengine == b'zstd':
1010 deltablob = self._cctx.compress(delta) 1012 deltablob = self._cctx.compress(delta)
1011 compression = COMPRESSION_ZSTD 1013 compression = COMPRESSION_ZSTD
1012 elif self._compengine == b'zlib': 1014 elif self._compengine == b'zlib':