From e7ec4ff4e5599592ad24afd2fca0a3a5294b4cc2 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 17 Apr 2007 20:27:56 -0700 Subject: [PATCH] factor out the tagged hash function used for subshares/blocks --- src/allmydata/download.py | 4 +++- src/allmydata/encode.py | 6 +++--- src/allmydata/hashtree.py | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/allmydata/download.py b/src/allmydata/download.py index 44076caf..ddc3678b 100644 --- a/src/allmydata/download.py +++ b/src/allmydata/download.py @@ -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 diff --git a/src/allmydata/encode.py b/src/allmydata/encode.py index cc3c4f39..5b74f107 100644 --- a/src/allmydata/encode.py +++ b/src/allmydata/encode.py @@ -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): diff --git a/src/allmydata/hashtree.py b/src/allmydata/hashtree.py index 63816f5e..c03c90d0 100644 --- a/src/allmydata/hashtree.py +++ b/src/allmydata/hashtree.py @@ -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) -- 2.45.2