summaryrefslogtreecommitdiff
path: root/dedup
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2016-04-16 11:22:18 +0200
committerHelmut Grohne <helmut@subdivi.de>2016-04-16 11:22:18 +0200
commit0715cc5f94438d58e2fc59c065a0afbd3dbb525a (patch)
tree46c396ec3c112f330dd9a41fdefd71dec4f378fa /dedup
parentf5684c218a7e7ed1166c0e60394daa05cda311fa (diff)
downloaddebian-dedup-0715cc5f94438d58e2fc59c065a0afbd3dbb525a.tar.gz
add a validate method to HashedStream
Diffstat (limited to 'dedup')
-rw-r--r--dedup/hashing.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/dedup/hashing.py b/dedup/hashing.py
index 1419811..2a83929 100644
--- a/dedup/hashing.py
+++ b/dedup/hashing.py
@@ -183,3 +183,13 @@ class HashedStream(object):
def hexdigest(self):
return self.hashobj.hexdigest()
+
+ def validate(self, hexdigest):
+ """Soak up any remaining input and validate the read data using the
+ given hexdigest.
+ @raises ValueError: when the hash does not match
+ """
+ while self.read(65536):
+ pass
+ if self.hexdigest() != hexdigest:
+ raise ValueError("hash sum mismatch")