ObjFW  Check-in [9b2d255a3d]

Overview
Comment:Make OFHash a protocol.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9b2d255a3d69282e63da1eb7afa2260670b2d5c0dc55d2b8f6c0b0189489e93e
User & Date: js on 2013-02-18 23:05:20
Other Links: manifest | tags
Context
2013-02-19
11:57
OFCountedSet: More thorough range check. check-in: bf8a579f38 user: js tags: trunk
2013-02-18
23:05
Make OFHash a protocol. check-in: 9b2d255a3d user: js tags: trunk
22:00
Rename OFXMLParser's _cache to _buffer. check-in: 265a0928ca user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [58c2011970] to [c7bbe66b12].

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
150
151
152
153
154
155
156

157
158
159
160
161
162
163







-







		4B3D238F1337FC0D00DD29B8 /* OFConstantString.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0D812DF4225005C7A0C /* OFConstantString.m */; };
		4B3D23901337FC0D00DD29B8 /* OFDataArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6799611099E7C50041064A /* OFDataArray.m */; };
		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 */; };
		4B3D239D1337FC0D00DD29B8 /* OFMutableString.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6799741099E7C50041064A /* OFMutableString.m */; };
		4B3D239E1337FC0D00DD29B8 /* OFNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6799761099E7C50041064A /* OFNumber.m */; };
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
792
793
794
795
796
797
798

799
800
801
802
803
804
805







-







		4BE5F0D912DF4225005C7A0C /* OFDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFDate.h; path = src/OFDate.h; sourceTree = SOURCE_ROOT; };
		4BE5F0DA12DF4225005C7A0C /* OFDate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFDate.m; path = src/OFDate.m; sourceTree = SOURCE_ROOT; };
		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 = "<group>"; };
		4BF1BCC011C9663F0025511F /* OFHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFHash.h; path = src/OFHash.h; sourceTree = "<group>"; };
		4BF1BCC111C9663F0025511F /* OFHash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHash.m; path = src/OFHash.m; sourceTree = "<group>"; };
		4BF1BCC211C9663F0025511F /* OFMD5Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMD5Hash.h; path = src/OFMD5Hash.h; sourceTree = "<group>"; };
		4BF1BCC311C9663F0025511F /* OFMD5Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMD5Hash.m; path = src/OFMD5Hash.m; sourceTree = "<group>"; };
		4BF1BCC411C9663F0025511F /* OFSHA1Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSHA1Hash.h; path = src/OFSHA1Hash.h; sourceTree = "<group>"; };
		4BF1BCC511C9663F0025511F /* OFSHA1Hash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSHA1Hash.m; path = src/OFSHA1Hash.m; sourceTree = "<group>"; };
		4BF1BCC611C9663F0025511F /* OFString+Hashing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+Hashing.h"; path = "src/OFString+Hashing.h"; sourceTree = "<group>"; };
		4BF1BCC711C9663F0025511F /* OFString+Hashing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFString+Hashing.m"; path = "src/OFString+Hashing.m"; sourceTree = "<group>"; };
		4BF1BCC811C9663F0025511F /* OFString+URLEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+URLEncoding.h"; path = "src/OFString+URLEncoding.h"; sourceTree = "<group>"; };
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1091
1092
1093
1094
1095
1096
1097

1098
1099
1100
1101
1102
1103
1104







-







				4B2B3E75140D430500EC2F7C /* OFDictionary_hashtable.h */,
				4B2B3E76140D430500EC2F7C /* OFDictionary_hashtable.m */,
				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 */,
				4BFDB4CF168B939A006A4027 /* OFHTTPRequestReply.m */,
				4BB4B54116775FF4002A2DCE /* OFHTTPServer.h */,
1596
1597
1598
1599
1600
1601
1602
1603

1604
1605
1606
1607
1608
1609
1610
1593
1594
1595
1596
1597
1598
1599

1600
1601
1602
1603
1604
1605
1606
1607







-
+







		};
/* End PBXNativeTarget section */

/* 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;
			knownRegions = (
				English,
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1717
1718
1719
1720
1721
1722
1723

1724
1725
1726
1727
1728
1729
1730







-







				4B3D23901337FC0D00DD29B8 /* OFDataArray.m in Sources */,
				4B3D23911337FC0D00DD29B8 /* OFDataArray+Hashing.m in Sources */,
				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 */,
				4B3D23991337FC0D00DD29B8 /* OFList.m in Sources */,
				4B3B0799166978780044E634 /* OFMapTable.m in Sources */,

Modified src/Makefile from [8c24021c12] to [12f61571f7].

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
16
17
18
19
20
21
22

23
24
25
26
27
28
29







-







       OFCountedSet.m			\
       OFDataArray.m			\
       OFDataArray+Hashing.m		\
       OFDate.m				\
       OFDictionary.m			\
       OFEnumerator.m			\
       OFFile.m				\
       OFHash.m				\
       OFHTTPClient.m			\
       OFHTTPRequest.m			\
       OFHTTPRequestReply.m		\
       OFHTTPServer.m			\
       OFIntrospection.m		\
       OFList.m				\
       OFMapTable.m			\
80
81
82
83
84
85
86

87
88
89
90
91
92
93
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93







+







	       OFThread.m		\
	       OFThreadPool.m		\
	       OFTLSKey.m

INCLUDES_THREADS = threading.h
INCLUDES := ${SRCS:.m=.h}		\
	    OFCollection.h		\
	    OFHash.h			\
	    OFJSONRepresentation.h	\
	    OFLocking.h			\
	    OFSerialization.h		\
	    OFTLSSocket.h		\
	    ObjFW.h			\
	    asprintf.h			\
	    autorelease.h		\

Modified src/OFHash.h from [9f5b79c75d] to [f3fad14a9f].

13
14
15
16
17
18
19
20

21
22
23
24
25
26

27
28
29
30
31
32
33
13
14
15
16
17
18
19

20
21





22
23
24
25
26
27
28
29







-
+

-
-
-
-
-
+







 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#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 <OFObject>
#ifdef OF_HAVE_PROPERTIES
@property (readonly, getter=isCalculated) BOOL calculated;
#endif

/*!
 * @brief Creates a new hash.
 *

Deleted src/OFHash.m version [f22a074494].

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


























































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <stdlib.h>

#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

Modified src/OFMD5Hash.h from [efbff1e954] to [833fa196ed].

17
18
19
20
21
22
23
24

25
26
27
28
29
30
31

32
33
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34







-
+







+


#import "OFHash.h"

#define OF_MD5_DIGEST_SIZE 16

/*!
 * @brief A class which provides functions to create an MD5 hash.
 */
@interface OFMD5Hash: OFHash
@interface OFMD5Hash: OFObject <OFHash>
{
	uint32_t _buffer[4];
	uint32_t _bits[2];
	union {
		uint8_t	u8[64];
		uint32_t u32[16];
	} _in;
	BOOL _calculated;
}
@end

Modified src/OFMD5Hash.m from [969e062cb6] to [83d7c707b9].

137
138
139
140
141
142
143





144
145
146
147
148
149
150
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155







+
+
+
+
+







	return 16;
}

+ (size_t)blockSize
{
	return 64;
}

+ (instancetype)hash
{
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];

	_buffer[0] = 0x67452301;
	_buffer[1] = 0xEFCDAB89;
254
255
256
257
258
259
260





261
259
260
261
262
263
264
265
266
267
268
269
270
271







+
+
+
+
+

	md5_transform(_buffer, _in.u32);
	BSWAP32_VEC_IF_BE(_buffer, 4);

	_calculated = YES;

	return (uint8_t*)_buffer;
}

- (BOOL)isCalculated
{
	return _calculated;
}
@end

Modified src/OFSHA1Hash.h from [0a2f6efcc5] to [6e69faf3b5].

17
18
19
20
21
22
23
24

25
26
27
28
29

30
31
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32







-
+





+


#import "OFHash.h"

#define OF_SHA1_DIGEST_SIZE 20

/*!
 * @brief A class which provides functions to create an SHA1 hash.
 */
@interface OFSHA1Hash: OFHash
@interface OFSHA1Hash: OFObject <OFHash>
{
	uint32_t _state[5];
	uint64_t _count;
	char	 _buffer[64];
	uint8_t	 _digest[OF_SHA1_DIGEST_SIZE];
	BOOL	 _calculated;
}
@end

Modified src/OFSHA1Hash.m from [25afa6488f] to [264141bf82].

134
135
136
137
138
139
140





141
142
143
144
145
146
147
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152







+
+
+
+
+







	return 20;
}

+ (size_t)blockSize
{
	return 64;
}

+ (instancetype)hash
{
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];

	_state[0] = 0x67452301;
	_state[1] = 0xEFCDAB89;
188
189
190
191
192
193
194





195
193
194
195
196
197
198
199
200
201
202
203
204
205







+
+
+
+
+

		_digest[i] = (char)((_state[i >> 2] >>
		    ((3 - (i & 3)) * 8)) & 255);

	_calculated = YES;

	return _digest;
}

- (BOOL)isCalculated
{
	return _calculated;
}
@end

Modified src/exceptions/OFHashAlreadyCalculatedException.h from [3c8cb83bb8] to [475c359189].

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
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







-
-
+






-
+



-
+










-
+









-
+






-
+

 * 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"

@class OFHash;
#import "OFHash.h"

/*!
 * @brief An exception indicating that the hash has already been calculated.
 */
@interface OFHashAlreadyCalculatedException: OFException
{
	OFHash *_hashObject;
	id <OFHash> _hashObject;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, retain, nonatomic) OFHash *hashObject;
@property (readonly, retain, nonatomic) id <OFHash> hashObject;
#endif

/*!
 * @brief Creates a new, autoreleased 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 A new, autoreleased hash already calculated exception
 */
+ (instancetype)exceptionWithClass: (Class)class_
			      hash: (OFHash*)hashObject;
			      hash: (id <OFHash>)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 <OFHash>)hashObject;

/*!
 * @brief Returns the hash which has already been calculated.
 *
 * @return The hash which has already been calculated
 */
- (OFHash*)hashObject;
- (id <OFHash>)hashObject;
@end

Modified src/exceptions/OFHashAlreadyCalculatedException.m from [6c880cfe21] to [c96d938c3c].

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
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







-





-
+


















-
+








#include "config.h"

#include <stdlib.h>

#import "OFHashAlreadyCalculatedException.h"
#import "OFString.h"
#import "OFHash.h"

#import "common.h"

@implementation OFHashAlreadyCalculatedException
+ (instancetype)exceptionWithClass: (Class)class
			      hash: (OFHash*)hash
			      hash: (id <OFHash>)hash
{
	return [[[self alloc] initWithClass: class
				       hash: hash] autorelease];
}

- initWithClass: (Class)class
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}

- initWithClass: (Class)class
	   hash: (OFHash*)hashObject
	   hash: (id <OFHash>)hashObject
{
	self = [super initWithClass: class];

	_hashObject = [hashObject retain];

	return self;
}
64
65
66
67
68
69
70
71

72
73
74
75
63
64
65
66
67
68
69

70
71
72
73
74







-
+




- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"The hash has already been calculated in class %@ and thus no new "
	    @"data can be added", _inClass];
}

- (OFHash*)hashObject
- (id <OFHash>)hashObject
{
	OF_GETTER(_hashObject, NO)
}
@end