Comment: | OFCryptographicHash: Add -[calculate]
Before, -[digest] would do the final calculation, however, this would |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
82801897d338b7f5da61f6e0a9e7dbf6 |
User & Date: | js on 2022-03-25 10:22:55 |
Other Links: | manifest | tags |
2022-03-25
| ||
10:59 | Use nameSpace instead of namespace_ for C++ check-in: fb151035d0 user: js tags: trunk | |
10:22 | OFCryptographicHash: Add -[calculate] check-in: 82801897d3 user: js tags: trunk | |
2022-03-24
| ||
21:12 | README.md: Move "Donating" to the Wiki check-in: cb75aa16d9 user: js tags: trunk | |
Modified src/OFCryptographicHash.h from [68944dcb5c] to [21f208b184].
︙ | ︙ | |||
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | * @brief Adds a buffer to the cryptographic hash to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Resets all state so that a new hash can be calculated. * * @warning This invalidates any pointer previously returned by @ref digest. If * you are still interested in the previous digest, you need to memcpy * it yourself before calling @ref reset! */ - (void)reset; @end OF_ASSUME_NONNULL_END | > > > > > | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | * @brief Adds a buffer to the cryptographic hash to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Performs the final calculation of the cryptographic hash. */ - (void)calculate; /** * @brief Resets all state so that a new hash can be calculated. * * @warning This invalidates any pointer previously returned by @ref digest. If * you are still interested in the previous digest, you need to memcpy * it yourself before calling @ref reset! */ - (void)reset; @end OF_ASSUME_NONNULL_END |
Modified src/OFData+CryptographicHashing.m from [b37a0e9886] to [caf70aabc2].
︙ | ︙ | |||
37 38 39 40 41 42 43 44 45 46 47 48 49 50 | [class hashWithAllowsSwappableMemory: true]; size_t digestSize = [class digestSize]; const unsigned char *digest; char cString[digestSize * 2]; [hash updateWithBuffer: self->_items length: self->_count * self->_itemSize]; digest = hash.digest; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; | > | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | [class hashWithAllowsSwappableMemory: true]; size_t digestSize = [class digestSize]; const unsigned char *digest; char cString[digestSize * 2]; [hash updateWithBuffer: self->_items length: self->_count * self->_itemSize]; [hash calculate]; digest = hash.digest; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; |
︙ | ︙ |
Modified src/OFHMAC.h from [512d223663] to [618167fc85].
︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 109 110 111 112 | * @brief Adds a buffer to the HMAC to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Resets the HMAC so that it can be calculated for a new message. * * @note This does not reset the key so that a new HMAC with the same key can * be calculated efficiently. If you want to reset both, use * @ref setKey:length:. * | > > > > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | * @brief Adds a buffer to the HMAC to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Performs the final calculation of the HMAC. */ - (void)calculate; /** * @brief Resets the HMAC so that it can be calculated for a new message. * * @note This does not reset the key so that a new HMAC with the same key can * be calculated efficiently. If you want to reset both, use * @ref setKey:length:. * |
︙ | ︙ |
Modified src/OFHMAC.m from [8f7abda357] to [2ceebc7fc2].
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include "config.h" #import "OFHMAC.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFInvalidArgumentException.h" @implementation OFHMAC @synthesize hashClass = _hashClass; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (instancetype)HMACWithHashClass: (Class <OFCryptographicHash>)class | > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "config.h" #import "OFHMAC.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFInvalidArgumentException.h" @implementation OFHMAC @synthesize hashClass = _hashClass; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (instancetype)HMACWithHashClass: (Class <OFCryptographicHash>)class |
︙ | ︙ | |||
80 81 82 83 84 85 86 87 88 89 90 91 92 93 | @try { if (length > blockSize) { id <OFCryptographicHash> hash = [_hashClass hashWithAllowsSwappableMemory: _allowsSwappableMemory]; [hash updateWithBuffer: key length: length]; length = hash.digestSize; if OF_UNLIKELY (length > blockSize) length = blockSize; memcpy(outerKeyPadItems, hash.digest, length); memcpy(innerKeyPadItems, hash.digest, length); | > | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | @try { if (length > blockSize) { id <OFCryptographicHash> hash = [_hashClass hashWithAllowsSwappableMemory: _allowsSwappableMemory]; [hash updateWithBuffer: key length: length]; [hash calculate]; length = hash.digestSize; if OF_UNLIKELY (length > blockSize) length = blockSize; memcpy(outerKeyPadItems, hash.digest, length); memcpy(innerKeyPadItems, hash.digest, length); |
︙ | ︙ | |||
136 137 138 139 140 141 142 | if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; [_innerHash updateWithBuffer: buffer length: length]; } | | > > > > | < < > > > > > > > | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; [_innerHash updateWithBuffer: buffer length: length]; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; if (_outerHash == nil || _innerHash == nil) @throw [OFInvalidArgumentException exception]; [_innerHash calculate]; [_outerHash updateWithBuffer: _innerHash.digest length: _innerHash.digestSize]; [_outerHash calculate]; _calculated = true; } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return _outerHash.digest; } - (size_t)digestSize { return [_hashClass digestSize]; |
︙ | ︙ |
Modified src/OFMD5Hash.m from [7457ae87b9] to [190d96fa7c].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <string.h> #import "OFMD5Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 16; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFMD5Hash () | > | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <string.h> #import "OFMD5Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 16; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFMD5Hash () |
︙ | ︙ | |||
240 241 242 243 244 245 246 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { | | > > | > > > > > > > < < | 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToLittleEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); _iVars->buffer.words[15] = OFToLittleEndian32((uint32_t)(_iVars->bits >> 32)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfBE(_iVars->state, 4); _calculated = true; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end |
Modified src/OFPBKDF2.m from [b45f589efb] to [cca92e4a20].
︙ | ︙ | |||
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | size_t length; memcpy(extendedSaltItems + param.saltLength, &i, 4); [param.HMAC reset]; [param.HMAC updateWithBuffer: extendedSaltItems length: param.saltLength + 4]; memcpy(bufferItems, param.HMAC.digest, digestSize); memcpy(digestItems, param.HMAC.digest, digestSize); for (size_t j = 1; j < param.iterations; j++) { [param.HMAC reset]; [param.HMAC updateWithBuffer: digestItems length: digestSize]; memcpy(digestItems, param.HMAC.digest, digestSize); for (size_t k = 0; k < digestSize; k++) bufferItems[k] ^= digestItems[k]; } | > > | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | size_t length; memcpy(extendedSaltItems + param.saltLength, &i, 4); [param.HMAC reset]; [param.HMAC updateWithBuffer: extendedSaltItems length: param.saltLength + 4]; [param.HMAC calculate]; memcpy(bufferItems, param.HMAC.digest, digestSize); memcpy(digestItems, param.HMAC.digest, digestSize); for (size_t j = 1; j < param.iterations; j++) { [param.HMAC reset]; [param.HMAC updateWithBuffer: digestItems length: digestSize]; [param.HMAC calculate]; memcpy(digestItems, param.HMAC.digest, digestSize); for (size_t k = 0; k < digestSize; k++) bufferItems[k] ^= digestItems[k]; } |
︙ | ︙ |
Modified src/OFRIPEMD160Hash.m from [237ac280a3] to [a6c68d768d].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <string.h> #import "OFRIPEMD160Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 20; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFRIPEMD160Hash () | > | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <string.h> #import "OFRIPEMD160Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 20; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFRIPEMD160Hash () |
︙ | ︙ | |||
254 255 256 257 258 259 260 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { | | > > | > > > > > > > < < | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToLittleEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); _iVars->buffer.words[15] = OFToLittleEndian32((uint32_t)(_iVars->bits >> 32)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfBE(_iVars->state, 5); _calculated = true; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end |
Modified src/OFSHA1Hash.m from [8fbe25b6ab] to [6da836d4ff].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <string.h> #import "OFSHA1Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 20; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFSHA1Hash () | > | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <string.h> #import "OFSHA1Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 20; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFSHA1Hash () |
︙ | ︙ | |||
214 215 216 217 218 219 220 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { | | > > | > > > > > > > < < | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToBigEndian32((uint32_t)(_iVars->bits >> 32)); _iVars->buffer.words[15] = OFToBigEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 5); _calculated = true; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end |
Modified src/OFSHA224Or256Hash.m from [19bc34b26d] to [de7aa6c8f4].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <stdlib.h> #include <string.h> #import "OFSHA224Or256Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 64; @interface OFSHA224Or256Hash () - (void)of_resetState; @end | > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdlib.h> #include <string.h> #import "OFSHA224Or256Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 64; @interface OFSHA224Or256Hash () - (void)of_resetState; @end |
︙ | ︙ | |||
230 231 232 233 234 235 236 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { | | > > | > > > > > > > < < | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToBigEndian32((uint32_t)(_iVars->bits >> 32)); _iVars->buffer.words[15] = OFToBigEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 8); _calculated = true; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); |
︙ | ︙ |
Modified src/OFSHA384Or512Hash.m from [1c897d691a] to [f0d2e79fad].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <stdlib.h> #include <string.h> #import "OFSHA384Or512Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 128; @interface OFSHA384Or512Hash () - (void)of_resetState; @end | > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdlib.h> #include <string.h> #import "OFSHA384Or512Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 128; @interface OFSHA384Or512Hash () - (void)of_resetState; @end |
︙ | ︙ | |||
243 244 245 246 247 248 249 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { | | > > | > > > > > > > < < | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | _iVars->bufferLength = 0; } } } - (const unsigned char *)digest { if (!_calculated) @throw [OFHashNotCalculatedException exceptionWithObject: self]; return (const unsigned char *)_iVars->state; } - (void)calculate { if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 128 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 112) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 128); } _iVars->buffer.words[14] = OFToBigEndian64(_iVars->bits[1]); _iVars->buffer.words[15] = OFToBigEndian64(_iVars->bits[0]); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 8); _calculated = true; } - (void)reset { [self of_resetState]; OFZeroMemory(_iVars->bits, sizeof(_iVars->bits)); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); |
︙ | ︙ |
Modified src/OFString+CryptographicHashing.m from [98d19965a9] to [30b5bea6f8].
︙ | ︙ | |||
35 36 37 38 39 40 41 42 43 44 45 46 47 48 | id <OFCryptographicHash> hash = [class hashWithAllowsSwappableMemory: true]; size_t digestSize = [class digestSize]; const unsigned char *digest; char cString[digestSize * 2]; [hash updateWithBuffer: self.UTF8String length: self.UTF8StringLength]; digest = hash.digest; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; | > | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | id <OFCryptographicHash> hash = [class hashWithAllowsSwappableMemory: true]; size_t digestSize = [class digestSize]; const unsigned char *digest; char cString[digestSize * 2]; [hash updateWithBuffer: self.UTF8String length: self.UTF8StringLength]; [hash calculate]; digest = hash.digest; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; |
︙ | ︙ |
Modified src/exceptions/Makefile from [d98a82648f] to [d0a796337a].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 | OFCopyItemFailedException.m \ OFCreateDirectoryFailedException.m \ OFCreateSymbolicLinkFailedException.m \ OFEnumerationMutationException.m \ OFException.m \ OFGetOptionFailedException.m \ OFHashAlreadyCalculatedException.m \ OFInitializationFailedException.m \ OFInvalidArgumentException.m \ OFInvalidEncodingException.m \ OFInvalidFormatException.m \ OFInvalidJSONException.m \ OFInvalidServerReplyException.m \ OFLinkFailedException.m \ | > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | OFCopyItemFailedException.m \ OFCreateDirectoryFailedException.m \ OFCreateSymbolicLinkFailedException.m \ OFEnumerationMutationException.m \ OFException.m \ OFGetOptionFailedException.m \ OFHashAlreadyCalculatedException.m \ OFHashNotCalculatedException.m \ OFInitializationFailedException.m \ OFInvalidArgumentException.m \ OFInvalidEncodingException.m \ OFInvalidFormatException.m \ OFInvalidJSONException.m \ OFInvalidServerReplyException.m \ OFLinkFailedException.m \ |
︙ | ︙ |
Added src/exceptions/OFHashNotCalculatedException.h version [83488903fa].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFHashNotCalculatedException OFHashNotCalculatedException.h \ * ObjFW/OFHashNotCalculatedException.h * * @brief An exception indicating that the hash has not been calculated yet. */ @interface OFHashNotCalculatedException: OFException { id _object; } /** * @brief The hash which has not been calculated yet. */ @property (readonly, nonatomic) id object; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Creates a new, autoreleased hash not calculated exception. * * @param object The hash which has not been calculated yet * @return A new, autoreleased hash not calculated exception */ + (instancetype)exceptionWithObject: (id)object; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated hash not calculated exception. * * @param object The hash which has not been calculated yet * @return An initialized hash not calculated exception */ - (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Added src/exceptions/OFHashNotCalculatedException.m version [3e84cb3642].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFHashNotCalculatedException.h" #import "OFString.h" @implementation OFHashNotCalculatedException @synthesize object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object { return [[[self alloc] initWithObject: object] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object { self = [super init]; _object = [object retain]; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The hash of type %@ has not been calculated yet!", [_object class]]; } @end |
Modified tests/OFHMACTests.m from [391ed8c509] to [7c5227bed5].
︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 109 110 111 112 | [HMACRMD160 updateWithBuffer: buffer length: length]; [HMACSHA256 updateWithBuffer: buffer length: length]; [HMACSHA384 updateWithBuffer: buffer length: length]; [HMACSHA512 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[digest] with MD5", memcmp(HMACMD5.digest, MD5Digest, HMACMD5.digestSize) == 0) TEST(@"-[digest] with SHA-1", memcmp(HMACSHA1.digest, SHA1Digest, HMACSHA1.digestSize) == 0) TEST(@"-[digest] with RIPEMD-160", memcmp(HMACRMD160.digest, RIPEMD160Digest, HMACRMD160.digestSize) == 0) | > > > > > > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | [HMACRMD160 updateWithBuffer: buffer length: length]; [HMACSHA256 updateWithBuffer: buffer length: length]; [HMACSHA384 updateWithBuffer: buffer length: length]; [HMACSHA512 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[calculate] with MD5", R([HMACMD5 calculate])) TEST(@"-[calculate] with SHA-1", R([HMACSHA1 calculate])) TEST(@"-[calculate] with RIPEMD-160", R([HMACRMD160 calculate])) TEST(@"-[calculate] with SHA-256", R([HMACSHA256 calculate])) TEST(@"-[calculate] with SHA-384", R([HMACSHA384 calculate])) TEST(@"-[calculate] with SHA-512", R([HMACSHA512 calculate])) TEST(@"-[digest] with MD5", memcmp(HMACMD5.digest, MD5Digest, HMACMD5.digestSize) == 0) TEST(@"-[digest] with SHA-1", memcmp(HMACSHA1.digest, SHA1Digest, HMACSHA1.digestSize) == 0) TEST(@"-[digest] with RIPEMD-160", memcmp(HMACRMD160.digest, RIPEMD160Digest, HMACRMD160.digestSize) == 0) |
︙ | ︙ |
Modified tests/OFMD5HashTests.m from [4a39a103b5] to [6eb26d1d7b].
︙ | ︙ | |||
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [MD5 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (MD5Copy = [[MD5 copy] autorelease])) TEST(@"-[digest]", memcmp(MD5.digest, testFileMD5, 16) == 0 && memcmp(MD5Copy.digest, testFileMD5, 16) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length]", OFHashAlreadyCalculatedException, [MD5 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end | > > | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [MD5 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (MD5Copy = [[MD5 copy] autorelease])) TEST(@"-[calculate]", R([MD5 calculate]) && R([MD5Copy calculate])) TEST(@"-[digest]", memcmp(MD5.digest, testFileMD5, 16) == 0 && memcmp(MD5Copy.digest, testFileMD5, 16) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length]", OFHashAlreadyCalculatedException, [MD5 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFRIPEMD160HashTests.m from [13f4c4529e] to [4b80756e64].
︙ | ︙ | |||
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | size_t length = [file readIntoBuffer: buffer length: 64]; [RIPEMD160 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (RIPEMD160Copy = [[RIPEMD160 copy] autorelease])) TEST(@"-[digest]", memcmp(RIPEMD160.digest, testFileRIPEMD160, 20) == 0 && memcmp(RIPEMD160Copy.digest, testFileRIPEMD160, 20) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length]", OFHashAlreadyCalculatedException, [RIPEMD160 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end | > > > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | size_t length = [file readIntoBuffer: buffer length: 64]; [RIPEMD160 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (RIPEMD160Copy = [[RIPEMD160 copy] autorelease])) TEST(@"-[calculate]", R([RIPEMD160 calculate]) && R([RIPEMD160Copy calculate])) TEST(@"-[digest]", memcmp(RIPEMD160.digest, testFileRIPEMD160, 20) == 0 && memcmp(RIPEMD160Copy.digest, testFileRIPEMD160, 20) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length]", OFHashAlreadyCalculatedException, [RIPEMD160 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA1HashTests.m from [3904915a0d] to [f5847018f6].
︙ | ︙ | |||
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [SHA1 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA1Copy = [[SHA1 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA1.digest, testFileSHA1, 20) == 0 && memcmp(SHA1Copy.digest, testFileSHA1, 20) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA1 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end | > > | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [SHA1 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA1Copy = [[SHA1 copy] autorelease])) TEST(@"-[calculate]", R([SHA1 calculate]) && R([SHA1Copy calculate])) TEST(@"-[digest]", memcmp(SHA1.digest, testFileSHA1, 20) == 0 && memcmp(SHA1Copy.digest, testFileSHA1, 20) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA1 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA224HashTests.m from [81d4ab4317] to [f0d335ef4f].
︙ | ︙ | |||
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | size_t length = [file readIntoBuffer: buffer length: 64]; [SHA224 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA224Copy = [[SHA224 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA224.digest, testFileSHA224, 28) == 0 && memcmp(SHA224Copy.digest, testFileSHA224, 28) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA224 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end | > > > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | size_t length = [file readIntoBuffer: buffer length: 64]; [SHA224 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA224Copy = [[SHA224 copy] autorelease])) TEST(@"-[calculate]", R([SHA224 calculate]) && R([SHA224Copy calculate])) TEST(@"-[digest]", memcmp(SHA224.digest, testFileSHA224, 28) == 0 && memcmp(SHA224Copy.digest, testFileSHA224, 28) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA224 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA256HashTests.m from [2e31055b19] to [2075144684].
︙ | ︙ | |||
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | size_t length = [file readIntoBuffer: buffer length: 64]; [SHA256 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA256Copy = [[SHA256 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA256.digest, testFileSHA256, 32) == 0 && memcmp(SHA256Copy.digest, testFileSHA256, 32) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA256 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end | > > > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | size_t length = [file readIntoBuffer: buffer length: 64]; [SHA256 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA256Copy = [[SHA256 copy] autorelease])) TEST(@"-[calculate]", R([SHA256 calculate]) && R([SHA256Copy calculate])) TEST(@"-[digest]", memcmp(SHA256.digest, testFileSHA256, 32) == 0 && memcmp(SHA256Copy.digest, testFileSHA256, 32) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA256 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA384HashTests.m from [e19c6a87fc] to [9815671ea1].
︙ | ︙ | |||
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | size_t length = [file readIntoBuffer: buffer length: 128]; [SHA384 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA384Copy = [[SHA384 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA384.digest, testFileSHA384, 48) == 0 && memcmp(SHA384Copy.digest, testFileSHA384, 48) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA384 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end | > > > | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | size_t length = [file readIntoBuffer: buffer length: 128]; [SHA384 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA384Copy = [[SHA384 copy] autorelease])) TEST(@"-[calculate]", R([SHA384 calculate]) && R([SHA384Copy calculate])) TEST(@"-[digest]", memcmp(SHA384.digest, testFileSHA384, 48) == 0 && memcmp(SHA384Copy.digest, testFileSHA384, 48) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA384 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA512HashTests.m from [3e05a03d90] to [8ea1d53446].
︙ | ︙ | |||
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | size_t length = [file readIntoBuffer: buffer length: 128]; [SHA512 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA512Copy = [[SHA512 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA512.digest, testFileSHA512, 64) == 0 && memcmp(SHA512Copy.digest, testFileSHA512, 64) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA512 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end | > > > | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | size_t length = [file readIntoBuffer: buffer length: 128]; [SHA512 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA512Copy = [[SHA512 copy] autorelease])) TEST(@"-[calculate]", R([SHA512 calculate]) && R([SHA512Copy calculate])) TEST(@"-[digest]", memcmp(SHA512.digest, testFileSHA512, 64) == 0 && memcmp(SHA512Copy.digest, testFileSHA512, 64) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA512 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified utils/ofhash/OFHash.m from [b400e7645a] to [1e29e681a3].
︙ | ︙ | |||
49 50 51 52 53 54 55 | [OFApplication terminateWithStatus: 1]; } static void printHash(OFString *algo, OFString *path, id <OFCryptographicHash> hash) { | > | > > | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | [OFApplication terminateWithStatus: 1]; } static void printHash(OFString *algo, OFString *path, id <OFCryptographicHash> hash) { size_t digestSize = hash.digestSize; const unsigned char *digest; [hash calculate]; digest = hash.digest; [OFStdOut writeFormat: @"%@ ", algo]; for (size_t i = 0; i < digestSize; i++) [OFStdOut writeFormat: @"%02x", digest[i]]; [OFStdOut writeFormat: @" %@\n", path]; |
︙ | ︙ |