factor out the tagged hash function used for subshares/blocks

This commit is contained in:
Brian Warner 2007-04-17 20:27:56 -07:00
parent 76e28b3484
commit e7ec4ff4e5
3 changed files with 9 additions and 4 deletions

View File

@ -95,7 +95,9 @@ class ValidatedBucket:
sht.set_hashes(sh)
self._share_hash = sht.get_leaf(self.sharenum)
blockhash = hashutil.tagged_hash("encoded subshare", blockdata)
#log.msg("checking block_hash(shareid=%d, blocknum=%d) len=%d" %
# (self.sharenum, blocknum, len(blockdata)))
blockhash = hashtree.block_hash(blockdata)
# we always validate the blockhash
bh = dict(enumerate(blockhashes))
# replace blockhash root with validated value

View File

@ -3,9 +3,9 @@
from zope.interface import implements
from twisted.internet import defer
from twisted.python import log
from allmydata.hashtree import HashTree
from allmydata.hashtree import HashTree, block_hash
from allmydata.Crypto.Cipher import AES
from allmydata.util import mathutil, hashutil
from allmydata.util import mathutil
from allmydata.util.assertutil import _assert
from allmydata.codec import CRSEncoder
from allmydata.interfaces import IEncoder
@ -225,7 +225,7 @@ class Encoder(object):
shareid = shareids[i]
d = self.send_subshare(shareid, segnum, subshare)
dl.append(d)
subshare_hash = hashutil.tagged_hash("encoded subshare", subshare)
subshare_hash = block_hash(subshare)
self.subshare_hashes[shareid].append(subshare_hash)
dl = defer.DeferredList(dl)
def _logit(res):

View File

@ -436,3 +436,6 @@ class IncompleteHashTree(CompleteBinaryTreeMixin, list):
for i in added:
self[i] = None
raise
def block_hash(data):
return tagged_hash("encoded subshare", data)