@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -20,10 +20,11 @@ #import "OFSHA224Or256Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" +#import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 64; @interface OFSHA224Or256Hash () @@ -232,12 +233,21 @@ } } - (const unsigned char *)digest { + if (!_calculated) + @throw [OFHashNotCalculatedException exceptionWithObject: self]; + + return (const unsigned char *)_iVars->state; +} + +- (void)calculate +{ if (_calculated) - return (const unsigned char *)_iVars->state; + @throw [OFHashAlreadyCalculatedException + exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); @@ -253,12 +263,10 @@ processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 8); _calculated = true; - - return (const unsigned char *)_iVars->state; } - (void)reset { [self of_resetState];