ObjFW  Diff

Differences From Artifact [25a2a29ceb]:

To Artifact [51628de7e9]:


47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
47
48
49
50
51
52
53

54

55
56
57
58
59
60
61







-
+
-







    "\x61\xB3\xF9\x1A\xE3\x09\x43\xA6\x5B\x85\xB1\x50\x5B\xCB\x1A\x2E"
    "\xB7\xE8\x87\xC1\x73\x19\x63\xF6\xA2\x91\x8D\x7E\x2E\xCC\xEC\x99";

@implementation TestsAppDelegate (OFHMACTests)
- (void)HMACTests
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *f = [OFFile fileWithPath: @"testfile.bin"
	OFFile *f = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
				    mode: @"r"];
	OFHMAC *HMAC_MD5, *HMAC_SHA1, *HMAC_RMD160;
	OFHMAC *HMAC_SHA256, *HMAC_SHA384, *HMAC_SHA512;

	TEST(@"+[HMACWithHashClass:] with MD5",
	    (HMAC_MD5 = [OFHMAC HMACWithHashClass: [OFMD5Hash class]
			    allowsSwappableMemory: true]))
	TEST(@"+[HMACWithHashClass:] with SHA-1",
76
77
78
79
80
81
82
83

84
85
86

87
88
89

90
91
92

93
94
95

96
97
98

99
100
101
102
103

104
105

106
107

108
109

110
111

112
113

114
115

116
117
118
119
120
121
122
123
75
76
77
78
79
80
81

82

83

84

85

86

87

88

89

90

91

92

93
94
95

96


97


98


99


100


101


102

103
104
105
106
107
108
109







-
+
-

-
+
-

-
+
-

-
+
-

-
+
-

-
+
-



-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-







			       allowsSwappableMemory: true]))

	EXPECT_EXCEPTION(@"Detection of missing key",
	    OFInvalidArgumentException, [HMAC_MD5 updateWithBuffer: ""
							    length: 0])

	TEST(@"-[setKey:length:] with MD5",
	    R([HMAC_MD5 setKey: key
	    R([HMAC_MD5 setKey: key length: key_length]))
			length: key_length]))
	TEST(@"-[setKey:length:] with SHA-1",
	    R([HMAC_SHA1 setKey: key
	    R([HMAC_SHA1 setKey: key length: key_length]))
			 length: key_length]))
	TEST(@"-[setKey:length:] with RIPEMD-160",
	    R([HMAC_RMD160 setKey: key
	    R([HMAC_RMD160 setKey: key length: key_length]))
			   length: key_length]))
	TEST(@"-[setKey:length:] with SHA-256",
	    R([HMAC_SHA256 setKey: key
	    R([HMAC_SHA256 setKey: key length: key_length]))
			   length: key_length]))
	TEST(@"-[setKey:length:] with SHA-384",
	    R([HMAC_SHA384 setKey: key
	    R([HMAC_SHA384 setKey: key length: key_length]))
			   length: key_length]))
	TEST(@"-[setKey:length:] with SHA-512",
	    R([HMAC_SHA512 setKey: key
	    R([HMAC_SHA512 setKey: key length: key_length]))
			   length: key_length]))

	while (!f.atEndOfStream) {
		char buf[64];
		size_t len = [f readIntoBuffer: buf
		size_t len = [f readIntoBuffer: buf length: 64];
					length: 64];
		[HMAC_MD5 updateWithBuffer: buf
		[HMAC_MD5 updateWithBuffer: buf length: len];
				    length: len];
		[HMAC_SHA1 updateWithBuffer: buf
		[HMAC_SHA1 updateWithBuffer: buf length: len];
				     length: len];
		[HMAC_RMD160 updateWithBuffer: buf
		[HMAC_RMD160 updateWithBuffer: buf length: len];
				       length: len];
		[HMAC_SHA256 updateWithBuffer: buf
		[HMAC_SHA256 updateWithBuffer: buf length: len];
				       length: len];
		[HMAC_SHA384 updateWithBuffer: buf
		[HMAC_SHA384 updateWithBuffer: buf length: len];
				       length: len];
		[HMAC_SHA512 updateWithBuffer: buf
		[HMAC_SHA512 updateWithBuffer: buf length: len];
				       length: len];
	}
	[f close];

	TEST(@"-[digest] with MD5",
	    memcmp(HMAC_MD5.digest, digest_md5, HMAC_MD5.digestSize) == 0)
	TEST(@"-[digest] with SHA-1",
	    memcmp(HMAC_SHA1.digest, digest_sha1, HMAC_SHA1.digestSize) == 0)