Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -152,11 +152,10 @@ 4B3D23911337FC0D00DD29B8 /* OFDataArray+Hashing.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE17ADA12FD746D002CEB0B /* OFDataArray+Hashing.m */; }; 4B3D23921337FC0D00DD29B8 /* OFDate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0DA12DF4225005C7A0C /* OFDate.m */; }; 4B3D23931337FC0D00DD29B8 /* OFDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6799631099E7C50041064A /* OFDictionary.m */; }; 4B3D23941337FC0D00DD29B8 /* OFEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B0108CA10EB8C9300631877 /* OFEnumerator.m */; }; 4B3D23961337FC0D00DD29B8 /* OFFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6799671099E7C50041064A /* OFFile.m */; }; - 4B3D23971337FC0D00DD29B8 /* OFHash.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BF1BCC111C9663F0025511F /* OFHash.m */; }; 4B3D23981337FC0D00DD29B8 /* OFHTTPRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B99251012E0780000215DBE /* OFHTTPRequest.m */; }; 4B3D23991337FC0D00DD29B8 /* OFList.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B67996D1099E7C50041064A /* OFList.m */; }; 4B3D239A1337FC0D00DD29B8 /* OFMD5Hash.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BF1BCC311C9663F0025511F /* OFMD5Hash.m */; }; 4B3D239B1337FC0D00DD29B8 /* OFMutableArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6799701099E7C50041064A /* OFMutableArray.m */; }; 4B3D239C1337FC0D00DD29B8 /* OFMutableDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6799721099E7C50041064A /* OFMutableDictionary.m */; }; @@ -795,11 +794,10 @@ 4BE5F0E412DF4259005C7A0C /* OFBlockTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFBlockTests.m; path = tests/OFBlockTests.m; sourceTree = SOURCE_ROOT; }; 4BE5F0E512DF4259005C7A0C /* OFDateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFDateTests.m; path = tests/OFDateTests.m; sourceTree = SOURCE_ROOT; }; 4BF0749512DFAFCA00A4ADD1 /* OFURLTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFURLTests.m; path = tests/OFURLTests.m; sourceTree = SOURCE_ROOT; }; 4BF1BCBF11C9663F0025511F /* objfw-defs.h.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "objfw-defs.h.in"; path = "src/objfw-defs.h.in"; sourceTree = ""; }; 4BF1BCC011C9663F0025511F /* OFHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFHash.h; path = src/OFHash.h; sourceTree = ""; }; - 4BF1BCC111C9663F0025511F /* OFHash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHash.m; path = src/OFHash.m; sourceTree = ""; }; 4BF1BCC211C9663F0025511F /* OFMD5Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMD5Hash.h; path = src/OFMD5Hash.h; sourceTree = ""; }; 4BF1BCC311C9663F0025511F /* OFMD5Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMD5Hash.m; path = src/OFMD5Hash.m; sourceTree = ""; }; 4BF1BCC411C9663F0025511F /* OFSHA1Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSHA1Hash.h; path = src/OFSHA1Hash.h; sourceTree = ""; }; 4BF1BCC511C9663F0025511F /* OFSHA1Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA1Hash.m; path = src/OFSHA1Hash.m; sourceTree = ""; }; 4BF1BCC611C9663F0025511F /* OFString+Hashing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+Hashing.h"; path = "src/OFString+Hashing.h"; sourceTree = ""; }; @@ -1095,11 +1093,10 @@ 4B0108C910EB8C9300631877 /* OFEnumerator.h */, 4B0108CA10EB8C9300631877 /* OFEnumerator.m */, 4B6799661099E7C50041064A /* OFFile.h */, 4B6799671099E7C50041064A /* OFFile.m */, 4BF1BCC011C9663F0025511F /* OFHash.h */, - 4BF1BCC111C9663F0025511F /* OFHash.m */, 4BB4B53F16775FF4002A2DCE /* OFHTTPClient.h */, 4BB4B54016775FF4002A2DCE /* OFHTTPClient.m */, 4B99250F12E0780000215DBE /* OFHTTPRequest.h */, 4B99251012E0780000215DBE /* OFHTTPRequest.m */, 4BFDB4CE168B939A006A4027 /* OFHTTPRequestReply.h */, @@ -1598,11 +1595,11 @@ /* Begin PBXProject section */ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0450; + LastUpgradeCheck = 0460; }; buildConfigurationList = 1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "ObjFW" */; compatibilityVersion = "Xcode 3.1"; developmentRegion = English; hasScannedForEncodings = 1; @@ -1722,11 +1719,10 @@ 4B3D23921337FC0D00DD29B8 /* OFDate.m in Sources */, 4B3D23931337FC0D00DD29B8 /* OFDictionary.m in Sources */, 4B2B3E80140D430500EC2F7C /* OFDictionary_hashtable.m in Sources */, 4B3D23941337FC0D00DD29B8 /* OFEnumerator.m in Sources */, 4B3D23961337FC0D00DD29B8 /* OFFile.m in Sources */, - 4B3D23971337FC0D00DD29B8 /* OFHash.m in Sources */, 4BB4B54516775FF4002A2DCE /* OFHTTPClient.m in Sources */, 4B3D23981337FC0D00DD29B8 /* OFHTTPRequest.m in Sources */, 4BFDB4D2168B93CB006A4027 /* OFHTTPRequestReply.m in Sources */, 4BB4B54716775FF4002A2DCE /* OFHTTPServer.m in Sources */, 4BA49D9113DB113B00381CDB /* OFIntrospection.m in Sources */, Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -18,11 +18,10 @@ OFDataArray+Hashing.m \ OFDate.m \ OFDictionary.m \ OFEnumerator.m \ OFFile.m \ - OFHash.m \ OFHTTPClient.m \ OFHTTPRequest.m \ OFHTTPRequestReply.m \ OFHTTPServer.m \ OFIntrospection.m \ @@ -82,10 +81,11 @@ OFTLSKey.m INCLUDES_THREADS = threading.h INCLUDES := ${SRCS:.m=.h} \ OFCollection.h \ + OFHash.h \ OFJSONRepresentation.h \ OFLocking.h \ OFSerialization.h \ OFTLSSocket.h \ ObjFW.h \ Index: src/OFHash.h ================================================================== --- src/OFHash.h +++ src/OFHash.h @@ -15,17 +15,13 @@ */ #import "OFObject.h" /*! - * @brief A base class for classes providing hash functions. + * @brief A protocol for classes providing hash functions. */ -@interface OFHash: OFObject -{ - BOOL _calculated; -} - +@protocol OFHash #ifdef OF_HAVE_PROPERTIES @property (readonly, getter=isCalculated) BOOL calculated; #endif /*! DELETED src/OFHash.m Index: src/OFHash.m ================================================================== --- src/OFHash.m +++ src/OFHash.m @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 - * 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 - * 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" - -#include - -#import "OFHash.h" - -@implementation OFHash -+ (instancetype)hash -{ - return [[[self alloc] init] autorelease]; -} - -+ (size_t)digestSize -{ - [self doesNotRecognizeSelector: _cmd]; - abort(); -} - -+ (size_t)blockSize -{ - [self doesNotRecognizeSelector: _cmd]; - abort(); -} - -- (void)updateWithBuffer: (const void*)buffer - length: (size_t)length -{ - [self doesNotRecognizeSelector: _cmd]; - abort(); -} - -- (uint8_t*)digest -{ - [self doesNotRecognizeSelector: _cmd]; - abort(); -} - -- (BOOL)isCalculated -{ - return _calculated; -} -@end Index: src/OFMD5Hash.h ================================================================== --- src/OFMD5Hash.h +++ src/OFMD5Hash.h @@ -19,15 +19,16 @@ #define OF_MD5_DIGEST_SIZE 16 /*! * @brief A class which provides functions to create an MD5 hash. */ -@interface OFMD5Hash: OFHash +@interface OFMD5Hash: OFObject { uint32_t _buffer[4]; uint32_t _bits[2]; union { uint8_t u8[64]; uint32_t u32[16]; } _in; + BOOL _calculated; } @end Index: src/OFMD5Hash.m ================================================================== --- src/OFMD5Hash.m +++ src/OFMD5Hash.m @@ -139,10 +139,15 @@ + (size_t)blockSize { return 64; } + ++ (instancetype)hash +{ + return [[[self alloc] init] autorelease]; +} - init { self = [super init]; @@ -256,6 +261,11 @@ _calculated = YES; return (uint8_t*)_buffer; } + +- (BOOL)isCalculated +{ + return _calculated; +} @end Index: src/OFSHA1Hash.h ================================================================== --- src/OFSHA1Hash.h +++ src/OFSHA1Hash.h @@ -19,13 +19,14 @@ #define OF_SHA1_DIGEST_SIZE 20 /*! * @brief A class which provides functions to create an SHA1 hash. */ -@interface OFSHA1Hash: OFHash +@interface OFSHA1Hash: OFObject { uint32_t _state[5]; uint64_t _count; char _buffer[64]; uint8_t _digest[OF_SHA1_DIGEST_SIZE]; + BOOL _calculated; } @end Index: src/OFSHA1Hash.m ================================================================== --- src/OFSHA1Hash.m +++ src/OFSHA1Hash.m @@ -136,10 +136,15 @@ + (size_t)blockSize { return 64; } + ++ (instancetype)hash +{ + return [[[self alloc] init] autorelease]; +} - init { self = [super init]; @@ -190,6 +195,11 @@ _calculated = YES; return _digest; } + +- (BOOL)isCalculated +{ + return _calculated; +} @end Index: src/exceptions/OFHashAlreadyCalculatedException.h ================================================================== --- src/exceptions/OFHashAlreadyCalculatedException.h +++ src/exceptions/OFHashAlreadyCalculatedException.h @@ -13,23 +13,22 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" - -@class OFHash; +#import "OFHash.h" /*! * @brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException { - OFHash *_hashObject; + id _hashObject; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, retain, nonatomic) OFHash *hashObject; +@property (readonly, retain, nonatomic) id hashObject; #endif /*! * @brief Creates a new, autoreleased hash already calculated exception. * @@ -36,24 +35,24 @@ * @param class_ The class of the object which caused the exception * @param hashObject The hash which has already been calculated * @return A new, autoreleased hash already calculated exception */ + (instancetype)exceptionWithClass: (Class)class_ - hash: (OFHash*)hashObject; + hash: (id )hashObject; /*! * @brief Initializes an already allocated hash already calculated exception. * * @param class_ The class of the object which caused the exception * @param hashObject The hash which has already been calculated * @return An initialized hash already calculated exception */ - initWithClass: (Class)class_ - hash: (OFHash*)hashObject; + hash: (id )hashObject; /*! * @brief Returns the hash which has already been calculated. * * @return The hash which has already been calculated */ -- (OFHash*)hashObject; +- (id )hashObject; @end Index: src/exceptions/OFHashAlreadyCalculatedException.m ================================================================== --- src/exceptions/OFHashAlreadyCalculatedException.m +++ src/exceptions/OFHashAlreadyCalculatedException.m @@ -18,17 +18,16 @@ #include #import "OFHashAlreadyCalculatedException.h" #import "OFString.h" -#import "OFHash.h" #import "common.h" @implementation OFHashAlreadyCalculatedException + (instancetype)exceptionWithClass: (Class)class - hash: (OFHash*)hash + hash: (id )hash { return [[[self alloc] initWithClass: class hash: hash] autorelease]; } @@ -43,11 +42,11 @@ abort(); } - initWithClass: (Class)class - hash: (OFHash*)hashObject + hash: (id )hashObject { self = [super initWithClass: class]; _hashObject = [hashObject retain]; @@ -66,10 +65,10 @@ return [OFString stringWithFormat: @"The hash has already been calculated in class %@ and thus no new " @"data can be added", _inClass]; } -- (OFHash*)hashObject +- (id )hashObject { OF_GETTER(_hashObject, NO) } @end