From 0715cc5f94438d58e2fc59c065a0afbd3dbb525a Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 16 Apr 2016 11:22:18 +0200 Subject: add a validate method to HashedStream --- dedup/hashing.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'dedup') 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") -- cgit v1.2.3