Index: src/OFHashes.h ================================================================== --- src/OFHashes.h +++ src/OFHashes.h @@ -16,74 +16,64 @@ #define OF_SHA1_DIGEST_SIZE 20 extern int _OFHashing_reference; /** - * \brief A class which provides functions to create an MD5 hash. + * \brief A base class for classes providing hash functions. */ -@interface OFMD5Hash: OFObject +@interface OFHash: OFObject { - uint32_t buf[4]; - uint32_t bits[2]; - uint8_t in[64]; - BOOL calculated; } -/** - * \return A new autoreleased MD5 Hash - */ -+ md5Hash; - /** * Adds a buffer to the hash to be calculated. * - * \param buf The buffer which should be included into calculation. + * \param buf The buffer which should be included into the calculation. * \param size The size of the buffer */ - (void)updateWithBuffer: (const char*)buf ofSize: (size_t)size; /** - * \return A buffer containing the hash (OF_MD5_DIGEST_SIZE = 16 bytes). - * The buffer is part of object's memory pool. + * \return A buffer containing the hash. The size of the buffer is depending + * on the hash used. The buffer is part of object's memory pool. */ - (uint8_t*)digest; @end +/** + * \brief A class which provides functions to create an MD5 hash. + */ +@interface OFMD5Hash: OFHash +{ + uint32_t buf[4]; + uint32_t bits[2]; + uint8_t in[64]; +} + +/** + * \return A new autoreleased MD5 Hash + */ ++ md5Hash; +@end + /** * \brief A class which provides functions to create an SHA1 hash. */ -@interface OFSHA1Hash: OFObject +@interface OFSHA1Hash: OFHash { uint32_t state[5]; uint64_t count; char buffer[64]; uint8_t digest[OF_SHA1_DIGEST_SIZE]; - - BOOL calculated; } /** * \return A new autoreleased SHA1 Hash */ + sha1Hash; - -/** - * Adds a buffer to the hash to be calculated. - * - * \param buf The buffer which should be included into calculation. - * \param size The size of the buffer - */ -- (void)updateWithBuffer: (const char*)buf - ofSize: (size_t)size; - -/** - * \return A buffer containing the hash (OF_SHA1_DIGEST_SIZE = 20 bytes). - * The buffer is part of object's memory pool. - */ -- (uint8_t*)digest; @end /** * The OFString (OFHashing) category provides methods to calculate hashes for * strings. Index: src/OFHashes.m ================================================================== --- src/OFHashes.m +++ src/OFHashes.m @@ -17,10 +17,25 @@ #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "macros.h" int _OFHashing_reference; + +@implementation OFHash +- (void)updateWithBuffer: (const char*)buffer + ofSize: (size_t)size +{ + @throw [OFNotImplementedException newWithClass: isa + selector: _cmd]; +} + +- (uint8_t*)digest +{ + @throw [OFNotImplementedException newWithClass: isa + selector: _cmd]; +} +@end /* * MD5 */