ObjFW  Check-in [c1060114f6]

Overview
Comment:OFHash: Take void* and unify convenience methods.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c1060114f66276e8e1da880c3d29b79ac1b9a67f6ff5327c869c27357ce7bbcd
User & Date: js on 2012-07-03 20:16:12
Other Links: manifest | tags
Context
2012-07-03
20:17
Get rid of a warning with clang trunk. check-in: 6ec1bc64a4 user: js tags: trunk
20:16
OFHash: Take void* and unify convenience methods. check-in: c1060114f6 user: js tags: trunk
15:50
Merge branch 'runtime' check-in: 4c4fdb3429 user: js tags: trunk
Changes

Modified configure.ac from [0661dee44a] to [13fd0aa2b6].

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
		[Whether we have objc_enumerationMutation])
])

case "$host_os" in
	darwin*)
		AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"])
		AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
		       AC_SUBST(REEXPORT_LIBOBJC, ["-Wl,-reexport-lobjc"])
			tmp="-Xarch_x86_64 -Wl,-alias_list,mach_alias_list"
			AC_SUBST(MACH_ALIAS_LIST, $tmp)
		])
		;;
esac

AC_C_BIGENDIAN([







|







252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
		[Whether we have objc_enumerationMutation])
])

case "$host_os" in
	darwin*)
		AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"])
		AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
			AC_SUBST(REEXPORT_LIBOBJC, ["-Wl,-reexport-lobjc"])
			tmp="-Xarch_x86_64 -Wl,-alias_list,mach_alias_list"
			AC_SUBST(MACH_ALIAS_LIST, $tmp)
		])
		;;
esac

AC_C_BIGENDIAN([

Modified src/OFDataArray+Hashing.m from [84f38acc0a] to [1c7d02816a].

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

int _OFDataArray_Hashing_reference;

@implementation OFDataArray (Hashing)
- (OFString*)MD5Hash
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *hash = [OFMD5Hash MD5Hash];
	uint8_t *digest;
	char cString[OF_MD5_DIGEST_SIZE * 2];
	size_t i;

	[hash updateWithBuffer: data
			length: count * itemSize];
	digest = [hash digest];







|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

int _OFDataArray_Hashing_reference;

@implementation OFDataArray (Hashing)
- (OFString*)MD5Hash
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *hash = [OFMD5Hash hash];
	uint8_t *digest;
	char cString[OF_MD5_DIGEST_SIZE * 2];
	size_t i;

	[hash updateWithBuffer: data
			length: count * itemSize];
	digest = [hash digest];
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
				  encoding: OF_STRING_ENCODING_ASCII
				    length: 32];
}

- (OFString*)SHA1Hash
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *hash = [OFSHA1Hash SHA1Hash];
	uint8_t *digest;
	char cString[OF_SHA1_DIGEST_SIZE * 2];
	size_t i;

	[hash updateWithBuffer: data
			length: count * itemSize];
	digest = [hash digest];







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
				  encoding: OF_STRING_ENCODING_ASCII
				    length: 32];
}

- (OFString*)SHA1Hash
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *hash = [OFSHA1Hash hash];
	uint8_t *digest;
	char cString[OF_SHA1_DIGEST_SIZE * 2];
	size_t i;

	[hash updateWithBuffer: data
			length: count * itemSize];
	digest = [hash digest];

Modified src/OFHash.h from [408c490e85] to [89f3a6d86f].

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
	BOOL calculated;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, getter=isCalculated) BOOL calculated;
#endif








/**
 * \brief Returns the digest size of the hash, in bytes.
 *
 * \return The digest size of the hash, in bytes
 */
+ (size_t)digestSize;

/**
 * \brief Returns the block size of the hash, in bytes.
 *
 * \return The block size of the hash, in bytes
 */
+ (size_t)blockSize;

/**
 * \brief Adds a buffer to the hash to be calculated.
 *
 * \param buf The buffer which should be included into the calculation.
 * \param length The length of the buffer
 */
- (void)updateWithBuffer: (const char*)buf
		  length: (size_t)length;

/**
 * \brief Returns a buffer containing the hash.
 *
 * The size of the buffer depends on the hash used. The buffer is part of the
 * receiver's memory pool.







>
>
>
>
>
>
>

















|


|







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
62
63
64
65
	BOOL calculated;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, getter=isCalculated) BOOL calculated;
#endif

/**
 * \brief Creates a new hash.
 *
 * \return A new autoreleased OFHash
 */
+ hash;

/**
 * \brief Returns the digest size of the hash, in bytes.
 *
 * \return The digest size of the hash, in bytes
 */
+ (size_t)digestSize;

/**
 * \brief Returns the block size of the hash, in bytes.
 *
 * \return The block size of the hash, in bytes
 */
+ (size_t)blockSize;

/**
 * \brief Adds a buffer to the 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 Returns a buffer containing the hash.
 *
 * The size of the buffer depends on the hash used. The buffer is part of the
 * receiver's memory pool.

Modified src/OFHash.m from [789e0520fc] to [7dbf281922].

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
#include "config.h"

#import "OFHash.h"

#import "OFNotImplementedException.h"

@implementation OFHash





+ (size_t)digestSize
{
	@throw [OFNotImplementedException exceptionWithClass: self
						    selector: _cmd];
}

+ (size_t)blockSize
{
	@throw [OFNotImplementedException exceptionWithClass: self
						    selector: _cmd];
}

- (void)updateWithBuffer: (const char*)buffer
		  length: (size_t)length
{
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}

- (uint8_t*)digest







>
>
>
>
>












|







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
#include "config.h"

#import "OFHash.h"

#import "OFNotImplementedException.h"

@implementation OFHash
+ hash
{
	return [[[self alloc] init] autorelease];
}

+ (size_t)digestSize
{
	@throw [OFNotImplementedException exceptionWithClass: self
						    selector: _cmd];
}

+ (size_t)blockSize
{
	@throw [OFNotImplementedException exceptionWithClass: self
						    selector: _cmd];
}

- (void)updateWithBuffer: (const void*)buffer
		  length: (size_t)length
{
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}

- (uint8_t*)digest

Modified src/OFMD5Hash.h from [95439e160f] to [a6c35b82ad].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	uint32_t buffer[4];
	uint32_t bits[2];
	union {
		uint8_t	u8[64];
		uint32_t u32[16];
	} in;
}

/**
 * \brief Creates a new OFMD5Hash.
 *
 * \return A new autoreleased OFMD5Hash
 */
+ MD5Hash;
@end







<
<
<
<
<
<
<

26
27
28
29
30
31
32







33
	uint32_t buffer[4];
	uint32_t bits[2];
	union {
		uint8_t	u8[64];
		uint32_t u32[16];
	} in;
}







@end

Modified src/OFMD5Hash.m from [919ef58dc0] to [a97a93ff1c].

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	buffer[0] += a;
	buffer[1] += b;
	buffer[2] += c;
	buffer[3] += d;
}

@implementation OFMD5Hash
+ MD5Hash
{
	return [[[self alloc] init] autorelease];
}

+ (size_t)digestSize
{
	return 16;
}

+ (size_t)blockSize
{







<
<
<
<
<







115
116
117
118
119
120
121





122
123
124
125
126
127
128
	buffer[0] += a;
	buffer[1] += b;
	buffer[2] += c;
	buffer[3] += d;
}

@implementation OFMD5Hash





+ (size_t)digestSize
{
	return 16;
}

+ (size_t)blockSize
{
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
	buffer[1] = 0xEFCDAB89;
	buffer[2] = 0x98BADCFE;
	buffer[3] = 0x10325476;

	return self;
}

- (void)updateWithBuffer: (const char*)buffer_
		  length: (size_t)length
{
	uint32_t t;


	if (length == 0)
		return;

	if (calculated)
		@throw [OFHashAlreadyCalculatedException
		    exceptionWithClass: isa







|



>







137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
	buffer[1] = 0xEFCDAB89;
	buffer[2] = 0x98BADCFE;
	buffer[3] = 0x10325476;

	return self;
}

- (void)updateWithBuffer: (const void*)buffer__
		  length: (size_t)length
{
	uint32_t t;
	const char *buffer_ = buffer__;

	if (length == 0)
		return;

	if (calculated)
		@throw [OFHashAlreadyCalculatedException
		    exceptionWithClass: isa

Modified src/OFSHA1Hash.h from [ca899bde17] to [b512b356a3].

24
25
26
27
28
29
30
31
32
33
34
35
36
@interface OFSHA1Hash: OFHash
{
	uint32_t state[5];
	uint64_t count;
	char	 buffer[64];
	uint8_t	 digest[OF_SHA1_DIGEST_SIZE];
}

/**
 * \return A new autoreleased SHA1 Hash
 */
+ SHA1Hash;
@end







<
<
<
<
<

24
25
26
27
28
29
30





31
@interface OFSHA1Hash: OFHash
{
	uint32_t state[5];
	uint64_t count;
	char	 buffer[64];
	uint8_t	 digest[OF_SHA1_DIGEST_SIZE];
}





@end

Modified src/OFSHA1Hash.m from [533a6ceae9] to [6e4ec96cf9].

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
	} else
		i = 0;

	memcpy(&buffer[j], &buf[i], length - i);
}

@implementation OFSHA1Hash
+ SHA1Hash
{
	return [[[self alloc] init] autorelease];
}

+ (size_t)digestSize
{
	return 20;
}

+ (size_t)blockSize
{







<
<
<
<
<







125
126
127
128
129
130
131





132
133
134
135
136
137
138
	} else
		i = 0;

	memcpy(&buffer[j], &buf[i], length - i);
}

@implementation OFSHA1Hash





+ (size_t)digestSize
{
	return 20;
}

+ (size_t)blockSize
{
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
	state[2] = 0x98BADCFE;
	state[3] = 0x10325476;
	state[4] = 0xC3D2E1F0;

	return self;
}

- (void)updateWithBuffer: (const char*)buffer_
		  length: (size_t)length
{
	if (length == 0)
		return;

	if (calculated)
		@throw [OFHashAlreadyCalculatedException







|







148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
	state[2] = 0x98BADCFE;
	state[3] = 0x10325476;
	state[4] = 0xC3D2E1F0;

	return self;
}

- (void)updateWithBuffer: (const void*)buffer_
		  length: (size_t)length
{
	if (length == 0)
		return;

	if (calculated)
		@throw [OFHashAlreadyCalculatedException

Modified src/OFString+Hashing.m from [07ba26d618] to [e987d561c5].

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

int _OFString_Hashing_reference;

@implementation OFString (Hashing)
- (OFString*)MD5Hash
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *hash = [OFMD5Hash MD5Hash];
	uint8_t *digest;
	char ret[OF_MD5_DIGEST_SIZE * 2];
	size_t i;

	[hash updateWithBuffer: [self UTF8String]
			length: [self UTF8StringLength]];
	digest = [hash digest];







|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

int _OFString_Hashing_reference;

@implementation OFString (Hashing)
- (OFString*)MD5Hash
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *hash = [OFMD5Hash hash];
	uint8_t *digest;
	char ret[OF_MD5_DIGEST_SIZE * 2];
	size_t i;

	[hash updateWithBuffer: [self UTF8String]
			length: [self UTF8StringLength]];
	digest = [hash digest];
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
				  encoding: OF_STRING_ENCODING_ASCII
				    length: 32];
}

- (OFString*)SHA1Hash
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *hash = [OFSHA1Hash SHA1Hash];
	uint8_t *digest;
	char ret[OF_SHA1_DIGEST_SIZE * 2];
	size_t i;

	[hash updateWithBuffer: [self UTF8String]
			length: [self UTF8StringLength]];
	digest = [hash digest];







|







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
				  encoding: OF_STRING_ENCODING_ASCII
				    length: 32];
}

- (OFString*)SHA1Hash
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *hash = [OFSHA1Hash hash];
	uint8_t *digest;
	char ret[OF_SHA1_DIGEST_SIZE * 2];
	size_t i;

	[hash updateWithBuffer: [self UTF8String]
			length: [self UTF8StringLength]];
	digest = [hash digest];

Modified tests/OFMD5HashTests.m from [3d9bebb920] to [e7dab670c1].

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
- (void)MD5HashTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *md5;
	OFFile *f = [OFFile fileWithPath: @"testfile.bin"
				    mode: @"rb"];

	TEST(@"+[MD5Hash]", (md5 = [OFMD5Hash MD5Hash]))

	while (![f isAtEndOfStream]) {
		char buf[64];
		size_t len = [f readIntoBuffer: buf
					length: 64];
		[md5 updateWithBuffer: buf
			       length: len];







|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
- (void)MD5HashTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFMD5Hash *md5;
	OFFile *f = [OFFile fileWithPath: @"testfile.bin"
				    mode: @"rb"];

	TEST(@"+[hash]", (md5 = [OFMD5Hash hash]))

	while (![f isAtEndOfStream]) {
		char buf[64];
		size_t len = [f readIntoBuffer: buf
					length: 64];
		[md5 updateWithBuffer: buf
			       length: len];

Modified tests/OFSHA1HashTests.m from [1cad042110] to [fea32d80e8].

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
- (void)SHA1HashTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFSHA1Hash *sha1;
	OFFile *f = [OFFile fileWithPath: @"testfile.bin"
				    mode: @"rb"];

	TEST(@"+[SHA1Hash]", (sha1 = [OFSHA1Hash SHA1Hash]))

	while (![f isAtEndOfStream]) {
		char buf[64];
		size_t len = [f readIntoBuffer: buf
					length: 64];
		[sha1 updateWithBuffer: buf
				length: len];







|







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
- (void)SHA1HashTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFSHA1Hash *sha1;
	OFFile *f = [OFFile fileWithPath: @"testfile.bin"
				    mode: @"rb"];

	TEST(@"+[hash]", (sha1 = [OFSHA1Hash hash]))

	while (![f isAtEndOfStream]) {
		char buf[64];
		size_t len = [f readIntoBuffer: buf
					length: 64];
		[sha1 updateWithBuffer: buf
				length: len];