diff options
-rw-r--r-- | include/HashFunction.h | 4 | ||||
-rw-r--r-- | lib/HashFunction.cc | 31 |
2 files changed, 33 insertions, 2 deletions
diff --git a/include/HashFunction.h b/include/HashFunction.h index 66c185b..e109778 100644 --- a/include/HashFunction.h +++ b/include/HashFunction.h @@ -17,18 +17,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: HashFunction.h,v 1.1 2007-09-05 14:11:54 pixel Exp $ */ +/* $Id: HashFunction.h,v 1.2 2007-09-17 16:04:40 pixel Exp $ */ #ifndef __HASHFUNCTION_H__ #define __HASHFUNCTION_H__ #include <Exceptions.h> +#include <Handle.h> class HashFunction : public Base { public: HashFunction(); void Update(const String &); void Update(const unsigned char * data, size_t len); + void Update(Handle *, ssize_t = -1); String Finish(); size_t RFinish(Uint8 * digest); protected: diff --git a/lib/HashFunction.cc b/lib/HashFunction.cc index 1904f49..9f165e4 100644 --- a/lib/HashFunction.cc +++ b/lib/HashFunction.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: HashFunction.cc,v 1.1 2007-09-05 14:11:54 pixel Exp $ */ +/* $Id: HashFunction.cc,v 1.2 2007-09-17 16:04:40 pixel Exp $ */ #include <sha1.h> #include <sha256.h> @@ -40,6 +40,35 @@ void HashFunction::Update(const unsigned char * data, size_t len) { update(data, len); } +#define BLKSIZE 1024 +void HashFunction::Update(Handle * h, ssize_t size) { + static Uint8 blk[BLKSIZE]; + long r; + + if (size < 0) + size = h->GetSize(); + + LOCK; + + while (size) { + if ((size > BLKSIZE) || (size < 0)) { + r = h->read(blk, BLKSIZE); + if (r) + Update(blk, r); + } else { + r = h->read(blk, size); + if (r) + Update(blk, r); + } + if (!r) + break; + if (size > 0) + size -= r; + } + + UNLOCK; +} + String HashFunction::Finish() { char digest_r[513]; int i; |