diff options
author | pixel <pixel> | 2007-09-17 16:04:40 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-09-17 16:04:40 +0000 |
commit | 36350232b4f4c7ddc7f3b9f65da81692e9f02183 (patch) | |
tree | 5617d8eed6aa9262840dc2915b70546bae3253e1 | |
parent | 3fedf9f3fff7c8ceadd077fc7ed4eff4c4108026 (diff) |
Adding hashing from Handles.
-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; |