Index: src/OFMD5Hash.m ================================================================== --- src/OFMD5Hash.m +++ src/OFMD5Hash.m @@ -153,11 +153,12 @@ if (size == 0) return; if (isCalculated) - @throw [OFHashAlreadyCalculatedException newWithClass: isa]; + @throw [OFHashAlreadyCalculatedException newWithClass: isa + hash: self]; /* Update bitcount */ t = bits[0]; if ((bits[0] = t + ((uint32_t)size << 3)) < t) /* Carry from low to high */ Index: src/OFSHA1Hash.m ================================================================== --- src/OFSHA1Hash.m +++ src/OFSHA1Hash.m @@ -162,11 +162,12 @@ { if (size == 0) return; if (isCalculated) - @throw [OFHashAlreadyCalculatedException newWithClass: isa]; + @throw [OFHashAlreadyCalculatedException newWithClass: isa + hash: self]; sha1_update(state, &count, buffer, buf, size); } - (uint8_t*)digest Index: src/exceptions/OFHashAlreadyCalculatedException.h ================================================================== --- src/exceptions/OFHashAlreadyCalculatedException.h +++ src/exceptions/OFHashAlreadyCalculatedException.h @@ -14,10 +14,40 @@ * file. */ #import "OFException.h" +@class OFHash; + /** * \brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException +{ + OFHash *hash; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFHash *hash; +#endif + +/** + * \param hash The hash which has already been calculated + * \return A new hash already calculated exception + */ ++ newWithClass: (Class)class_ + hash: (OFHash*)hash; + +/** + * Initializes an already allocated hash already calculated exception. + * + * \param hash The hash which has already been calculated + * \return An initialized hash already calculated exception + */ +- initWithClass: (Class)class_ + hash: (OFHash*)hash; + +/** + * \return The hash which has already been calculated + */ +- (OFHash*)hash; @end Index: src/exceptions/OFHashAlreadyCalculatedException.m ================================================================== --- src/exceptions/OFHashAlreadyCalculatedException.m +++ src/exceptions/OFHashAlreadyCalculatedException.m @@ -16,12 +16,51 @@ #include "config.h" #import "OFHashAlreadyCalculatedException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFHashAlreadyCalculatedException ++ newWithClass: (Class)class_ + hash: (OFHash*)hash +{ + return [[self alloc] initWithClass: class_ + hash: hash]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + hash: (OFHash*)hash_ +{ + self = [super initWithClass: class_]; + + @try { + hash = [hash_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [hash release]; + + [super dealloc]; +} + - (OFString*)description { if (description != nil) return description; @@ -29,6 +68,11 @@ @"The hash has already been calculated in class %@ and thus no new " @"data can be added", inClass]; return description; } + +- (OFHash*)hash +{ + return hash; +} @end